From 1cf05c23563fa06ec3b88c5943ea7e2186d8ffb1 Mon Sep 17 00:00:00 2001 From: Erik van Velzen Date: Tue, 2 Jul 2024 08:49:19 +0200 Subject: [PATCH 1/4] Remove Nginx --- docker/Dockerfile | 8 --- docker/files/certs/.gitkeep | 0 docker/files/config/nginx.conf | 43 ------------- docker/files/config/nginx.conf.template | 76 ----------------------- docker/files/config/nginx.pizza.conf | 81 ------------------------- docker/files/db-dumps/.gitkeep | 0 docker/files/shared/.gitkeep | 0 docker/files/static/502.html | 16 ----- docker/files/var/log/app/.gitkeep | 0 docker/files/var/log/nginx/.gitkeep | 0 10 files changed, 224 deletions(-) delete mode 100644 docker/Dockerfile delete mode 100644 docker/files/certs/.gitkeep delete mode 100644 docker/files/config/nginx.conf delete mode 100644 docker/files/config/nginx.conf.template delete mode 100644 docker/files/config/nginx.pizza.conf delete mode 100644 docker/files/db-dumps/.gitkeep delete mode 100644 docker/files/shared/.gitkeep delete mode 100644 docker/files/static/502.html delete mode 100644 docker/files/var/log/app/.gitkeep delete mode 100644 docker/files/var/log/nginx/.gitkeep diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 93daae126..000000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM nginx:1.25.0-alpine3.17 - -COPY ./files/config/nginx.conf.template /etc/nginx/templates/default.conf.template -COPY ./files/config/nginx.conf /etc/nginx/nginx.conf - -WORKDIR /app - -COPY ./files/static/502.html 502.html diff --git a/docker/files/certs/.gitkeep b/docker/files/certs/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/docker/files/config/nginx.conf b/docker/files/config/nginx.conf deleted file mode 100644 index 1ed05d8a0..000000000 --- a/docker/files/config/nginx.conf +++ /dev/null @@ -1,43 +0,0 @@ - -user nginx; -worker_processes auto; - -error_log /var/log/nginx/error.log notice; -pid /var/run/nginx.pid; - - -events { - worker_connections 1024; -} - - -http { - include /etc/nginx/mime.types; - default_type application/octet-stream; - - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; - - access_log /var/log/nginx/access.log main; - - sendfile on; - #tcp_nopush on; - - keepalive_timeout 65; - - #gzip on; - - include /etc/nginx/conf.d/*.conf; -} - - -stream { - upstream ssh { - server python:22; - } - server { - listen 2222; - proxy_pass ssh; - } -} \ No newline at end of file diff --git a/docker/files/config/nginx.conf.template b/docker/files/config/nginx.conf.template deleted file mode 100644 index 5c8fc9c42..000000000 --- a/docker/files/config/nginx.conf.template +++ /dev/null @@ -1,76 +0,0 @@ -server { - listen 80 default_server; - listen [::]:80 default_server; - proxy_connect_timeout 600s; # time to open a connection to the proxy before we give up - proxy_send_timeout 600s; # timeout for transmitting a request to the proxied server - proxy_read_timeout 600s; # timeout for reading a response from the proxied server - did it send back anything before this has expired - send_timeout 600s; # timeout for sending a response to the requesting client - note this isn't proxy_send_timeout, but the time between two successive write operations to the requesting client (ie. browser) - reset_timedout_connection on; - - server_name ${SERVER_NAME} _; - - client_max_body_size 128M; - client_body_buffer_size 16M; - - proxy_buffer_size 16M; - proxy_busy_buffers_size 16M; - proxy_buffers 16 16M; - - gzip on; - gzip_proxied any; - gzip_types text/plain text/xml text/css application/x-javascript; - gzip_vary on; - gzip_disable “MSIE [1-6]\.(?!.*SV1)”; - - sendfile on; - sendfile_max_chunk 512k; - - root /app/src; - - access_log off; - - error_page 502 /502.html; - location /502.html { - root /app; - } - - location /wt/media { - alias /app/media; - } - - location /wt/static/ { - expires 30d; - autoindex off; - alias /app/static/; - } - - location / { - proxy_set_header Host $host:8000; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_pass ${NEXT_HOST}:3000; - } - - location /_next/webpack-hmr { - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_pass ${NEXT_HOST}:3000/_next/webpack-hmr; - } - - location /_util { - proxy_set_header Host $host:8000; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_pass ${PYTHON_HOST}:8000/wt; - } - - location /wt { - proxy_set_header Host $host:8000; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_http_version 1.1; - proxy_set_header Connection ""; - proxy_pass ${PYTHON_HOST}:8000/wt; - } -} diff --git a/docker/files/config/nginx.pizza.conf b/docker/files/config/nginx.pizza.conf deleted file mode 100644 index 22f756d0c..000000000 --- a/docker/files/config/nginx.pizza.conf +++ /dev/null @@ -1,81 +0,0 @@ -server { - listen 80 default_server; - listen [::]:80 default_server; - - ## SSL part - listen 443 ssl; - ssl_certificate /etc/nginx/certs/fullchain.pem; - ssl_certificate_key /etc/nginx/certs/privkey.pem; - - - proxy_connect_timeout 120s; # time to open a connection to the proxy before we give up - proxy_send_timeout 120s; # timeout for transmitting a request to the proxied server - proxy_read_timeout 600s; # timeout for reading a response from the proxied server - did it send back anything before this has expired - send_timeout 120s; # timeout for sending a response to the requesting client - note this isn't proxy_send_timeout, but the time between two successive write operations to the requesting client (ie. browser) - reset_timedout_connection on; - - proxy_buffer_size 16M; - proxy_busy_buffers_size 16M; - proxy_buffers 16 16M; - - - server_name ${SERVER_NAME} _; - - client_max_body_size 128M; - - gzip on; - gzip_proxied any; - gzip_types text/plain text/xml text/css application/x-javascript; - gzip_vary on; - gzip_disable “MSIE [1-6]\.(?!.*SV1)”; - - sendfile on; - sendfile_max_chunk 512k; - - root /app/src; - - access_log off; - - error_page 502 /502.html; - location /502.html { - root /app; - } - - location /wt/media { - alias /app/media; - } - - location /wt/static/ { - expires 30d; - autoindex off; - alias /app/static/; - } - - location / { - proxy_set_header Host $host:8000; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_pass ${NEXT_HOST}:3000; - } - - location /_next/webpack-hmr { - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_pass ${NEXT_HOST}:3000/_next/webpack-hmr; - } - - location /_util { - proxy_set_header Host $host:8000; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_pass ${PYTHON_HOST}:8000/wt; - } - - location /wt { - proxy_set_header Host $host:8000; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_pass ${PYTHON_HOST}:8000/wt; - } -} diff --git a/docker/files/db-dumps/.gitkeep b/docker/files/db-dumps/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/docker/files/shared/.gitkeep b/docker/files/shared/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/docker/files/static/502.html b/docker/files/static/502.html deleted file mode 100644 index daa9e232a..000000000 --- a/docker/files/static/502.html +++ /dev/null @@ -1,16 +0,0 @@ - - - 502 Bad Gateway - - - - -
-
-

502 Bad Gateway

-

Have you started the Next.js server with npm run dev (for dev) or npm run start (for production)?

-
-
diff --git a/docker/files/var/log/app/.gitkeep b/docker/files/var/log/app/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/docker/files/var/log/nginx/.gitkeep b/docker/files/var/log/nginx/.gitkeep deleted file mode 100644 index e69de29bb..000000000 From fad44a73971c959e4cd83406bdfa68374ce19627 Mon Sep 17 00:00:00 2001 From: Erik van Velzen Date: Mon, 15 Jul 2024 15:55:47 +0200 Subject: [PATCH 2/4] Docker swarm Deploy test environment to docker swarm. --- .editorconfig | 2 +- .github/workflows/build-push-deploy.yml | 44 ++++++++++++++++-- .github/workflows/get-variables.js | 15 ++++++ docker/compose-prod.yaml | 61 +++++++++++++++++++++++++ docker/config/python.example.env | 1 + src/requirements/local.txt | 2 +- 6 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 docker/compose-prod.yaml diff --git a/.editorconfig b/.editorconfig index 11b226077..5c17cd8d7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,7 +14,7 @@ indent_size = 4 [*.{yml,yaml}] indent_style = space -indent_size = 2 +indent_size = 4 [*.md] trim_trailing_whitespace = false diff --git a/.github/workflows/build-push-deploy.yml b/.github/workflows/build-push-deploy.yml index 05cf9d853..f60c2039c 100644 --- a/.github/workflows/build-push-deploy.yml +++ b/.github/workflows/build-push-deploy.yml @@ -6,6 +6,7 @@ on: - main - production - acceptance + - swarm workflow_dispatch: permissions: @@ -74,7 +75,7 @@ jobs: --push ## This job takes pretty long and can be split up to parallelize the deploy. - deploy-wagtail: + deploy-wagtail-azure: needs: - build-and-push-images - variables @@ -141,8 +142,7 @@ jobs: --name wagtail-${{ github.ref_name }} --hostname ${{ fromJson(needs.variables.outputs.result).WAGTAIL_HOSTNAME }} - - deploy-next: + deploy-next-azure: needs: - build-and-push-images - variables @@ -195,3 +195,41 @@ jobs: --environment holon-env --name next-${{ github.ref_name }} --hostname www.holontool.nl + + deploy-swarm: + runs-on: ubuntu-latest + environment: ${{ fromJson(needs.variables.outputs.result).GITHUB_ENVIRONMENT }} + needs: + - build-and-push-images + - variables + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + sparse-checkout: docker + - name: Deploy to Docker Swarm + uses: sagebind/docker-swarm-deploy-action@v2 + env: + # Shared + TAG: ${{ needs.variables.outputs.tag }} + WAGTAIL_HOSTNAME: ${{ fromJson(needs.variables.outputs.result).WAGTAIL_HOSTNAME }} + # Wagtail + AZURE_STORAGE_KEY: ${{ secrets.AZURE_STORAGE_KEY }} + MEDIA_LOCATION: ${{ fromJson(needs.variables.outputs.result).MEDIA_LOCATION }} + STATIC_LOCATION: ${{ fromJson(needs.variables.outputs.result).STATIC_LOCATION }} + DB_USER: ${{ fromJson(needs.variables.outputs.result).DB_USER }} + DB_NAME: ${{ fromJson(needs.variables.outputs.result).DB_NAME }} + DB_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} + RETURN_SCENARIO: ${{ fromJson(needs.variables.outputs.result).RETURN_SCENARIO }} + SECRET_KEY: "${{ secrets.SECRET_KEY }}" + SENTRY_ENVIRONMENT: ${{ fromJson(needs.variables.outputs.result).SENTRY_ENVIRONMENT }} + DOMAIN_HOST: ${{ fromJson(needs.variables.outputs.result).DOMAIN_HOST }} + EMAIL_HOST_PASSWORD: ${{ secrets.EMAIL_HOST_PASSWORD }} + # NextJS + NEXT_HOSTNAME: ${{ fromJson(needs.variables.outputs.result).NEXT_HOSTNAME }} + NEXT_PUBLIC_TINY_URL_API_KEY: ${{ secrets.TINY_URL_API_KEY }} + with: + remote_host: ssh://root@server.zenmo.com + ssh_private_key: ${{ secrets.SWARM_SSH_PRIVATE_KEY }} + ssh_public_key: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJ1E4LUG22qgzc8U7oNYGWCn0cyA31+iyX2pck9wcPMS + args: stack deploy --compose-file ./docker/compose-prod.yaml holon-${{ fromJson(needs.variables.outputs.result).GITHUB_ENVIRONMENT }} diff --git a/.github/workflows/get-variables.js b/.github/workflows/get-variables.js index 7e44858ee..5bbdf7d53 100644 --- a/.github/workflows/get-variables.js +++ b/.github/workflows/get-variables.js @@ -1,6 +1,7 @@ const configPerBranch = { main: { + GITHUB_ENVIRONMENT: 'test', DB_NAME: 'holon-wagtail-v2-test', DB_USER: 'holon_wagtail_test', DB_PASSWORD_KEY: 'DB_PASSWORD_TEST', @@ -18,6 +19,7 @@ const configPerBranch = { } }, acceptance: { + GITHUB_ENVIRONMENT: 'acceptance', DB_NAME: 'holon-wagtail-v2-acceptatie', DB_USER: 'holon_wagtail_acceptance', DB_PASSWORD_KEY: 'DB_PASSWORD_ACCEPTANCE', @@ -35,6 +37,7 @@ const configPerBranch = { } }, production: { + GITHUB_ENVIRONMENT: 'production', DB_NAME: 'holon-wagtail-v2', DB_USER: 'holon_wagtail_prod', DB_PASSWORD_KEY: 'DB_PASSWORD_PROD', @@ -52,6 +55,18 @@ const configPerBranch = { N_WORKERS: '4', } }, + swarm: { + GITHUB_ENVIRONMENT: 'swarm_test', + DB_NAME: 'holon-test', + DB_USER: 'holon-test', + RETURN_SCENARIO: 'True', + SENTRY_ENVIRONMENT: 'swarm-test', + NEXT_HOSTNAME: 'swarm.holontool.nl', + DOMAIN_HOST: 'https://swarm.holontool.nl', + WAGTAIL_HOSTNAME: 'cms-swarm.holontool.nl', + MEDIA_LOCATION: 'media-test', + STATIC_LOCATION: 'static-test', + }, } module.exports = (branchName) => { diff --git a/docker/compose-prod.yaml b/docker/compose-prod.yaml new file mode 100644 index 000000000..b5c1dfbb4 --- /dev/null +++ b/docker/compose-prod.yaml @@ -0,0 +1,61 @@ +## Compose file for Docker Swarm environments +version: "3.8" + +services: + wagtail: + image: ghcr.io/zenmo/holon-wagtail:${TAG} + environment: + ALLOWED_HOSTS: "*" + AZURE_ACCOUNT_NAME: holonstorage + AZURE_STORAGE_KEY: ${AZURE_STORAGE_KEY} + MEDIA_LOCATION: ${MEDIA_LOCATION} + STATIC_LOCATION: ${STATIC_LOCATION} + DB_HOST: postgres + DB_USER: ${DB_USER} + DB_NAME: ${DB_NAME} + DB_PASSWORD: ${DB_PASSWORD} + RETURN_SCENARIO: ${RETURN_SCENARIO} + SECRET_KEY: ${SECRET_KEY} + SENTRY_DSN: "https://764e9f2b886741bcbcfd2acd74a7f7b0@o4505045746384896.ingest.sentry.io/4505045759361024" + SENTRY_ENVIRONMENT: ${SENTRY_ENVIRONMENT} + DOMAIN_HOST: ${DOMAIN_HOST} + N_WORKERS: 8 + EMAIL_HOST_PASSWORD: ${EMAIL_HOST_PASSWORD} + WAGTAILADMIN_BASE_URL: https://${WAGTAIL_HOSTNAME} + labels: + caddy: ${WAGTAIL_HOSTNAME} + caddy.reverse_proxy: "{{upstreams 8000}}" + networks: + - caddy_default + - postgres_default + - default + deploy: + resources: + limits: + cpus: "8" + memory: 8G + + nextjs: + image: ghcr.io/zenmo/holon-nextjs:${TAG} + environment: + WAGTAIL_API_URL: http://wagtail:8000/wt/api/nextjs + NEXT_PUBLIC_WAGTAIL_API_URL: https://${WAGTAIL_HOSTNAME}/wt/api/nextjs + NEXT_PUBLIC_TINY_URL_API_KEY: ${NEXT_PUBLIC_TINY_URL_API_KEY} + labels: + caddy: ${NEXT_HOSTNAME} + caddy.reverse_proxy: "{{upstreams 3000}}" + networks: + - caddy_default + - default + deploy: + resources: + limits: + cpus: "4" + memory: 4G + +networks: + caddy_default: + external: true + postgres_default: + external: true + default: diff --git a/docker/config/python.example.env b/docker/config/python.example.env index c95a7a8b6..c3b3d6dd6 100644 --- a/docker/config/python.example.env +++ b/docker/config/python.example.env @@ -1,3 +1,4 @@ +# For development AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_BUCKET_NAME= diff --git a/src/requirements/local.txt b/src/requirements/local.txt index a2f241264..31456abbc 100644 --- a/src/requirements/local.txt +++ b/src/requirements/local.txt @@ -2,7 +2,7 @@ -r test.txt # Add local extra requirements here (django-debug etc) -pydevd-pycharm~=241.17011.79 +pydevd-pycharm~=242.21829.44 black django-debug-toolbar isort From 72ecf523e13fd7537357023293a7c8443da31562 Mon Sep 17 00:00:00 2001 From: Erik van Velzen Date: Wed, 28 Aug 2024 15:39:54 +0200 Subject: [PATCH 3/4] Remove Azure deploy --- .github/workflows/build-push-deploy.yml | 122 ------------------------ 1 file changed, 122 deletions(-) diff --git a/.github/workflows/build-push-deploy.yml b/.github/workflows/build-push-deploy.yml index f60c2039c..7153e70ad 100644 --- a/.github/workflows/build-push-deploy.yml +++ b/.github/workflows/build-push-deploy.yml @@ -74,128 +74,6 @@ jobs: --tag ghcr.io/zenmo/holon-nextjs:${{ needs.variables.outputs.tag }} --push - ## This job takes pretty long and can be split up to parallelize the deploy. - deploy-wagtail-azure: - needs: - - build-and-push-images - - variables - runs-on: ubuntu-latest - steps: - - name: Log in to Azure - uses: azure/login@v1 - with: - ## https://github.com/Azure/login#configure-a-service-principal-with-a-secret - creds: ${{ secrets.AZURE_CREDENTIALS }} -# - name: Create app environment -# uses: azure/CLI@v1 -# with: -# azcliversion: 2.51.0 -# inlineScript: > -# az containerapp env create -# --name holon-env -# --location westeurope -# --resource-group HOLON-webapp - - name: Deploy-Wagtail - uses: azure/CLI@v1 - with: - ## Use generic azure/CLI@v1 instead of specific azure/container-apps-deploy-action@v1 - ## because it supports the options that we want. - azcliversion: 2.51.0 - inlineScript: > - az containerapp create - --resource-group HOLON-webapp - --environment holon-env - --name wagtail-${{ github.ref_name }} - --env-vars - ALLOWED_HOSTS="*" - AZURE_ACCOUNT_NAME=holonstorage - AZURE_STORAGE_KEY=${{ secrets.AZURE_STORAGE_KEY }} - MEDIA_LOCATION=${{ fromJson(needs.variables.outputs.result).MEDIA_LOCATION }} - STATIC_LOCATION=${{ fromJson(needs.variables.outputs.result).STATIC_LOCATION }} - DB_HOST=${{ secrets.DB_HOST }} - DB_USER=${{ fromJson(needs.variables.outputs.result).DB_USER }} - DB_NAME=${{ fromJson(needs.variables.outputs.result).DB_NAME }} - DB_PASSWORD=${{ secrets[fromJson(needs.variables.outputs.result).DB_PASSWORD_KEY] }} - RETURN_SCENARIO=${{ fromJson(needs.variables.outputs.result).RETURN_SCENARIO }} - SECRET_KEY="${{ secrets.SECRET_KEY }}" - SENTRY_DSN=https://764e9f2b886741bcbcfd2acd74a7f7b0@o4505045746384896.ingest.sentry.io/4505045759361024 - SENTRY_ENVIRONMENT=${{ fromJson(needs.variables.outputs.result).SENTRY_ENVIRONMENT }} - DOMAIN_HOST=${{ fromJson(needs.variables.outputs.result).DOMAIN_HOST }} - N_WORKERS=${{ fromJson(needs.variables.outputs.result).wagtail.N_WORKERS }} - EMAIL_HOST_PASSWORD=${{ secrets.EMAIL_HOST_PASSWORD }} - WAGTAILADMIN_BASE_URL=https://${{ fromJson(needs.variables.outputs.result).WAGTAIL_HOSTNAME }} - --target-port 8000 - --ingress external - --image ghcr.io/zenmo/holon-wagtail:${{ needs.variables.outputs.tag }} - --cpu ${{ fromJson(needs.variables.outputs.result).wagtail.CPU }} - --memory ${{ fromJson(needs.variables.outputs.result).wagtail.MEMORY }} - --min-replicas 1 - --max-replicas 2 - - name: Bind-Wagtail - uses: azure/CLI@v1 - with: - azcliversion: 2.51.0 - inlineScript: > - az containerapp hostname bind - --resource-group HOLON-webapp - --environment holon-env - --name wagtail-${{ github.ref_name }} - --hostname ${{ fromJson(needs.variables.outputs.result).WAGTAIL_HOSTNAME }} - - deploy-next-azure: - needs: - - build-and-push-images - - variables - runs-on: ubuntu-latest - steps: - - name: Log in to Azure - uses: azure/login@v1 - with: - ## https://github.com/Azure/login#configure-a-service-principal-with-a-secret - creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Deploy-Next.js - uses: azure/CLI@v1 - with: - azcliversion: 2.51.0 - inlineScript: > - az containerapp create - --resource-group HOLON-webapp - --name next-${{ github.ref_name }} - --environment holon-env - --env-vars - WAGTAIL_API_URL=http://wagtail-${{ github.ref_name }}/wt/api/nextjs - NEXT_PUBLIC_WAGTAIL_API_URL=https://${{ fromJson(needs.variables.outputs.result).WAGTAIL_HOSTNAME }}/wt/api/nextjs - NEXT_PUBLIC_TINY_URL_API_KEY=${{ secrets.TINY_URL_API_KEY }} - --target-port 3000 - --ingress external - --tags branch=${{ github.ref_name }} - --image ghcr.io/zenmo/holon-nextjs:${{ needs.variables.outputs.tag }} - --cpu 0.25 - --memory 0.5 - --min-replicas 1 - --max-replicas 1 - - name: Bind-Next.js - uses: azure/CLI@v1 - with: - azcliversion: 2.51.0 - inlineScript: > - az containerapp hostname bind - --resource-group HOLON-webapp - --environment holon-env - --name next-${{ github.ref_name }} - --hostname ${{ fromJson(needs.variables.outputs.result).NEXT_HOSTNAME }} - - name: Bind-www - if: github.ref_name == 'production' - uses: azure/CLI@v1 - with: - azcliversion: 2.51.0 - inlineScript: > - az containerapp hostname bind - --resource-group HOLON-webapp - --environment holon-env - --name next-${{ github.ref_name }} - --hostname www.holontool.nl - deploy-swarm: runs-on: ubuntu-latest environment: ${{ fromJson(needs.variables.outputs.result).GITHUB_ENVIRONMENT }} From 91ea105ac8a7e1512a2cf67d217ba6b25e1ab271 Mon Sep 17 00:00:00 2001 From: Erik van Velzen Date: Wed, 28 Aug 2024 15:53:24 +0200 Subject: [PATCH 4/4] Change config for caddy and database --- .github/workflows/build-push-deploy.yml | 2 +- .github/workflows/get-variables.js | 55 ++++++------------------- docker/compose-prod.yaml | 4 +- 3 files changed, 15 insertions(+), 46 deletions(-) diff --git a/.github/workflows/build-push-deploy.yml b/.github/workflows/build-push-deploy.yml index 7153e70ad..4969ccaab 100644 --- a/.github/workflows/build-push-deploy.yml +++ b/.github/workflows/build-push-deploy.yml @@ -6,7 +6,6 @@ on: - main - production - acceptance - - swarm workflow_dispatch: permissions: @@ -105,6 +104,7 @@ jobs: EMAIL_HOST_PASSWORD: ${{ secrets.EMAIL_HOST_PASSWORD }} # NextJS NEXT_HOSTNAME: ${{ fromJson(needs.variables.outputs.result).NEXT_HOSTNAME }} + NEXT_CADDY_HOSTS: ${{ fromJson(needs.variables.outputs.result).NEXT_CADDY_HOSTS }} NEXT_PUBLIC_TINY_URL_API_KEY: ${{ secrets.TINY_URL_API_KEY }} with: remote_host: ssh://root@server.zenmo.com diff --git a/.github/workflows/get-variables.js b/.github/workflows/get-variables.js index 5bbdf7d53..4bfd82d92 100644 --- a/.github/workflows/get-variables.js +++ b/.github/workflows/get-variables.js @@ -2,70 +2,39 @@ const configPerBranch = { main: { GITHUB_ENVIRONMENT: 'test', - DB_NAME: 'holon-wagtail-v2-test', - DB_USER: 'holon_wagtail_test', - DB_PASSWORD_KEY: 'DB_PASSWORD_TEST', + DB_NAME: 'holon-test', + DB_USER: 'holon-test', RETURN_SCENARIO: 'True', - SENTRY_ENVIRONMENT: 'azure-test', + SENTRY_ENVIRONMENT: 'swarm-test', NEXT_HOSTNAME: 'test.holontool.nl', - DOMAIN_HOST: 'https://test.holontool.nl', + NEXT_CADDY_HOSTS: 'test.holontool.nl', WAGTAIL_HOSTNAME: 'cms-test.holontool.nl', MEDIA_LOCATION: 'media-test', STATIC_LOCATION: 'static-test', - wagtail: { - CPU: '0.25', - MEMORY: '0.5', - N_WORKERS: '2', - } }, acceptance: { GITHUB_ENVIRONMENT: 'acceptance', - DB_NAME: 'holon-wagtail-v2-acceptatie', - DB_USER: 'holon_wagtail_acceptance', - DB_PASSWORD_KEY: 'DB_PASSWORD_ACCEPTANCE', + DB_NAME: 'holon-acceptance', + DB_USER: 'holon-acceptance', RETURN_SCENARIO: 'True', - SENTRY_ENVIRONMENT: 'azure-acceptance', + SENTRY_ENVIRONMENT: 'swarm-acceptance', NEXT_HOSTNAME: 'acceptatie.holontool.nl', - DOMAIN_HOST: 'https://acceptatie.holontool.nl', + NEXT_CADDY_HOSTS: 'acceptatie.holontool.nl', WAGTAIL_HOSTNAME: 'cms-acceptatie.holontool.nl', MEDIA_LOCATION: 'media-acceptatie', STATIC_LOCATION: 'static-acceptatie', - wagtail: { - CPU: '0.5', - MEMORY: '1', - N_WORKERS: '4', - } }, production: { GITHUB_ENVIRONMENT: 'production', - DB_NAME: 'holon-wagtail-v2', - DB_USER: 'holon_wagtail_prod', - DB_PASSWORD_KEY: 'DB_PASSWORD_PROD', + DB_NAME: 'holon-production', + DB_USER: 'holon-production', RETURN_SCENARIO: 'False', - SENTRY_ENVIRONMENT: 'azure-production', + SENTRY_ENVIRONMENT: 'swarm-production', NEXT_HOSTNAME: 'holontool.nl', - DOMAIN_HOST: 'https://holontool.nl', + NEXT_CADDY_HOSTS: 'holontool.nl, www.holontool.nl', WAGTAIL_HOSTNAME: 'cms.holontool.nl', MEDIA_LOCATION: 'media', STATIC_LOCATION: 'static', - // It seems we only need to scale Wagtail but not Next.js - wagtail: { - CPU: '0.5', - MEMORY: '1', - N_WORKERS: '4', - } - }, - swarm: { - GITHUB_ENVIRONMENT: 'swarm_test', - DB_NAME: 'holon-test', - DB_USER: 'holon-test', - RETURN_SCENARIO: 'True', - SENTRY_ENVIRONMENT: 'swarm-test', - NEXT_HOSTNAME: 'swarm.holontool.nl', - DOMAIN_HOST: 'https://swarm.holontool.nl', - WAGTAIL_HOSTNAME: 'cms-swarm.holontool.nl', - MEDIA_LOCATION: 'media-test', - STATIC_LOCATION: 'static-test', }, } diff --git a/docker/compose-prod.yaml b/docker/compose-prod.yaml index b5c1dfbb4..98dd04262 100644 --- a/docker/compose-prod.yaml +++ b/docker/compose-prod.yaml @@ -18,7 +18,7 @@ services: SECRET_KEY: ${SECRET_KEY} SENTRY_DSN: "https://764e9f2b886741bcbcfd2acd74a7f7b0@o4505045746384896.ingest.sentry.io/4505045759361024" SENTRY_ENVIRONMENT: ${SENTRY_ENVIRONMENT} - DOMAIN_HOST: ${DOMAIN_HOST} + DOMAIN_HOST: https://${NEXT_HOSTNAME} N_WORKERS: 8 EMAIL_HOST_PASSWORD: ${EMAIL_HOST_PASSWORD} WAGTAILADMIN_BASE_URL: https://${WAGTAIL_HOSTNAME} @@ -42,7 +42,7 @@ services: NEXT_PUBLIC_WAGTAIL_API_URL: https://${WAGTAIL_HOSTNAME}/wt/api/nextjs NEXT_PUBLIC_TINY_URL_API_KEY: ${NEXT_PUBLIC_TINY_URL_API_KEY} labels: - caddy: ${NEXT_HOSTNAME} + caddy: ${NEXT_CADDY_HOSTS} caddy.reverse_proxy: "{{upstreams 3000}}" networks: - caddy_default