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

Conversation

alishaz-polymath
Copy link
Member

This PR attempts to add a runtime check as well as runtime logs and build logs to the docker-build-push-dockerhub.yml workflow

@krumware
Copy link
Member

Happy to review! I see you're still pushing some things. Give me a heads up when it's ready

@alishaz-polymath
Copy link
Member Author

Happy to review! I see you're still pushing some things. Give me a heads up when it's ready

Hey, Yeah. Still working through. I'll ping once it's ready for your review 🙌

@krumware
Copy link
Member

krumware commented Sep 27, 2023

@alishaz-polymath one quick thought, for convenience you could create another docker-compose.yml (maybe in a /test folder? a docker-compose.test.yaml maybe), which provides a different command for the calcom container to run, and effectively run unit tests or integration tests instead of the standard start script.
https://docs.docker.com/compose/multiple-compose-files/extends/

@alishaz-polymath
Copy link
Member Author

@krumware Thank you, I'll give it a go tomorrow, pretty late here 😅

@alishaz-polymath
Copy link
Member Author

Hey @krumware Can you please review? I think we can revisit the suggestion you left earlier for maybe next week (I will take it up next week), but if you could review the rest, it would be super awesome 🙌

Copy link
Member Author

@alishaz-polymath alishaz-polymath left a comment

Choose a reason for hiding this comment

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

Self Review added



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.

Comment on lines +134 to +145
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
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.

Comment on lines +151 to +152
NEXTAUTH_SECRET: 'EI4qqDpcfdvf4A+0aQEEx8JjHxHSy4uWiZw/F32K+pA='
CALENDSO_ENCRYPTION_KEY: '0zfLtY99wjeLnsM7qsa8xsT+Q0oSgnOL'
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

Copy link
Member

@krumware krumware left a comment

Choose a reason for hiding this comment

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

Can we split the build and push into two steps that sandwich the test step? It should work pretty close to the way you have it now. That will also let you run the tests against the built image instead of the hardcoded docker.io/calcom/cal.com:add-runtime-check, then we can prevent the push if the test fails. Currently it will push before it fails.

See for an example:

      - name: Build and export to Docker
        uses: docker/build-push-action@v5
        with:
          context: .
          load: true
          tags: ${{ steps.meta.outputs.tags }}
      - name: Test
        run: |
          docker run --rm ${{ steps.meta.outputs.tags[0] }}          
      - name: Build and push
        uses: docker/build-push-action@v5
        with:
          context: .
          platforms: linux/amd64
          push: true
          tags: ${{ steps.meta.outputs.tags }}

(full disclosure, I can't remember if I'm selecting the first tag in the array of tags properly in that docker run step)

modified from https://docs.docker.com/build/ci/github-actions/test-before-push/

@alishaz-polymath
Copy link
Member Author

Oh nice catch indeed! I'll take it up tomorrow morning 🙏

Comment on lines +158 to +164
- 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
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.

Comment on lines +21 to +25
# Uncomment below to allow specific version workflow run
# inputs:
# version:
# description: 'Version to build'
# required: true
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

@alishaz-polymath
Copy link
Member Author

alishaz-polymath commented Sep 29, 2023

For added context: I've tested this with v3.2.8 and runtime test fails (as expected), but goes through fine with v3.0.0 (as expected). 🙏

@alishaz-polymath
Copy link
Member Author

@krumware Gentle nudge for review 🙏

@krumware
Copy link
Member

krumware commented Oct 3, 2023

Sorry for delay, travelling. Looks good, comments included can be addressed in the future. Thanks!

@krumware krumware merged commit f89ea70 into main Oct 3, 2023
@krumware krumware deleted the add-runtime-check branch October 3, 2023 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants