This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
forked from calcom/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
217 lines (188 loc) · 7.71 KB
/
docker-build-push-dockerhub.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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# This is a basic workflow to help you get started with Actions
name: Build and push image to DockerHub
# Controls when the workflow will run
on:
push:
tags:
- 'v*'
# update on run of Update Calendso nightly submodule update
workflow_run:
workflows: ["Update Calendso"]
branches: [main]
types:
- completed
# Allow running workflow manually from the Actions tab
workflow_dispatch:
inputs:
branch:
description: 'Branch to build on'
type: string
default: main
# Uncomment below to allow specific version workflow run
# inputs:
# version:
# description: 'Version to build'
# required: true
# Leaving in example for releases. Initially we simply push to 'latest'
# on:
# release:
# types: [ created ]
# 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"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# Free about 4.5 GB, elminating our disk space issues
tool-cache: true
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it, uncomment below
# - name: Checkout code at specified version
# uses: actions/checkout@v2
# with:
# ref: ${{ github.event.inputs.version }}
- name: checkout
uses: actions/checkout@v4
- name: Delete submodule
run: |
rm -rf calcom
mkdir calcom
- name: Fetch git repo
uses: actions/checkout@v4
with:
repository: YouthCatalyst/calendar
ref: ${{ inputs.branch }}
path: calcom
token: ${{ secrets.GH_TOKEN }}
- name: Get Cal repo branch
id: get-branch
run: |
BRANCH=${{ inputs.branch }}
echo "git-branch=${BRANCH#RELEASE/}" >> "$GITHUB_OUTPUT"
- name: Log in to the Docker Hub registry
uses: docker/login-action@v3
with:
# Username used to log against the Docker registry
username: ${{ secrets.DOCKER_HUB_USERNAME }}
# Password or personal access token used to log against the Docker registry
password: ${{ secrets.DOCKER_HUB_TOKEN }}
# Log out from the Docker registry at the end of a job
logout: true # optional, default is true
- name: Log in to the Github Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
docker.io/youthcatalyst/calendar
tags: |
type=raw,value=${{ steps.get-branch.outputs.git-branch }}
# Add flavor latest only on full releases, not on pre-releases
flavor: |
latest=${{ !github.event.release.prerelease }}
- name: Copy env
run: |
grep -o '^[^#]*' .env.example > .env
cat .env >> $GITHUB_ENV
echo "DATABASE_HOST=localhost:5432" >> $GITHUB_ENV
eval $(sed -e '/^#/d' -e 's/^/export /' -e 's/$/;/' .env) ;
# Temporarily disable ARM build due to runner performance issues
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v2
- name: Start database
run: |
docker compose up -d database
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
network=container:database
buildkitd-flags: |
--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host
# config-inline: |
# [worker.oci]
# max-parallelism = 1
- name: Build image
id: docker_build
uses: docker/build-push-action@v5
with:
context: ./
file: ./Dockerfile
load: true # Load the image into the Docker daemon
push: false # Do not push the image at this stage
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
NEXT_PUBLIC_WEBAPP_URL=${{ env.NEXT_PUBLIC_WEBAPP_URL }}
NEXT_PUBLIC_API_V2_URL=${{ env.NEXT_PUBLIC_API_V2_URL }}
NEXT_PUBLIC_LICENSE_CONSENT=${{ env.NEXT_PUBLIC_LICENSE_CONSENT }}
NEXT_PUBLIC_TELEMETRY_KEY=${{ env.NEXT_PUBLIC_TELEMETRY_KEY }}
DATABASE_URL=postgresql://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@${{ env.DATABASE_HOST }}/${{ env.POSTGRES_DB }}
DATABASE_DIRECT_URL=postgresql://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@${{ env.DATABASE_HOST }}/${{ env.POSTGRES_DB }}
- name: Test runtime
run: |
tags="${{ steps.meta.outputs.tags }}"
IFS=',' read -ra ADDR <<< "$tags" # Convert string to array using ',' as delimiter
tag=${ADDR[0]} # Get the first tag
docker run --rm --network stack \
-p 3000:3000 \
-e DATABASE_URL=postgresql://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@database/${{ env.POSTGRES_DB }} \
-e DATABASE_DIRECT_URL=postgresql://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@database/${{ env.POSTGRES_DB }} \
-e NEXTAUTH_SECRET=${{ env.NEXTAUTH_SECRET }} \
-e CALENDSO_ENCRYPTION_KEY=${{ env.CALENDSO_ENCRYPTION_KEY }} \
$tag &
server_pid=$!
echo "Waiting for the server to start..."
sleep 120
echo ${{ env.NEXT_PUBLIC_WEBAPP_URL }}/auth/login
for i in {1..60}; do
echo "Checking server health ($i/60)..."
response=$(curl -o /dev/null -s -w "%{http_code}" ${{ env.NEXT_PUBLIC_WEBAPP_URL }}/auth/login)
echo "HTTP Status Code: $response"
if [[ "$response" == "200" ]] || [[ "$response" == "307" ]]; then
echo "Server is healthy"
# Now, shutdown the server
kill $server_pid
exit 0
fi
sleep 1
done
echo "Server health check failed"
kill $server_pid
exit 1
env:
NEXTAUTH_SECRET: 'EI4qqDpcfdvf4A+0aQEEx8JjHxHSy4uWiZw/F32K+pA='
CALENDSO_ENCRYPTION_KEY: '0zfLtY99wjeLnsM7qsa8xsT+Q0oSgnOL'
- name: Push image
id: docker_push
uses: docker/build-push-action@v5
with:
context: ./
file: ./Dockerfile
push: true
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
NEXT_PUBLIC_WEBAPP_URL=${{ env.NEXT_PUBLIC_WEBAPP_URL }}
NEXT_PUBLIC_API_V2_URL=${{ env.NEXT_PUBLIC_API_V2_URL }}
NEXT_PUBLIC_LICENSE_CONSENT=${{ env.NEXT_PUBLIC_LICENSE_CONSENT }}
NEXT_PUBLIC_TELEMETRY_KEY=${{ env.NEXT_PUBLIC_TELEMETRY_KEY }}
DATABASE_URL=postgresql://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@${{ env.DATABASE_HOST }}/${{ env.POSTGRES_DB }}
DATABASE_DIRECT_URL=postgresql://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@${{ env.DATABASE_HOST }}/${{ env.POSTGRES_DB }}
if: ${{ !github.event.release.prerelease }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
- name: Cleanup
run: |
docker compose down