-
Notifications
You must be signed in to change notification settings - Fork 3
147 lines (133 loc) · 4.73 KB
/
hetzner-prd-workflow.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: hetzner production workflow
on:
pull_request:
branches:
- main
- develop
push:
branches:
- main
- 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:
lock_file:
runs-on: [self-hosted, "hetzner"]
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- run: uv lock --locked
linting:
runs-on: [self-hosted, "hetzner"]
needs: [lock_file]
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- run: uvx ruff check .
formatting:
runs-on: [self-hosted, "hetzner"]
needs: [lock_file]
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- run: uvx ruff format --check .
# type_consistency:
# runs-on: [self-hosted, "hetzner"]
# needs: [lock_file]
# steps:
# - uses: actions/checkout@v4
# - uses: ./.github/actions/setup
# - run: uv run pyright
tests:
runs-on: [self-hosted, "hetzner"]
needs: [lock_file]
env:
ENV: "DVP"
DATABASE_URL: "mysql+aiomysql://root:root_bot_buster@mysql:3306/playerdata"
KAFKA_HOST: "localhost:9092"
POOL_RECYCLE: 60
POOL_TIMEOUT: 30
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: ".python-version"
- name: Setup Docker Containers
run: |
docker-compose --verbose up --build -d
- name: Check API is Up
uses: cygnetdigital/[email protected]
with:
url: "http://localhost:5000/docs"
responseCode: "200,500"
timeout: 120000 # wait up to 120 seconds
interval: 5000 # poll every 5 seconds
- run: uv run pytest -v --durations=0 --cov --cov-report=xml
# This workflow contains two jobs: build_image and update_image_version
build_image:
runs-on: [self-hosted, "hetzner"]
needs: [tests]
# Run only on manual trigger
if: ${{ github.event_name == 'workflow_dispatch' }}
# 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
# Run only on manual trigger
if: ${{ github.event_name == 'workflow_dispatch' }}
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 }}"
}