This repository was archived by the owner on Oct 5, 2026. It is now read-only.
Repository navigation
123 lines (109 loc) · 3.76 KB
/
Copy pathdeploy.yml
File metadata and controls
123 lines (109 loc) · 3.76 KB
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
name: Deploy
on:
workflow_call:
inputs:
environment:
required: true
type: string
version:
required: false
type: string
default: ''
jobs:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.meta.outputs.version }}
image-tag: ${{ steps.meta.outputs.image-tag }}
steps:
- uses: actions/checkout@v6
- name: Login GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Set tags & version
id: meta
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
VERSION="${INPUT_VERSION:-$SHORT_SHA}"
if [ "${{ inputs.environment }}" = "prod" ]; then
echo "tags=ghcr.io/gc-stats/api:latest,ghcr.io/gc-stats/api:${VERSION}" >> $GITHUB_OUTPUT
echo "image-tag=latest" >> $GITHUB_OUTPUT
else
echo "tags=ghcr.io/gc-stats/api:preprod" >> $GITHUB_OUTPUT
echo "image-tag=preprod" >> $GITHUB_OUTPUT
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Build & Push
uses: docker/build-push-action@v7
with:
push: true
no-cache: true
tags: ${{ steps.meta.outputs.tags }}
build-args: |
RELEASE_VERSION=${{ steps.meta.outputs.version }}
resolve-servers:
runs-on: ubuntu-latest
needs: build
environment: ${{ inputs.environment }}
outputs:
primary: ${{ steps.servers.outputs.primary }}
rest: ${{ steps.servers.outputs.rest }}
hook-id: ${{ steps.servers.outputs.hook-id }}
steps:
- name: Resolve server list
id: servers
env:
SERVERS: ${{ vars.SERVERS }}
run: |
if [ -z "$SERVERS" ]; then
echo "❌ vars.SERVERS is not set for the '${{ inputs.environment }}' environment"
exit 1
fi
IFS=',' read -ra ALL <<< "$SERVERS"
PRIMARY="${ALL[0]}"
REST=("${ALL[@]:1}")
REST_JSON=$(printf '%s\n' "${REST[@]:-}" | jq -R . | jq -sc '[.[] | select(length > 0)]')
HOOK_ID="gcs-api"
echo "primary=$PRIMARY" >> $GITHUB_OUTPUT
echo "rest=$REST_JSON" >> $GITHUB_OUTPUT
echo "hook-id=$HOOK_ID" >> $GITHUB_OUTPUT
deploy-primary:
runs-on: ubuntu-latest
needs: [build, resolve-servers]
environment: ${{ inputs.environment }}
steps:
- uses: actions/checkout@v6
- name: Deploy to primary server
uses: ./.github/actions/deploy-webhook
with:
server: ${{ needs.resolve-servers.outputs.primary }}
hook-id: ${{ needs.resolve-servers.outputs.hook-id }}
secret: ${{ secrets.DEPLOY_WEBHOOK_SECRET }}
image-tag: ${{ needs.build.outputs.image-tag }}
version: ${{ needs.build.outputs.version }}
verify-health: ${{ inputs.environment == 'prod' }}
deploy-rest:
runs-on: ubuntu-latest
needs: [build, resolve-servers, deploy-primary]
if: needs.resolve-servers.outputs.rest != '[]'
environment: ${{ inputs.environment }}
strategy:
fail-fast: false
matrix:
server: ${{ fromJSON(needs.resolve-servers.outputs.rest) }}
steps:
- uses: actions/checkout@v6
- name: Deploy to ${{ matrix.server }}
uses: ./.github/actions/deploy-webhook
with:
server: ${{ matrix.server }}
hook-id: ${{ needs.resolve-servers.outputs.hook-id }}
secret: ${{ secrets.DEPLOY_WEBHOOK_SECRET }}
image-tag: ${{ needs.build.outputs.image-tag }}
version: ${{ needs.build.outputs.version }}
verify-health: 'true'