From 39397f8552f8995587df9e9f802c24e2170614b4 Mon Sep 17 00:00:00 2001 From: extreme4all <40169115+extreme4all@users.noreply.github.com> Date: Tue, 15 Aug 2023 22:15:15 +0200 Subject: [PATCH 1/2] Update hetzner-prd-workflow.yml --- .github/workflows/hetzner-prd-workflow.yml | 51 ++++++++++++++-------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/.github/workflows/hetzner-prd-workflow.yml b/.github/workflows/hetzner-prd-workflow.yml index 94652fa..193316d 100644 --- a/.github/workflows/hetzner-prd-workflow.yml +++ b/.github/workflows/hetzner-prd-workflow.yml @@ -16,14 +16,14 @@ permissions: write-all env: VALUE_FILE: bd-discord-prd/deployment.yaml REGISTRY: quay.io/bot_detector/bd-discord-bot - + ENVIRONMENT: prd # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" + # This workflow contains two jobs: build_image and update_image_version build_image: # The type of runner that the job will run on - runs-on: [self-hosted, hetzner] + runs-on: [self-hosted, "hetzner"] # Steps represent a sequence of tasks that will be executed as part of the job steps: @@ -35,36 +35,51 @@ jobs: id: vars run: | echo "GIT_HASH=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_OUTPUT - echo "REGISTRY=$REGISTRY" >> $GITHUB_OUTPUT - echo "VALUE_FILE=$VALUE_FILE" >> $GITHUB_OUTPUT - - # Runs a command using the runners shell - - name: docker build - run: docker build . --file Dockerfile --network=host -t "$REGISTRY:${{ steps.vars.outputs.GIT_HASH }}" --target production --build-arg api_port=3000 --build-arg root_path=/ - - name: login to registry - run: echo "${{ secrets.QUAY_REGISTERY_PASSWORD }}" | docker login -u="bot_detector+quay_robot" quay.io --password-stdin + - name: Docker Build + run: | + docker build . --file Dockerfile --network=host -t "${REGISTRY}:${{ steps.vars.outputs.GIT_HASH }}" + + - name: Login to Quay registry + run: echo "${{ secrets.QUAY_REGISTERY_PASSWORD }}" | docker login -u "bot_detector+quay_robot" quay.io --password-stdin + + - name: Tag image + run: | + docker tag "${REGISTRY}:${{ steps.vars.outputs.GIT_HASH }}" "${REGISTRY}:${ENVIRONMENT}" + + - name: Docker Push image to Quay registry + run: | + docker push "${REGISTRY}:${{ steps.vars.outputs.GIT_HASH }}" + docker push "${REGISTRY}:${ENVIRONMENT}" - - name: docker push image to registry - run: docker push "$REGISTRY:${{ steps.vars.outputs.GIT_HASH }}" + update_image_version: + runs-on: [self-hosted, "hetzner"] + needs: build_image # This ensures that the build_image job is completed before running this job + steps: - name: Checkout Target Repository uses: actions/checkout@v3 with: repository: Bot-detector/bot-detector-k8s + - name: Set vars + id: vars + run: | + echo "GIT_HASH=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_OUTPUT + - name: Update Image Version uses: fjogeleit/yaml-update-action@main with: repository: Bot-detector/bot-detector-k8s - valueFile: "${{ steps.vars.outputs.VALUE_FILE }}" - token: ${{ secrets.HETZNER_ACTIONS_RUNNER_TOKEN }} + valueFile: ${{ env.VALUE_FILE }} + token: "${{ secrets.HETZNER_ACTIONS_RUNNER_TOKEN }}" commitChange: true - branch: "${{ steps.vars.outputs.GIT_HASH }}" + title: "${{ env.VALUE_FILE }}_${{ steps.vars.outputs.GIT_HASH }}" + branch: "${{ env.VALUE_FILE }}_${{ steps.vars.outputs.GIT_HASH }}" targetBranch: develop masterBranchName: develop createPR: true changes: | { - "spec.template.spec.containers[0].image":"${{ steps.vars.outputs.REGISTRY }}:${{ steps.vars.outputs.GIT_HASH }}" - } \ No newline at end of file + "spec.template.spec.containers[0].image": "${{ env.REGISTRY }}:${{ steps.vars.outputs.GIT_HASH }}" + } From 494f1ecc913e35304e8e93f3c38347f398ddc85b Mon Sep 17 00:00:00 2001 From: extreme4all <40169115+extreme4all@users.noreply.github.com> Date: Tue, 15 Aug 2023 22:16:10 +0200 Subject: [PATCH 2/2] Delete production-workflow.yml --- .github/workflows/production-workflow.yml | 38 ----------------------- 1 file changed, 38 deletions(-) delete mode 100644 .github/workflows/production-workflow.yml diff --git a/.github/workflows/production-workflow.yml b/.github/workflows/production-workflow.yml deleted file mode 100644 index 19033fc..0000000 --- a/.github/workflows/production-workflow.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Docker Image CI - -on: - push: - branches: [main] - -jobs: - build: - runs-on: self-hosted - - steps: - - uses: actions/checkout@v2 - - name: Set Up ENV - run: | - echo "${{ secrets.TOKEN }}" > ./src/.env - echo "${{ secrets.API_TOKEN }}" >> ./src/.env - echo "${{ secrets.COMMAND_PREFIX }}" >> ./src/.env - echo "${{ secrets.WEBHOOK }}" >> ./src/.env - echo "${{ secrets.API_URL }}" >> ./src/.env - echo "${{ secrets.SQL_URI }}" >> ./src/.env - - - name: Build the Docker image - run: docker build . --file Dockerfile -t bot-detector/bd-discord-bot:latest - - - name: Tag Image - run: docker tag bot-detector/bd-discord-bot:latest hub.osrsbotdetector.com/bot-detector/bd-discord-bot:latest - - - name: Login to Docker Registry - run: echo "${{ secrets.DOCKER_REGISTRY_PASSWORD }}" | docker login https://hub.osrsbotdetector.com -u "${{ secrets.DOCKER_REGISTRY_USERNAME }}" --password-stdin - - - name: Push Image to Registry - run: docker push hub.osrsbotdetector.com/bot-detector/bd-discord-bot:latest - - - name: Apply Possible Deployment Changes - run: kubectl apply -f deployment/prd/ - - - name: Restart Deployment for Possible Container Changes - run: kubectl rollout restart deploy bd-discord-bot