Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add runtime check, runtime logs and build logs #293

Merged
merged 33 commits into from
Oct 3, 2023
Merged
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
fa788cf
Adds test runtime check
alishaz-polymath Sep 27, 2023
d299d9a
Add logging to build and runtime steps
alishaz-polymath Sep 27, 2023
fe5c310
temporary block push to dockerhub for local testing purposes
alishaz-polymath Sep 27, 2023
2b54576
Add load true to load image to local docker env
alishaz-polymath Sep 27, 2023
9a74219
Update image name in test runtime as digest isn't found/recognized
alishaz-polymath Sep 27, 2023
ff56a03
specify db container in test runtime
alishaz-polymath Sep 27, 2023
a049989
revert prev commit
alishaz-polymath Sep 27, 2023
5f2a14b
Add a network to specify where the DB is
alishaz-polymath Sep 27, 2023
5dbfc57
Revert prev
alishaz-polymath Sep 27, 2023
d4e0fce
Specify stack as network, as per docker-compose file
alishaz-polymath Sep 27, 2023
42e1b72
Remove WIP
alishaz-polymath Sep 27, 2023
83d34f8
specify 'database'
alishaz-polymath Sep 27, 2023
3161242
Add nextauth and calendso encryption to test runtime
alishaz-polymath Sep 28, 2023
1cb1dec
duh
alishaz-polymath Sep 28, 2023
bcdff6e
add health check
alishaz-polymath Sep 28, 2023
4870434
Increase health check time limit to allow boot
alishaz-polymath Sep 28, 2023
933f472
Increase timeout for testing
alishaz-polymath Sep 28, 2023
92512fd
use next-webapp-url for curl req domain
alishaz-polymath Sep 28, 2023
a1d56a1
Add server startup wait time~2mins
alishaz-polymath Sep 28, 2023
26784d6
debug curl call endpoint
alishaz-polymath Sep 28, 2023
8353418
verbose curl req
alishaz-polymath Sep 28, 2023
bd8a941
Publish on port 3000 for accessibility by health check
alishaz-polymath Sep 28, 2023
ff0db3a
Redirect is also representative of healthy
alishaz-polymath Sep 28, 2023
89bd10b
debug response
alishaz-polymath Sep 28, 2023
0048a58
Reduce number of attempts for server health check
alishaz-polymath Sep 28, 2023
008ddd5
Remove redundant steps of logging
alishaz-polymath Sep 28, 2023
f7885ee
Allow pushing to Dockerhub
alishaz-polymath Sep 28, 2023
d17064f
split build and push image and test in between
alishaz-polymath Sep 29, 2023
4be3f45
fix push step
alishaz-polymath Sep 29, 2023
a23fd8b
checkout spcific version
alishaz-polymath Sep 29, 2023
04e4c64
comment push to dockerhub for testing
alishaz-polymath Sep 29, 2023
34c213f
Ready
alishaz-polymath Sep 29, 2023
87379fe
remove unnecessary remnant
alishaz-polymath Sep 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 67 additions & 5 deletions .github/workflows/docker-build-push-dockerhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ on:
types:
- completed
# Allow running workflow manually from the Actions tab
# workflow_dispatch:
workflow_dispatch:
# Uncomment below to allow specific version workflow run
# inputs:
# version:
# description: 'Version to build'
# required: true
Comment on lines +20 to +24
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be beneficial in the future to test the workflow run against specific versions for a more targeted debugging

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good with adding this commented. would be good to add an additional input to toggle pushing as well here


# Leaving in example for releases. Initially we simply push to 'latest'
# on:
Expand All @@ -32,7 +38,12 @@ jobs:

# 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
# 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@v3

Expand Down Expand Up @@ -91,14 +102,15 @@ jobs:
# config-inline: |
# [worker.oci]
# max-parallelism = 1
- name: Build and push image

- name: Build image
id: docker_build
uses: docker/build-push-action@v4
with:
context: ./
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
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 }}
Expand All @@ -107,11 +119,61 @@ jobs:
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 }}

# - name: Build with docker compose
# run: |
# DOCKER_BUILDKIT=0 docker compose build --build-arg DATABASE_URL=postgresql://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@${{ env.DATABASE_HOST }}/${{ env.POSTGRES_DB }} calcom

- 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 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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We give 120 seconds for the server to be ready to accept curl request. It was erroring out with code 7 if we requested when it wasn't ready.


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
Comment on lines +147 to +158
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check every second until true if we can access /auth/login, and we tend to currently redirect it to /auth/setup but even that is a good indication of server being functional, so we accept both 200 and 307 to cover this.


echo "Server health check failed"
kill $server_pid
exit 1
env:
NEXTAUTH_SECRET: 'EI4qqDpcfdvf4A+0aQEEx8JjHxHSy4uWiZw/F32K+pA='
CALENDSO_ENCRYPTION_KEY: '0zfLtY99wjeLnsM7qsa8xsT+Q0oSgnOL'
Comment on lines +164 to +165
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure if it's better to pass these from env.<...> but this works well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's probably save since these are just arbitrary test values in this case


- name: Push image
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 push $tag
Comment on lines +167 to +173
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use docker push to push the built image and avoid re-building it after the runtime check is complete

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to check in a future PR if it's better to reuse the docker/build-push-action like in the example. It should't rebuild but that isn't clear in the docs I linked.



- name: Cleanup
run: |
docker compose down
Expand Down