From 9ecf480956249712ba6ad8a8338b0300105cf5a7 Mon Sep 17 00:00:00 2001 From: asavienko Date: Mon, 30 Oct 2023 21:57:28 -0700 Subject: [PATCH 01/12] update path --- .github/workflows/build-deploy-by-pull-request.yml | 12 ++++++------ .github/workflows/build-deploy-by-push-action.yml | 12 ++++++------ .github/workflows/close-pull-request.yml | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-deploy-by-pull-request.yml b/.github/workflows/build-deploy-by-pull-request.yml index 57c34292..1d9f0e63 100644 --- a/.github/workflows/build-deploy-by-pull-request.yml +++ b/.github/workflows/build-deploy-by-pull-request.yml @@ -95,8 +95,8 @@ jobs: script: | source "/home/ubuntu/.acme.sh/acme.sh.env" PULL_REQUEST_NAME=$(printf "pr-%s" ${{ github.event.number }}) - mkdir -p /opt/deployments/simbolik-$PULL_REQUEST_NAME - cd /opt/deployments/simbolik-$PULL_REQUEST_NAME + mkdir -p ~/opt/deployments/simbolik-$PULL_REQUEST_NAME + cd ~/opt/deployments/simbolik-$PULL_REQUEST_NAME # Frontend docker pull ${{ needs.build.outputs.IMAGE_PREFIX }}/frontend:$PULL_REQUEST_NAME @@ -132,10 +132,10 @@ jobs: ${{ needs.build.outputs.IMAGE_PREFIX }}/backend:$PULL_REQUEST_NAME # Nginx - mkdir -p /opt/deployments/nginx/www - mkdir -p /opt/deployments/nginx/conf.d - mkdir -p /opt/deployments/nginx/ssl/${{ needs.build.outputs.HOST }} - cd /opt/deployments/nginx + mkdir -p ~/opt/deployments/nginx/www + mkdir -p ~/opt/deployments/nginx/conf.d + mkdir -p ~/opt/deployments/nginx/ssl/${{ needs.build.outputs.HOST }} + cd ~/opt/deployments/nginx docker stop nginx-root docker rm nginx-root echo '${{ needs.build.outputs.NGINX_MAIN_CONFIG }}' > ./nginx.conf diff --git a/.github/workflows/build-deploy-by-push-action.yml b/.github/workflows/build-deploy-by-push-action.yml index a1f0fd01..fed727a9 100644 --- a/.github/workflows/build-deploy-by-push-action.yml +++ b/.github/workflows/build-deploy-by-push-action.yml @@ -81,8 +81,8 @@ jobs: port: 22 script: | source "/home/ubuntu/.acme.sh/acme.sh.env" - mkdir -p /opt/deployments/simbolik-${{ github.ref_name }} - cd /opt/deployments/simbolik-${{ github.ref_name }} + mkdir -p ~/opt/deployments/simbolik-${{ github.ref_name }} + cd ~/opt/deployments/simbolik-${{ github.ref_name }} # Frontend docker tag ${{ needs.build.outputs.IMAGE_PREFIX }}/frontend:${{ github.ref_name }} ${{ needs.build.outputs.IMAGE_PREFIX }}/frontend:${{ github.ref_name }}-backup @@ -120,10 +120,10 @@ jobs: ${{ needs.build.outputs.IMAGE_PREFIX }}/backend:${{ github.ref_name }} # Nginx - mkdir -p /opt/deployments/nginx/www - mkdir -p /opt/deployments/nginx/conf.d - mkdir -p /opt/deployments/nginx/ssl/${{ needs.build.outputs.HOST }} - cd /opt/deployments/nginx + mkdir -p ~/opt/deployments/nginx/www + mkdir -p ~/opt/deployments/nginx/conf.d + mkdir -p ~/opt/deployments/nginx/ssl/${{ needs.build.outputs.HOST }} + cd ~/opt/deployments/nginx docker stop nginx-root docker rm nginx-root echo '${{ needs.build.outputs.NGINX_MAIN_CONFIG }}' > ./nginx.conf diff --git a/.github/workflows/close-pull-request.yml b/.github/workflows/close-pull-request.yml index 1dd55237..e3d198b2 100644 --- a/.github/workflows/close-pull-request.yml +++ b/.github/workflows/close-pull-request.yml @@ -42,8 +42,8 @@ jobs: docker rm simbolik-frontend-$PULL_REQUEST_NAME docker stop simbolik-backend-$PULL_REQUEST_NAME docker rm simbolik-backend-$PULL_REQUEST_NAME - rm -rfv /opt/deployments/simbolik-${PULL_REQUEST_NAME} - cd /opt/deployments/nginx + rm -rfv ~/opt/deployments/simbolik-${PULL_REQUEST_NAME} + cd ~/opt/deployments/nginx rm -rfv ./conf.d/${{ steps.process-outputs.outputs.HOST }}.conf rm -rfv ./ssl/${{ steps.process-outputs.outputs.HOST }} rm -rfv ./www/${{ steps.process-outputs.outputs.HOST }} From 6cca44659e37cab1da9c425e8c93bf726f937660 Mon Sep 17 00:00:00 2001 From: asavienko Date: Tue, 31 Oct 2023 11:08:30 -0700 Subject: [PATCH 02/12] update order --- .github/workflows/build-deploy-by-pull-request.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-deploy-by-pull-request.yml b/.github/workflows/build-deploy-by-pull-request.yml index 1d9f0e63..816bc169 100644 --- a/.github/workflows/build-deploy-by-pull-request.yml +++ b/.github/workflows/build-deploy-by-pull-request.yml @@ -136,10 +136,10 @@ jobs: mkdir -p ~/opt/deployments/nginx/conf.d mkdir -p ~/opt/deployments/nginx/ssl/${{ needs.build.outputs.HOST }} cd ~/opt/deployments/nginx - docker stop nginx-root - docker rm nginx-root echo '${{ needs.build.outputs.NGINX_MAIN_CONFIG }}' > ./nginx.conf echo '${{ needs.build.outputs.NGINX_NO_SSL_TEMPLATE_CONFIG }}' > ./conf.d/${{ needs.build.outputs.HOST }}.conf + docker stop nginx-root + docker rm nginx-root docker run -p 80:80 -p 443:443 \ --net=host \ --name nginx-root \ From 9c63fab7e1ea9f3ed037d2d6aefa1529e311f76b Mon Sep 17 00:00:00 2001 From: asavienko Date: Tue, 31 Oct 2023 11:29:06 -0700 Subject: [PATCH 03/12] update script --- .github/workflows/build-deploy-by-pull-request.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-deploy-by-pull-request.yml b/.github/workflows/build-deploy-by-pull-request.yml index 816bc169..4775e253 100644 --- a/.github/workflows/build-deploy-by-pull-request.yml +++ b/.github/workflows/build-deploy-by-pull-request.yml @@ -144,10 +144,10 @@ jobs: --net=host \ --name nginx-root \ -d --restart=always \ - -v ./conf.d:/etc/nginx/conf.d \ - -v ./nginx.conf:/etc/nginx/nginx.conf \ - -v ./www:/var/www \ - -v ./ssl:/etc/nginx/ssl \ + -v $pwd/conf.d:/etc/nginx/conf.d \ + -v $pwd/nginx.conf:/etc/nginx/nginx.conf \ + -v $pwd/www:/var/www \ + -v $pwd/ssl:/etc/nginx/ssl \ nginx:alpine ## Issue and install SSL certificate /home/ubuntu/.acme.sh/acme.sh --issue \ From 01925fa95b746ee0916a28ab0feb05dfc20aa195 Mon Sep 17 00:00:00 2001 From: asavienko Date: Tue, 31 Oct 2023 11:30:49 -0700 Subject: [PATCH 04/12] update script --- .github/workflows/build-deploy-by-pull-request.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-deploy-by-pull-request.yml b/.github/workflows/build-deploy-by-pull-request.yml index 4775e253..99d46cba 100644 --- a/.github/workflows/build-deploy-by-pull-request.yml +++ b/.github/workflows/build-deploy-by-pull-request.yml @@ -144,10 +144,10 @@ jobs: --net=host \ --name nginx-root \ -d --restart=always \ - -v $pwd/conf.d:/etc/nginx/conf.d \ - -v $pwd/nginx.conf:/etc/nginx/nginx.conf \ - -v $pwd/www:/var/www \ - -v $pwd/ssl:/etc/nginx/ssl \ + -v $PWD/conf.d:/etc/nginx/conf.d \ + -v $PWD/nginx.conf:/etc/nginx/nginx.conf \ + -v $PWD/www:/var/www \ + -v $PWD/ssl:/etc/nginx/ssl \ nginx:alpine ## Issue and install SSL certificate /home/ubuntu/.acme.sh/acme.sh --issue \ From 25f53ae544faf87442a2961b0d78fcc01796fd9f Mon Sep 17 00:00:00 2001 From: asavienko Date: Tue, 31 Oct 2023 16:10:46 -0700 Subject: [PATCH 05/12] update ci --- .../build-deploy-by-pull-request.yml | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/build-deploy-by-pull-request.yml b/.github/workflows/build-deploy-by-pull-request.yml index 99d46cba..977cd635 100644 --- a/.github/workflows/build-deploy-by-pull-request.yml +++ b/.github/workflows/build-deploy-by-pull-request.yml @@ -109,6 +109,27 @@ jobs: -e RECAPTCHA_SITE_KEY=${{ secrets.RECAPTCHA_SITE_KEY }} \ ${{ needs.build.outputs.IMAGE_PREFIX }}/frontend:$PULL_REQUEST_NAME + + #DB + docker pull postgres + docker stop ${{ needs.build.outputs.DB_NAME }} || true + docker rm ${{ needs.build.outputs.DB_NAME }} || true + + docker network create ${{ needs.build.outputs.DB_NAME }} + + docker run -p ${{ needs.build.outputs.DB_PORT }}:5432 \ + --name ${{ needs.build.outputs.DB_NAME }} \ + -d --restart=always \ + --network=${{ needs.build.outputs.DB_NAME }} \ + -e POSTGRES_USER=${{ secrets.DB_USER }} \ + -e POSTGRES_PASSWORD=${{ secrets.DB_PASSWORD }} \ + -e POSTGRES_DB=${{ secrets.DB_NAME }} \ + postgres + + + + + # Backend docker pull ${{ needs.build.outputs.IMAGE_PREFIX }}/backend:$PULL_REQUEST_NAME docker stop simbolik-backend-$PULL_REQUEST_NAME From fe25ffb584ee58023417d122cca2279d0c754108 Mon Sep 17 00:00:00 2001 From: asavienko Date: Tue, 31 Oct 2023 16:18:36 -0700 Subject: [PATCH 06/12] update ci --- .github/workflows/build-deploy-by-push-action.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-deploy-by-push-action.yml b/.github/workflows/build-deploy-by-push-action.yml index fed727a9..55a40247 100644 --- a/.github/workflows/build-deploy-by-push-action.yml +++ b/.github/workflows/build-deploy-by-push-action.yml @@ -95,7 +95,13 @@ jobs: -e GRAPHQL_ENDPOINT=https://${{ needs.build.outputs.HOST }}/graphql \ -e RECAPTCHA_SITE_KEY=${{ secrets.RECAPTCHA_SITE_KEY }} \ ${{ needs.build.outputs.IMAGE_PREFIX }}/frontend:${{ github.ref_name }} - + + DATABASE_URL=$(printf "postgresql://%s:%s@%s/%s/simbolik?schema=${{ github.ref_name }}&connection_limit=40&pool_timeout=30" \ + ${{ secrets.DB_USER }} \ + ${{ secrets.DB_PASSWORD }} \ + ${{ secrets.DB_HOST_PORT }} \ + ${{ secrets.DB_NAME }}) + # Backend docker tag ${{ needs.build.outputs.IMAGE_PREFIX }}/backend:${{ github.ref_name }} ${{ needs.build.outputs.IMAGE_PREFIX }}/backend:${{ github.ref_name }}-backup docker pull ${{ needs.build.outputs.IMAGE_PREFIX }}/backend:${{ github.ref_name }} @@ -104,7 +110,7 @@ jobs: docker run -p ${{ needs.build.outputs.BACKEND_PORT }}:8080 \ --name simbolik-backend-${{ github.ref_name }} \ -d --restart=always \ - -e DATABASE_URL="postgresql://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@${{ secrets.POSTGRES_HOST }}:${{ secrets.POSTGRES_PORT }}/simbolik?schema=${{ github.ref_name }}&connection_limit=40&pool_timeout=30" \ + -e DATABASE_URL=$DATABASE_URL \ -e FRONTEND_URL=https://${{ needs.build.outputs.HOST }} \ -e GITHUB_CALLBACK_HOST=${{ needs.build.outputs.HOST }} \ -e GITHUB_CLIENT_ID=${{ secrets.GH_CLIENT_ID }} \ From b046a2c324bf63094e1336e7ee958ae2d3102cc9 Mon Sep 17 00:00:00 2001 From: asavienko Date: Tue, 31 Oct 2023 16:46:05 -0700 Subject: [PATCH 07/12] update ci --- .github/workflows/build-deploy-by-pull-request.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/build-deploy-by-pull-request.yml b/.github/workflows/build-deploy-by-pull-request.yml index 977cd635..7cffc2a9 100644 --- a/.github/workflows/build-deploy-by-pull-request.yml +++ b/.github/workflows/build-deploy-by-pull-request.yml @@ -18,6 +18,8 @@ jobs: NGINX_SSL_TEMPLATE_CONFIG: ${{ steps.process-outputs.outputs.NGINX_SSL_TEMPLATE_CONFIG }} IMAGE_PREFIX: ${{ steps.process-outputs.outputs.IMAGE_PREFIX }} IMAGE_TAG: ${{ steps.process-outputs.outputs.IMAGE_TAG }} + DB_PORT: ${{ steps.process-outputs.outputs.DB_PORT }} + DB_NAME: ${{ steps.process-outputs.outputs.DB_NAME }} steps: # - name: Get GitHub payload # env: # GITHUB_CONTEXT: ${{ toJson(vars) }} @@ -33,6 +35,11 @@ jobs: BACKEND_PORT=$(printf "%d" $(expr 15000 + $PULL_REQUEST_NUMBER)) HOST=$(printf "pr-%s.%s" ${{ github.event.number }} ${{ vars.HOST }}) IMAGE_TAG=$(printf "pr-%s" ${{ github.event.number }}) + DB_PORT=$(printf "%d" $(expr 20000 + $PR_NUMBER)) + DB_NAME=$(printf "kaas-db-pr-%s" $PR_NUMBER) + echo "HOST=$HOST" >> $GITHUB_OUTPUT + echo "DB_PORT=$DB_PORT" >> $GITHUB_OUTPUT + echo "DB_NAME=$DB_NAME" >> $GITHUB_OUTPUT echo "FRONTEND_PORT=$FRONTEND_PORT" >> $GITHUB_OUTPUT echo "BACKEND_PORT=$BACKEND_PORT" >> $GITHUB_OUTPUT echo "HOST=$HOST" >> $GITHUB_OUTPUT From b08205e2ca791008ab73f162748cb3da414aee7e Mon Sep 17 00:00:00 2001 From: asavienko Date: Tue, 31 Oct 2023 17:03:00 -0700 Subject: [PATCH 08/12] update ci --- .github/workflows/build-deploy-by-pull-request.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-deploy-by-pull-request.yml b/.github/workflows/build-deploy-by-pull-request.yml index 7cffc2a9..6405ea0a 100644 --- a/.github/workflows/build-deploy-by-pull-request.yml +++ b/.github/workflows/build-deploy-by-pull-request.yml @@ -35,8 +35,8 @@ jobs: BACKEND_PORT=$(printf "%d" $(expr 15000 + $PULL_REQUEST_NUMBER)) HOST=$(printf "pr-%s.%s" ${{ github.event.number }} ${{ vars.HOST }}) IMAGE_TAG=$(printf "pr-%s" ${{ github.event.number }}) - DB_PORT=$(printf "%d" $(expr 20000 + $PR_NUMBER)) - DB_NAME=$(printf "kaas-db-pr-%s" $PR_NUMBER) + DB_PORT=$(printf "%d" $(expr 20000 + $PULL_REQUEST_NUMBER)) + DB_NAME=$(printf "kaas-db-pr-%s" $PULL_REQUEST_NUMBER) echo "HOST=$HOST" >> $GITHUB_OUTPUT echo "DB_PORT=$DB_PORT" >> $GITHUB_OUTPUT echo "DB_NAME=$DB_NAME" >> $GITHUB_OUTPUT From afddc24074fb7b791a97a2681e4e4f1235312dba Mon Sep 17 00:00:00 2001 From: asavienko Date: Tue, 31 Oct 2023 17:28:48 -0700 Subject: [PATCH 09/12] update ci --- .github/workflows/build-deploy-by-pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-deploy-by-pull-request.yml b/.github/workflows/build-deploy-by-pull-request.yml index 6405ea0a..3efe6a04 100644 --- a/.github/workflows/build-deploy-by-pull-request.yml +++ b/.github/workflows/build-deploy-by-pull-request.yml @@ -144,7 +144,7 @@ jobs: docker run -p ${{ needs.build.outputs.BACKEND_PORT }}:8080 \ --name simbolik-backend-$PULL_REQUEST_NAME \ -d --restart=always \ - -e DATABASE_URL="postgresql://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@${{ secrets.POSTGRES_HOST }}:${{ secrets.POSTGRES_PORT }}/simbolik?schema=$PULL_REQUEST_NAME&connection_limit=40&pool_timeout=30" \ + -e DATABASE_URL="postgresql://${{ secrets.DB_USER }}:${{ secrets.DB_PASSWORD }}@${{ needs.build.outputs.DB_NAME }}/simbolik?schema=$PULL_REQUEST_NAME&connection_limit=40&pool_timeout=30" \ -e FRONTEND_URL=https://${{ needs.build.outputs.HOST }} \ -e GITHUB_CLIENT_ID=${{ secrets.GH_CLIENT_ID }} \ -e GITHUB_CLIENT_SECRET=${{ secrets.GH_CLIENT_SECRET }} \ From b4e784f37a7bf86c2cb223d6248ab357294335a2 Mon Sep 17 00:00:00 2001 From: asavienko Date: Tue, 31 Oct 2023 17:52:13 -0700 Subject: [PATCH 10/12] update ci --- .github/workflows/build-deploy-by-pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-deploy-by-pull-request.yml b/.github/workflows/build-deploy-by-pull-request.yml index 3efe6a04..12db99f8 100644 --- a/.github/workflows/build-deploy-by-pull-request.yml +++ b/.github/workflows/build-deploy-by-pull-request.yml @@ -36,7 +36,7 @@ jobs: HOST=$(printf "pr-%s.%s" ${{ github.event.number }} ${{ vars.HOST }}) IMAGE_TAG=$(printf "pr-%s" ${{ github.event.number }}) DB_PORT=$(printf "%d" $(expr 20000 + $PULL_REQUEST_NUMBER)) - DB_NAME=$(printf "kaas-db-pr-%s" $PULL_REQUEST_NUMBER) + DB_NAME=$(printf "simbolik-db-pr-%s" $PULL_REQUEST_NUMBER) echo "HOST=$HOST" >> $GITHUB_OUTPUT echo "DB_PORT=$DB_PORT" >> $GITHUB_OUTPUT echo "DB_NAME=$DB_NAME" >> $GITHUB_OUTPUT From 7cf012907195da9ef2607f3643b7df6eeff34ac5 Mon Sep 17 00:00:00 2001 From: asavienko Date: Tue, 31 Oct 2023 18:21:42 -0700 Subject: [PATCH 11/12] update ci --- .github/workflows/build-deploy-by-pull-request.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-deploy-by-pull-request.yml b/.github/workflows/build-deploy-by-pull-request.yml index 12db99f8..34c78bc6 100644 --- a/.github/workflows/build-deploy-by-pull-request.yml +++ b/.github/workflows/build-deploy-by-pull-request.yml @@ -144,6 +144,7 @@ jobs: docker run -p ${{ needs.build.outputs.BACKEND_PORT }}:8080 \ --name simbolik-backend-$PULL_REQUEST_NAME \ -d --restart=always \ + --network=${{ needs.build.outputs.DB_NAME }} \ -e DATABASE_URL="postgresql://${{ secrets.DB_USER }}:${{ secrets.DB_PASSWORD }}@${{ needs.build.outputs.DB_NAME }}/simbolik?schema=$PULL_REQUEST_NAME&connection_limit=40&pool_timeout=30" \ -e FRONTEND_URL=https://${{ needs.build.outputs.HOST }} \ -e GITHUB_CLIENT_ID=${{ secrets.GH_CLIENT_ID }} \ From 3ba12831c1248862c457869d182ae44a0b1757ab Mon Sep 17 00:00:00 2001 From: asavienko Date: Tue, 31 Oct 2023 19:53:24 -0700 Subject: [PATCH 12/12] update redirect --- frontend/pages/access-token.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/pages/access-token.tsx b/frontend/pages/access-token.tsx index 1d022567..c273df0a 100644 --- a/frontend/pages/access-token.tsx +++ b/frontend/pages/access-token.tsx @@ -7,6 +7,7 @@ import { useEffect } from 'react'; */ export default function AccessTokenPage() { const { token } = useRouter().query; + const router = useRouter(); useEffect(() => { if (!token) { @@ -14,6 +15,7 @@ export default function AccessTokenPage() { } localStorage.setItem('token', token as string); + router.push('/account'); }, [token]); return (