From c133a606582b0094ff1421df6b4a71ebd8ddf518 Mon Sep 17 00:00:00 2001 From: Marcin Bator Date: Tue, 3 Dec 2024 18:22:35 +0100 Subject: [PATCH] fix: #dev-deploy tag fix 8 --- .github/workflows/dev.kodemy.deploy.yml | 206 +++++++++++++----------- 1 file changed, 108 insertions(+), 98 deletions(-) diff --git a/.github/workflows/dev.kodemy.deploy.yml b/.github/workflows/dev.kodemy.deploy.yml index c86afd2..0f73337 100644 --- a/.github/workflows/dev.kodemy.deploy.yml +++ b/.github/workflows/dev.kodemy.deploy.yml @@ -36,100 +36,100 @@ env: JWT_KEY: ${{ secrets.JWT_KEY }} jobs: - prepare: - name: Prepare - runs-on: self-hosted - environment: dev - steps: - - name: Check environments - run: | - REQUIRED_VARS=\ - ( - "WORKING_DIRECTORY" - "NETWORK_NAME" - "DATASOURCE_CONTAINER" - "DATASOURCE_USERNAME" - "DATASOURCE_PASSWORD" - "DATASOURCE_DB" - "RABBITMQ_HOST" - "RABBITMQ_PORT" - "RABBITMQ_USERNAME" - "RABBITMQ_PASSWORD" - "RABBITMQ_PASSWORD" - "ELASTICSEARCH_USERNAME" - "ELASTICSEARCH_PASSWORD" - "EUREKA_URL" - "FRONTEND_PUBLIC_HOST" - "CORS_ALLOWED_ORIGINS" - "GATEWAY_PUBLIC_HOST" - "OAUTH_GITHUB_ID" - "OAUTH_GITHUB_KEY" - "JWT_KEY" - "REDIS_HOST" - "REDIS_PORT" - ) - EXIT=0 - for VAR in "${REQUIRED_VARS[@]}"; do - [ -z "${!VAR}" ] && echo "Environment variable $VAR is missing." && EXIT=1 - done - exit $EXIT - update-branch: - name: Update branch - needs: [ prepare ] - runs-on: self-hosted - environment: dev - steps: - - name: Update ${{ github.ref_name }} - uses: appleboy/ssh-action@master - env: - BRANCH: ${{ github.ref_name }} - with: - host: ${{ secrets.REMOTE_HOST }} - username: ${{ secrets.REMOTE_USER }} - port: ${{ secrets.REMOTE_PORT }} - key: ${{ secrets.SSH_PRIVATE_KEY }} - envs: WORKING_DIRECTORY,BRANCH - script: | - cd $WORKING_DIRECTORY - git checkout $BRANCH || exit 1 - git pull origin $BRANCH || exit 1 - validate: - name: Validate services - runs-on: self-hosted - needs: [ update-branch ] - environment: dev - steps: - - name: Validate services - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.REMOTE_HOST }} - username: ${{ secrets.REMOTE_USER }} - port: ${{ secrets.REMOTE_PORT }} - key: ${{ secrets.SSH_PRIVATE_KEY }} - envs: WORKING_DIRECTORY,NETWORK_NAME,DATASOURCE_CONTAINER,DATASOURCE_USERNAME,DATASOURCE_DB - script: | - echo "Validate network" - docker network inspect $NETWORK_NAME > /dev/null 2>&1 \ - || { echo "Network $NETWORK_NAME is not available."; exit 1; } + # prepare: + # name: Prepare + # runs-on: self-hosted + # environment: dev + # steps: + # - name: Check environments + # run: | + # REQUIRED_VARS=\ + # ( + # "WORKING_DIRECTORY" + # "NETWORK_NAME" + # "DATASOURCE_CONTAINER" + # "DATASOURCE_USERNAME" + # "DATASOURCE_PASSWORD" + # "DATASOURCE_DB" + # "RABBITMQ_HOST" + # "RABBITMQ_PORT" + # "RABBITMQ_USERNAME" + # "RABBITMQ_PASSWORD" + # "RABBITMQ_PASSWORD" + # "ELASTICSEARCH_USERNAME" + # "ELASTICSEARCH_PASSWORD" + # "EUREKA_URL" + # "FRONTEND_PUBLIC_HOST" + # "CORS_ALLOWED_ORIGINS" + # "GATEWAY_PUBLIC_HOST" + # "OAUTH_GITHUB_ID" + # "OAUTH_GITHUB_KEY" + # "JWT_KEY" + # "REDIS_HOST" + # "REDIS_PORT" + # ) + # EXIT=0 + # for VAR in "${REQUIRED_VARS[@]}"; do + # [ -z "${!VAR}" ] && echo "Environment variable $VAR is missing." && EXIT=1 + # done + # exit $EXIT + # update-branch: + # name: Update branch + # needs: [ prepare ] + # runs-on: self-hosted + # environment: dev + # steps: + # - name: Update ${{ github.ref_name }} + # uses: appleboy/ssh-action@master + # env: + # BRANCH: ${{ github.ref_name }} + # with: + # host: ${{ secrets.REMOTE_HOST }} + # username: ${{ secrets.REMOTE_USER }} + # port: ${{ secrets.REMOTE_PORT }} + # key: ${{ secrets.SSH_PRIVATE_KEY }} + # envs: WORKING_DIRECTORY,BRANCH + # script: | + # cd $WORKING_DIRECTORY + # git checkout $BRANCH || exit 1 + # git pull origin $BRANCH || exit 1 + # validate: + # name: Validate services + # runs-on: self-hosted + # needs: [ update-branch ] + # environment: dev + # steps: + # - name: Validate services + # uses: appleboy/ssh-action@master + # with: + # host: ${{ secrets.REMOTE_HOST }} + # username: ${{ secrets.REMOTE_USER }} + # port: ${{ secrets.REMOTE_PORT }} + # key: ${{ secrets.SSH_PRIVATE_KEY }} + # envs: WORKING_DIRECTORY,NETWORK_NAME,DATASOURCE_CONTAINER,DATASOURCE_USERNAME,DATASOURCE_DB + # script: | + # echo "Validate network" + # docker network inspect $NETWORK_NAME > /dev/null 2>&1 \ + # || { echo "Network $NETWORK_NAME is not available."; exit 1; } - echo "Validate database - container" - docker exec -t $DATASOURCE_CONTAINER pg_isready \ - || { echo "PostgreSQL is not running."; exit 1; } + # echo "Validate database - container" + # docker exec -t $DATASOURCE_CONTAINER pg_isready \ + # || { echo "PostgreSQL is not running."; exit 1; } - echo "Validate database - database" - docker exec -t $DATASOURCE_CONTAINER psql -lqt -U $DATASOURCE_USERNAME | grep -q $DATASOURCE_DB \ - || { echo "Database $DATASOURCE_DB does not exist."; exit 1; } + # echo "Validate database - database" + # docker exec -t $DATASOURCE_CONTAINER psql -lqt -U $DATASOURCE_USERNAME | grep -q $DATASOURCE_DB \ + # || { echo "Database $DATASOURCE_DB does not exist."; exit 1; } - echo "Validate database - schemas" - DATASOURCE_SCHEMAS=("kodemy-auth" "kodemy-backend" "kodemy-notification") - for SCHEMA in "${DATASOURCE_SCHEMAS[@]}" - do - docker exec -t $DATASOURCE_CONTAINER psql \ - -U $DATASOURCE_USERNAME \ - -d $DATASOURCE_DB \ - -tAc "SELECT 1 FROM information_schema.schemata WHERE schema_name = '$SCHEMA'" \ - | grep -q 1 || { echo "Schema $SCHEMA does not exist."; exit 1; } - done + # echo "Validate database - schemas" + # DATASOURCE_SCHEMAS=("kodemy-auth" "kodemy-backend" "kodemy-notification") + # for SCHEMA in "${DATASOURCE_SCHEMAS[@]}" + # do + # docker exec -t $DATASOURCE_CONTAINER psql \ + # -U $DATASOURCE_USERNAME \ + # -d $DATASOURCE_DB \ + # -tAc "SELECT 1 FROM information_schema.schemata WHERE schema_name = '$SCHEMA'" \ + # | grep -q 1 || { echo "Schema $SCHEMA does not exist."; exit 1; } + # done # build-and-deploy: # name: Build, Test, Deploy @@ -190,6 +190,7 @@ jobs: create-tag: name: Create tag runs-on: self-hosted + environment: dev steps: - name: Determine new tag id: tag @@ -203,15 +204,24 @@ jobs: echo "TAG_NAME=$new_tag" >> $GITHUB_ENV - name: Create tag - uses: actions/github-script@v5 + uses: appleboy/ssh-action@master with: + host: ${{ secrets.REMOTE_HOST }} + username: ${{ secrets.REMOTE_USER }} + port: ${{ secrets.REMOTE_PORT }} + key: ${{ secrets.SSH_PRIVATE_KEY }} script: | - github.rest.git.createRef({ - owner: context.repo.owner, - repo: context.repo.repo, - ref: `refs/tags/${{ env.TAG_NAME }}`, - sha: context.sha - }); + git tag ${{ env.TAG_NAME }} + git push origin --tags + + # uses: actions/github-script@v5 + # script: | + # github.rest.git.createRef({ + # owner: context.repo.owner, + # repo: context.repo.repo, + # ref: `refs/tags/${{ env.TAG_NAME }}`, + # sha: context.sha + # });