-
Notifications
You must be signed in to change notification settings - Fork 12.8k
176 lines (161 loc) · 6.75 KB
/
release-docker.yaml
File metadata and controls
176 lines (161 loc) · 6.75 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
name: "Release Docker"
permissions:
contents: read
packages: write
env:
POSTGRES_USER: "unicorn_user"
POSTGRES_PASSWORD: "magical_password"
POSTGRES_DB: "calendso"
DATABASE_HOST: "database:5432"
on:
push:
tags:
- "v*"
# in case manual trigger is needed
workflow_dispatch:
inputs:
BUILD_FROM_BRANCH:
description: "Build from the selected branch instead of a tag"
type: boolean
default: false
RELEASE_TAG:
description: "Tag to build (e.g., v6.0.5) - required if BUILD_FROM_BRANCH is false"
required: false
PUSH_IMAGE:
description: "Push the Docker image to DockerHub"
type: boolean
default: true
jobs:
prepare:
name: "Prepare Release"
runs-on: ubuntu-latest
outputs:
release_tag: ${{ steps.determine-tag.outputs.release_tag }}
checkout_ref: ${{ steps.determine-tag.outputs.checkout_ref }}
steps:
- name: Validate inputs
if: github.event_name == 'workflow_dispatch' && inputs.BUILD_FROM_BRANCH == false && inputs.RELEASE_TAG == ''
run: |
echo "::error::RELEASE_TAG is required when BUILD_FROM_BRANCH is false"
exit 1
- name: checkout
uses: actions/checkout@v4
with:
ref: ${{ (github.event_name == 'workflow_dispatch' && inputs.BUILD_FROM_BRANCH) && github.ref || inputs.RELEASE_TAG || github.ref }}
- name: "Determine tag and ref"
id: determine-tag
run: |
# Determine checkout ref
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.BUILD_FROM_BRANCH }}" = "true" ]; then
echo "checkout_ref=${{ github.ref }}" >> $GITHUB_OUTPUT
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "checkout_ref=${{ inputs.RELEASE_TAG }}" >> $GITHUB_OUTPUT
else
echo "checkout_ref=${{ github.ref }}" >> $GITHUB_OUTPUT
fi
# Determine release tag
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
if [ "${{ inputs.BUILD_FROM_BRANCH }}" = "true" ]; then
# Extract branch name and short SHA for the tag
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
# Sanitize branch name: replace all invalid Docker tag characters with dashes
# Docker tags can only contain lowercase/uppercase letters, digits, underscores, periods, and dashes
# Also remove any leading dashes or periods
SANITIZED_BRANCH=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9_.-]/-/g' | sed 's/^[-.]*//')
SHORT_SHA=$(git rev-parse --short HEAD)
echo "release_tag=${SANITIZED_BRANCH}-${SHORT_SHA}" >> $GITHUB_OUTPUT
else
echo "release_tag=${{ inputs.RELEASE_TAG }}" >> $GITHUB_OUTPUT
fi
else
echo "release_tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
release-amd64:
name: "Release AMD64"
needs: prepare
runs-on: ubuntu-latest
env:
RELEASE_TAG: ${{ needs.prepare.outputs.release_tag }}
steps:
- name: checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.checkout_ref }}
- name: Build and test Docker image
uses: ./.github/actions/docker-build-and-test
with:
platform: "linux/amd64"
platform-suffix: ""
dockerhub-username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub-token: ${{ secrets.DOCKERHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
postgres-user: ${{ env.POSTGRES_USER }}
postgres-password: ${{ env.POSTGRES_PASSWORD }}
postgres-db: ${{ env.POSTGRES_DB }}
database-host: ${{ env.DATABASE_HOST }}
push-image: ${{ (github.event_name == 'push' || inputs.PUSH_IMAGE) && 'true' || 'false' }}
use-as-latest: "true"
- name: Notify Slack on Success
if: success() && secrets.CI_SLACK_WEBHOOK_URL != ''
uses: slackapi/slack-github-action@v1.24.0
with:
payload: |
{
"text": ":large_green_circle: Workflow *${{ github.workflow }}* (AMD64) succeeded in job *${{ github.job }}*.\nSee: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.CI_SLACK_WEBHOOK_URL }}
- name: Notify Slack on Failure
if: failure() && secrets.CI_SLACK_WEBHOOK_URL != ''
uses: slackapi/slack-github-action@v1.24.0
with:
payload: |
{
"text": ":red_circle: Workflow *${{ github.workflow }}* (AMD64) failed in job *${{ github.job }}*.\nSee: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.CI_SLACK_WEBHOOK_URL }}
release-arm:
name: "Release ARM"
needs: prepare
runs-on: ubuntu-24.04-arm
env:
RELEASE_TAG: ${{ needs.prepare.outputs.release_tag }}
steps:
- name: checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.checkout_ref }}
- name: Build and test Docker image
uses: ./.github/actions/docker-build-and-test
with:
platform: "arm64"
platform-suffix: "-arm"
dockerhub-username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub-token: ${{ secrets.DOCKERHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
postgres-user: ${{ env.POSTGRES_USER }}
postgres-password: ${{ env.POSTGRES_PASSWORD }}
postgres-db: ${{ env.POSTGRES_DB }}
database-host: ${{ env.DATABASE_HOST }}
push-image: ${{ (github.event_name == 'push' || inputs.PUSH_IMAGE) && 'true' || 'false' }}
- name: Notify Slack on Success
if: success() && secrets.CI_SLACK_WEBHOOK_URL != ''
uses: slackapi/slack-github-action@v1.24.0
with:
payload: |
{
"text": ":large_green_circle: Workflow *${{ github.workflow }}* (ARM) succeeded in job *${{ github.job }}*.\nSee: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.CI_SLACK_WEBHOOK_URL }}
- name: Notify Slack on Failure
if: failure() && secrets.CI_SLACK_WEBHOOK_URL != ''
uses: slackapi/slack-github-action@v1.24.0
with:
payload: |
{
"text": ":red_circle: Workflow *${{ github.workflow }}* (ARM) failed in job *${{ github.job }}*.\nSee: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.CI_SLACK_WEBHOOK_URL }}