Skip to content

feat(action): add Github action to build and push image to registry #2

feat(action): add Github action to build and push image to registry

feat(action): add Github action to build and push image to registry #2

name: Build and push image to GitHub Container Registry
on: pull_request
# on:
# push:
# branches:
# - "main"
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
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
- name: checkout
uses: actions/checkout@v4
- name: Git submodule update
run: |
git submodule update --init
- 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: |
ghcr.io/matheoleger/cal.com
- 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=${{ secrets.NEXT_PUBLIC_WEBAPP_URL }}
NEXT_PUBLIC_API_V2_URL=${{ secrets.NEXT_PUBLIC_API_V2_URL }}
NEXT_PUBLIC_LICENSE_CONSENT=${{ secrets.NEXT_PUBLIC_LICENSE_CONSENT }}
- 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
NETWORK=$(docker network ls --format {{.Name}} --filter name=github_network)
docker run --rm \
--network $NETWORK \
-p 3000:3000 \
-e NEXT_PUBLIC_WEBAPP_URL=localhost:3000 \
-e NEXT_PUBLIC_API_V2_URL=${{ secrets.NEXT_PUBLIC_API_V2_URL }} \
-e DATABASE_URL=postgresql://postgres:postgres@postgres:5432/calendso \
-e DATABASE_DIRECT_URL=postgresql://postgres:postgres@postgres:5432/calendso \
-e NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }} \
-e CALENDSO_ENCRYPTION_KEY=${{ secrets.CALENDSO_ENCRYPTION_KEY }} \
$tag &
server_pid=$!
echo "Waiting for the server to start..."
sleep 120
echo localhost:3000/auth/login
for i in {1..60}; do
echo "Checking server health ($i/60)..."
response=$(curl -o /dev/null -s -w "%{http_code}" localhost:3000/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
- 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=${{ secrets.NEXT_PUBLIC_WEBAPP_URL }}
NEXT_PUBLIC_API_V2_URL=${{ secrets.NEXT_PUBLIC_API_V2_URL }}
NEXT_PUBLIC_LICENSE_CONSENT=${{ secrets.NEXT_PUBLIC_LICENSE_CONSENT }}
if: ${{ !github.event.release.prerelease }}