From bb38b8d9d72950b46d04cb54971c6f632851a053 Mon Sep 17 00:00:00 2001 From: 3nprob <3nprob@3nprob> Date: Sun, 4 Apr 2021 23:38:16 +0900 Subject: [PATCH 1/3] Add nginx Dockerfile --- docker-compose.yml | 14 ++++++++++++++ nginx.Dockerfile | 12 ++++++++++++ nginx.conf.tmpl | 30 ++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 nginx.Dockerfile create mode 100644 nginx.conf.tmpl diff --git a/docker-compose.yml b/docker-compose.yml index bfe2a14..dc0982d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,6 +12,20 @@ services: - mysql:/var/lib/mysql healthcheck: test: ["CMD", "mysqladmin", "ping", "--silent"] + nginx: + build: + context: . + dockerfile: nginx.Dockerfile + restart: unless-stopped + environment: + HOSTNAME: 'changeme.example.com' + HTTP_PORT: 8080 + YOTTER_ADDRESS: 'http://yotter:5000' + YTPROXY_ADDRESS: 'http://unix:/var/run/ytproxy/http-proxy.sock' + ports: + - "127.0.0.1:8080:8080" + volumes: + - "/var/run/ytproxy:/app/socket/" ytproxy: image: 1337kavin/ytproxy:latest restart: unless-stopped diff --git a/nginx.Dockerfile b/nginx.Dockerfile new file mode 100644 index 0000000..9d476ca --- /dev/null +++ b/nginx.Dockerfile @@ -0,0 +1,12 @@ +FROM nginx:mainline-alpine + +WORKDIR /var/www +COPY ./app/static ./static +COPY ./nginx.conf.tmpl /nginx.conf.tmpl + +ENV HOSTNAME= \ + HTTP_PORT=80 \ + YOTTER_ADDRESS=http://127.0.0.1:5000 \ + YTPROXY_ADDRESS=http://unix:/var/run/ytproxy/http-proxy.sock + +CMD ["/bin/sh", "-c", "envsubst '${HOSTNAME} ${HTTP_PORT} ${YOTTER_ADDRESS} ${YTPROXY_ADDRESS}' < /nginx.conf.tmpl > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"] diff --git a/nginx.conf.tmpl b/nginx.conf.tmpl new file mode 100644 index 0000000..a509920 --- /dev/null +++ b/nginx.conf.tmpl @@ -0,0 +1,30 @@ +server { + listen ${HTTP_PORT}; + server_name ${HOSTNAME}; + access_log off; + + location / { + proxy_pass ${YOTTER_ADDRESS}; + proxy_set_header Host $host; + proxy_http_version 1.1; + proxy_set_header Connection ""; + } + + location /static/ { + root /var/www; + sendfile on; + aio threads=default; + } + + location ~ (^/videoplayback$|/videoplayback/|/vi/|/a/|/ytc|/vi_webp/|/sb/) { + proxy_pass ${YTPROXY_ADDRESS}; + add_header Access-Control-Allow-Origin *; + sendfile on; + tcp_nopush on; + aio_write on; + aio threads=default; + directio 512; + proxy_http_version 1.1; + proxy_set_header Connection ""; + } +} From f0a5d2f16700f61278d9c657afdb7f1207e3c333 Mon Sep 17 00:00:00 2001 From: 3nprob <3nprob@3nprob> Date: Sun, 4 Apr 2021 23:38:32 +0900 Subject: [PATCH 2/3] Exclude static assets from yotter backend docker image --- .dockerignore | 1 + nginx.Dockerfile.dockerignore | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 nginx.Dockerfile.dockerignore diff --git a/.dockerignore b/.dockerignore index 5ce824d..59f19fd 100644 --- a/.dockerignore +++ b/.dockerignore @@ -8,3 +8,4 @@ docker-compose.yml LICENSE *.md dockerhash.txt +app/static diff --git a/nginx.Dockerfile.dockerignore b/nginx.Dockerfile.dockerignore new file mode 100644 index 0000000..5ce824d --- /dev/null +++ b/nginx.Dockerfile.dockerignore @@ -0,0 +1,10 @@ +.circleci +.git +.github +.gitignore +cache +Dockerfile +docker-compose.yml +LICENSE +*.md +dockerhash.txt From 789d5d16f73e7d7cc1a2c82ddfe9696bdcea1618 Mon Sep 17 00:00:00 2001 From: 3nprob <3nprob@3nprob> Date: Mon, 12 Apr 2021 09:20:45 +0900 Subject: [PATCH 3/3] Add GH action for nginx docker image --- .github/workflows/docker-build.yml | 43 +++++++++++++++++++++++++++++- docker-compose.yml | 4 +-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 6d4fbcc..21fac93 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -1,4 +1,4 @@ -name: Docker Multi-Architecture Build +nme: Docker Multi-Architecture Build on: push: @@ -90,3 +90,44 @@ jobs: tags: ytorg/yotter:pypy cache-from: type=local,src=cache cache-to: type=local,dest=cache + nginx-build-docker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + with: + platforms: all + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + with: + version: latest + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Get hash of latest image + run: docker pull nginx:mainline-alpine && docker inspect --format='{{index .RepoDigests 0}}' nginx:mainline-alpine > dockerhash.txt + - name: Write the current version to a file + run: "{ git describe --tags --abbrev=0 & date +\"%d-%m-%y\" & git rev-list HEAD --max-count=1 --abbrev-commit;} > version.txt" + - name: cache docker cache + uses: actions/cache@v2.1.4 + with: + path: ${{ github.workspace }}/cache + key: ${{ runner.os }}-docker-nginx-${{ hashFiles('**/dockerhash.txt') }} + restore-keys: | + ${{ runner.os }}-docker-nginx- + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: ytorg/nginx:latest + cache-from: type=local,src=cache + cache-to: type=local,dest=cache diff --git a/docker-compose.yml b/docker-compose.yml index dc0982d..4de24e9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,9 +13,7 @@ services: healthcheck: test: ["CMD", "mysqladmin", "ping", "--silent"] nginx: - build: - context: . - dockerfile: nginx.Dockerfile + image: ytorg/nginx:latest restart: unless-stopped environment: HOSTNAME: 'changeme.example.com'