From 87181e1a2889cc5d8f5812ee57ed36c771b2dee7 Mon Sep 17 00:00:00 2001 From: Dmitry Stoyanov Date: Thu, 3 Oct 2024 01:34:32 +0300 Subject: [PATCH 1/4] Added new workflow to deploy new instance --- .../docker-build-push-redeploy_new.yml | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 .github/workflows/docker-build-push-redeploy_new.yml diff --git a/.github/workflows/docker-build-push-redeploy_new.yml b/.github/workflows/docker-build-push-redeploy_new.yml new file mode 100644 index 000000000..2cb9265e8 --- /dev/null +++ b/.github/workflows/docker-build-push-redeploy_new.yml @@ -0,0 +1,79 @@ +name: Docker Build, Push images and redeploy new instance + +on: + push: + branches: + - devops/new_instance + +jobs: + # build_and_publish_backend: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v4 + # - name: Publish to Registry brainup/brn-backend + # uses: elgohr/Publish-Docker-Github-Action@master + # with: + # name: brainup/brn-backend + # username: ${{ secrets.DOCKER_USERNAME }} + # password: ${{ secrets.DOCKER_PASSWORD }} + # build_and_publish_frontend: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v4 + # - name: Publish to Registry brainup/brn-frontend + # uses: elgohr/Publish-Docker-Github-Action@master + # with: + # name: brainup/brn-frontend + # username: ${{ secrets.DOCKER_USERNAME }} + # password: ${{ secrets.DOCKER_PASSWORD }} + # dockerfile: Dockerfile_frontend + # build_and_publish_frontend_with_tls: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v4 + # - name: Publish to Registry brainup/brn-frontend-with-tls + # uses: elgohr/Publish-Docker-Github-Action@master + # with: + # name: brainup/brn-frontend-with-tls + # username: ${{ secrets.DOCKER_USERNAME }} + # password: ${{ secrets.DOCKER_PASSWORD }} + # dockerfile: Dockerfile_frontend_with_tls + redeploy_instance: + # needs: [ build_and_publish_backend, build_and_publish_frontend, build_and_publish_frontend_with_tls] + runs-on: ${{ matrix.runners }} + strategy: + matrix: + runners: [ selectel ] + steps: + - uses: actions/checkout@v4 + - name: Configure secrets + run: | + echo "$S3_KEY"|base64 -d > aws-key.properties + echo "$FIREBASE_CONFIG"|base64 -d > firebase_config.json + mv docker-compose-run.yml docker-compose.yml + sed -i -e "s/_YANDEX_AUTH_TOKEN_/\\$YANDEX_AUTH_TOKEN/" docker-compose.yml + sed -i -e "s/_YANDEX_FOLDER_ID_/\\$YANDEX_FOLDER_ID/" docker-compose.yml + sed -i -e "s/_POSTGRES_PASSWORD_/\\$POSTGRES_PASSWORD/" docker-compose.yml + sed -i -e "s/_API_GITHUB_TOKEN_/\\$API_GITHUB_TOKEN/" docker-compose.yml + env: + S3_KEY: ${{ secrets.S3_KEY }} + FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }} + YANDEX_AUTH_TOKEN: ${{ secrets.YANDEX_AUTH_TOKEN }} + YANDEX_FOLDER_ID: ${{ secrets.YANDEX_FOLDER_ID }} + POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} + API_GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }} +# It is unclear how to use IF, so option from the first link is used. In case of crash we can rewrite to if: ${{matrix.runners == 'vscale'}} +# Link 1: https://github.community/t/what-is-the-correct-if-condition-syntax-for-checking-matrix-os-version/16221 +# Link 2: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsif + - name: Redeploy backend + run: | + docker-compose pull + docker-compose up -d --no-deps brn + - name: Redeploy frontend vscale + if: matrix.runners == 'vscale' + run: docker-compose up -d --no-deps brn_fe_with_tls + - name: Redeploy frontend selectel + if: matrix.runners == 'selectel' + run: docker-compose up -d --no-deps brn_fe + - name: Remove old images + run: docker image prune -af From c131d8cb26307122c25a6485181da472928c48ef Mon Sep 17 00:00:00 2001 From: Dmitry Stoyanov Date: Thu, 3 Oct 2024 02:38:47 +0300 Subject: [PATCH 2/4] Added flag for db that already existed --- docker-compose-run.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose-run.yml b/docker-compose-run.yml index 153c7450d..0401b4032 100644 --- a/docker-compose-run.yml +++ b/docker-compose-run.yml @@ -9,6 +9,7 @@ services: POSTGRES_DB: brn POSTGRES_USER: admin POSTGRES_PASSWORD: _POSTGRES_PASSWORD_ + DATABASE_ALREADY_EXISTS: 'true' volumes: - dbdata:/var/lib/postgresql/data brn: From 149222601132d14f57756977003dfaa60407cb2b Mon Sep 17 00:00:00 2001 From: Dmitry Stoyanov Date: Thu, 3 Oct 2024 12:14:50 +0300 Subject: [PATCH 3/4] Changed vscale instance to selectel in main redeploy workflow --- .../workflows/docker-build-push-redeploy.yml | 10 +-- .../docker-build-push-redeploy_new.yml | 79 ------------------- 2 files changed, 3 insertions(+), 86 deletions(-) delete mode 100644 .github/workflows/docker-build-push-redeploy_new.yml diff --git a/.github/workflows/docker-build-push-redeploy.yml b/.github/workflows/docker-build-push-redeploy.yml index a4e91c237..1f501a15b 100644 --- a/.github/workflows/docker-build-push-redeploy.yml +++ b/.github/workflows/docker-build-push-redeploy.yml @@ -43,8 +43,7 @@ jobs: runs-on: ${{ matrix.runners }} strategy: matrix: - # runners: [ epam, vscale ] - runners: [ vscale ] + runners: [ selectel ] steps: - uses: actions/checkout@v4 - name: Configure secrets @@ -70,11 +69,8 @@ jobs: run: | docker-compose pull docker-compose up -d --no-deps brn - - name: Redeploy frontend epam - if: matrix.runners == 'epam' - run: docker-compose up -d --no-deps brn_fe - - name: Redeploy frontend vscale - if: matrix.runners == 'vscale' + - name: Redeploy frontend selectel + if: matrix.runners == 'selectel' run: docker-compose up -d --no-deps brn_fe_with_tls - name: Remove old images run: docker image prune -af diff --git a/.github/workflows/docker-build-push-redeploy_new.yml b/.github/workflows/docker-build-push-redeploy_new.yml deleted file mode 100644 index 2cb9265e8..000000000 --- a/.github/workflows/docker-build-push-redeploy_new.yml +++ /dev/null @@ -1,79 +0,0 @@ -name: Docker Build, Push images and redeploy new instance - -on: - push: - branches: - - devops/new_instance - -jobs: - # build_and_publish_backend: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v4 - # - name: Publish to Registry brainup/brn-backend - # uses: elgohr/Publish-Docker-Github-Action@master - # with: - # name: brainup/brn-backend - # username: ${{ secrets.DOCKER_USERNAME }} - # password: ${{ secrets.DOCKER_PASSWORD }} - # build_and_publish_frontend: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v4 - # - name: Publish to Registry brainup/brn-frontend - # uses: elgohr/Publish-Docker-Github-Action@master - # with: - # name: brainup/brn-frontend - # username: ${{ secrets.DOCKER_USERNAME }} - # password: ${{ secrets.DOCKER_PASSWORD }} - # dockerfile: Dockerfile_frontend - # build_and_publish_frontend_with_tls: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v4 - # - name: Publish to Registry brainup/brn-frontend-with-tls - # uses: elgohr/Publish-Docker-Github-Action@master - # with: - # name: brainup/brn-frontend-with-tls - # username: ${{ secrets.DOCKER_USERNAME }} - # password: ${{ secrets.DOCKER_PASSWORD }} - # dockerfile: Dockerfile_frontend_with_tls - redeploy_instance: - # needs: [ build_and_publish_backend, build_and_publish_frontend, build_and_publish_frontend_with_tls] - runs-on: ${{ matrix.runners }} - strategy: - matrix: - runners: [ selectel ] - steps: - - uses: actions/checkout@v4 - - name: Configure secrets - run: | - echo "$S3_KEY"|base64 -d > aws-key.properties - echo "$FIREBASE_CONFIG"|base64 -d > firebase_config.json - mv docker-compose-run.yml docker-compose.yml - sed -i -e "s/_YANDEX_AUTH_TOKEN_/\\$YANDEX_AUTH_TOKEN/" docker-compose.yml - sed -i -e "s/_YANDEX_FOLDER_ID_/\\$YANDEX_FOLDER_ID/" docker-compose.yml - sed -i -e "s/_POSTGRES_PASSWORD_/\\$POSTGRES_PASSWORD/" docker-compose.yml - sed -i -e "s/_API_GITHUB_TOKEN_/\\$API_GITHUB_TOKEN/" docker-compose.yml - env: - S3_KEY: ${{ secrets.S3_KEY }} - FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }} - YANDEX_AUTH_TOKEN: ${{ secrets.YANDEX_AUTH_TOKEN }} - YANDEX_FOLDER_ID: ${{ secrets.YANDEX_FOLDER_ID }} - POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} - API_GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }} -# It is unclear how to use IF, so option from the first link is used. In case of crash we can rewrite to if: ${{matrix.runners == 'vscale'}} -# Link 1: https://github.community/t/what-is-the-correct-if-condition-syntax-for-checking-matrix-os-version/16221 -# Link 2: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsif - - name: Redeploy backend - run: | - docker-compose pull - docker-compose up -d --no-deps brn - - name: Redeploy frontend vscale - if: matrix.runners == 'vscale' - run: docker-compose up -d --no-deps brn_fe_with_tls - - name: Redeploy frontend selectel - if: matrix.runners == 'selectel' - run: docker-compose up -d --no-deps brn_fe - - name: Remove old images - run: docker image prune -af From d7ddb45e2281f9dc00ac880c9af85e4d372b5cbe Mon Sep 17 00:00:00 2001 From: Dmitry Stoyanov Date: Thu, 3 Oct 2024 12:31:46 +0300 Subject: [PATCH 4/4] Updated actions/upload-artifact to v4 after deprecation v2 https://github.com/actions/upload-artifact --- .github/workflows/java-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/java-ci.yml b/.github/workflows/java-ci.yml index 1c73a34e6..1c642cf69 100644 --- a/.github/workflows/java-ci.yml +++ b/.github/workflows/java-ci.yml @@ -26,13 +26,13 @@ jobs: check_name: Gradle Unit and Integration Test Results files: build/test-results/**/*.xml - name: Upload Unit Test Results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: failure() with: name: Unit Test Results path: build/reports/tests/test/ - name: Upload Integration Test Results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: failure() with: name: Integration Test Results