From 8d410df572d984e6fae33b5a427365105440fcf8 Mon Sep 17 00:00:00 2001 From: AtomHare Date: Wed, 25 Aug 2021 09:51:41 +0200 Subject: [PATCH] Add Initial docker compose * Initial draft of the docker-compose with configuration files * Update docker-compose.yml update path * Add configure-instance script. * Fix caddyfile and improvements. * Enable quic for Caddy. * Add missing newline. * Remove unnecessary depends_on. Co-authored-by: FireMasterK <20838718+FireMasterK@users.noreply.github.com> --- .gitignore | 2 ++ configure-instance.sh | 16 ++++++++++ docker-compose.yml | 65 ++++++++++++++++++++++++++++++++++++++ template/Caddyfile | 48 ++++++++++++++++++++++++++++ template/config.properties | 25 +++++++++++++++ template/default.vcl | 5 +++ 6 files changed, 161 insertions(+) create mode 100644 .gitignore create mode 100755 configure-instance.sh create mode 100644 docker-compose.yml create mode 100644 template/Caddyfile create mode 100644 template/config.properties create mode 100644 template/default.vcl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2171176 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +config/ +data/ diff --git a/configure-instance.sh b/configure-instance.sh new file mode 100755 index 0000000..76d7899 --- /dev/null +++ b/configure-instance.sh @@ -0,0 +1,16 @@ +echo "Enter a hostname for the Frontend (eg: piped.kavin.rocks):" +read frontend + +echo "Enter a hostname for the Backend (eg: pipedapi.kavin.rocks):" +read backend + +echo "Enter a hostname for the Proxy (eg: pipedproxy.kavin.rocks):" +read proxy + +rm -rf config/ + +cp -r template/ config/ + +sed -i "s/FRONTEND_HOSTNAME/$frontend/g" config/* +sed -i "s/BACKEND_HOSTNAME/$backend/g" config/* +sed -i "s/PROXY_HOSTNAME/$proxy/g" config/* diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7badbfe --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,65 @@ +services: + pipedfrontend: + image: 1337kavin/piped-frontend:latest + restart: unless-stopped + depends_on: + - piped + container_name: piped-frontend + ytproxy: + image: 1337kavin/ytproxy:latest + restart: unless-stopped + volumes: + - ytproxy:/app/socket + container_name: ytproxy + piped: + image: 1337kavin/piped:latest + restart: unless-stopped + volumes: + - ./config/config.properties:/app/config.properties:ro + depends_on: + - postgres + container_name: piped-backend + varnish: + image: varnish:6.6-alpine + restart: unless-stopped + volumes: + - ./config/default.vcl:/etc/varnish/default.vcl:ro + container_name: varnish + depends_on: + - piped + caddy: + image: caddy:2-alpine + restart: unless-stopped + ports: + - "80:80" + - "443:443" + - "443:443/udp" + volumes: + - ./config/Caddyfile:/etc/caddy/Caddyfile:ro + - caddy_data:/data + - ytproxy:/var/run/ytproxy + container_name: caddy + postgres: + image: postgres:13-alpine + restart: unless-stopped + volumes: + - ./data/db:/var/lib/postgresql/data + environment: + - POSTGRES_DB=piped + - POSTGRES_USER=piped + - POSTGRES_PASSWORD=changeme + container_name: postgres + watchtower: + image: containrrr/watchtower + restart: always + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - /etc/timezone:/etc/timezone:ro + environment: + - WATCHTOWER_CLEANUP=true + - WATCHTOWER_INCLUDE_RESTARTING=true + container_name: watchtower + command: piped-frontend piped-backend ytproxy varnish caddy postgres watchtower +volumes: + caddy_data: + ytproxy: diff --git a/template/Caddyfile b/template/Caddyfile new file mode 100644 index 0000000..0aabe7c --- /dev/null +++ b/template/Caddyfile @@ -0,0 +1,48 @@ +{ + servers :443 { + protocol { + experimental_http3 + } + } +} + +FRONTEND_HOSTNAME { + reverse_proxy pipedfrontend:80 +} + +BACKEND_HOSTNAME { + reverse_proxy varnish:80 +} + +PROXY_HOSTNAME { + + @ytproxy path /videoplayback* /api/v4/* /api/manifest/* + + @optionscall { + method OPTIONS + } + + header Access-Control-Allow-Origin * + header Access-Control-Allow-Headers * + + route { + + header @ytproxy { + Cache-Control private always + } + + header / { + Cache-Control "public, max-age=604800" + } + + respond @optionscall 200 + + reverse_proxy unix//var/run/ytproxy/http-proxy.sock { + header_up -CF-Connecting-IP + header_up -X-Forwarded-For + header_down -Access-Control-Allow-Origin + header_down -etag + header_down -alt-svc + } + } +} diff --git a/template/config.properties b/template/config.properties new file mode 100644 index 0000000..2020201 --- /dev/null +++ b/template/config.properties @@ -0,0 +1,25 @@ +# The port to Listen on. +PORT: 8080 + +# The number of workers to use for the server +HTTP_WORKERS: 2 + +# Proxy +PROXY_PART: https://PROXY_HOSTNAME + +# Outgoing HTTP Proxy - eg: 127.0.0.1:8118 +#HTTP_PROXY: 127.0.0.1:8118 + +# Captcha Parameters +CAPTCHA_BASE_URL: https://api.capmonster.cloud/ +CAPTCHA_API_KEY: INSERT_HERE + +# Public API URL +API_URL: https://BACKEND_HOSTNAME + +# Hibernate properties +hibernate.connection.url: jdbc:postgresql://postgres:5432/piped +hibernate.connection.driver_class: org.postgresql.Driver +hibernate.dialect: org.hibernate.dialect.PostgreSQL10Dialect +hibernate.connection.username: piped +hibernate.connection.password: changeme diff --git a/template/default.vcl b/template/default.vcl new file mode 100644 index 0000000..2cb3b70 --- /dev/null +++ b/template/default.vcl @@ -0,0 +1,5 @@ +vcl 4.0; + +backend default { + .host = "piped:8080"; +}