Skip to content

Commit

Permalink
added workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
extreme4all committed Sep 22, 2023
1 parent 90d71cb commit c16c40f
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ENV = "DVP"
DATABASE_URL = "mysql+aiomysql://username:password@localhost/database_name"
DATABASE_URL = "mysql+aiomysql://username:password@localhost/database_name"
KAFKA_HOST = "kafka:9092"
83 changes: 83 additions & 0 deletions .github/workflows/hetzner-prd-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: hetzner production workflow

# Controls when the workflow will run
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
on:
# Triggers the workflow on push events but only for the "develop" branch
push:
branches:
- develop

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

env:
VALUE_FILE: public-api-prd/deployment.yaml
REGISTRY: quay.io/bot_detector/public-api
ENVIRONMENT: prd

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# 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"]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: git checkout
uses: actions/checkout@v3

- name: Set vars
id: vars
run: |
echo "GIT_HASH=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_OUTPUT
- name: Docker Build
run: |
docker build . --file Dockerfile --network=host -t "${REGISTRY}:${{ steps.vars.outputs.GIT_HASH }}" --target production --build-arg api_port=5000 --build-arg root_path=""
- 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}"
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: ${{ env.VALUE_FILE }}
token: "${{ secrets.HETZNER_ACTIONS_RUNNER_TOKEN }}"
commitChange: true
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": "${{ env.REGISTRY }}:${{ steps.vars.outputs.GIT_HASH }}"
}

0 comments on commit c16c40f

Please sign in to comment.