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

Build docker image in CI #2015

Merged
merged 9 commits into from
Jun 17, 2024

Conversation

richardolsson
Copy link
Member

@richardolsson richardolsson commented Jun 6, 2024

Description

This PR sets up a CI workflow to build a docker image and push it to the GitHub container registry.

Screenshots

None

Changes

  • Adds a GitHub Actions workflow to build Docker images, that is executed when something is merged into the release branch
  • Changes the Dockerfile so that NEXT.js is built into the image
  • Adds .github to the .dockerignore so that github workflows do not affect the image itself

Notes to reviewer

I appreciate that this might be difficult for anyone except myself to review, but any feedback (even questions) would be useful for me to really think this through.

Related issues

Undocumented

@richardolsson richardolsson force-pushed the undocumented/build-docker-image-from-gh-action branch from e69cc5e to 2343026 Compare June 7, 2024 06:06
Base automatically changed from issue-1786/env-vars-in-context to main June 7, 2024 13:12
@richardolsson richardolsson marked this pull request as ready for review June 14, 2024 15:12
@richardolsson
Copy link
Member Author

I'd also love to hear from @benjaoming and @voxpelli. 😊

@voxpelli
Copy link
Contributor

@richardolsson Looks good to me 👍

Copy link
Contributor

@benjaoming benjaoming left a comment

Choose a reason for hiding this comment

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

Looks great! Gonna add a further idea in a comment outside the review.

.github/workflows/delivery.yml Show resolved Hide resolved
.github/workflows/delivery.yml Show resolved Hide resolved
@benjaoming
Copy link
Contributor

Additional speculation...

Considering that this is perhaps gradually going to mature into more automated setups, you could also additionally experiment with getting closer to some "build=>test=>deploy" pipeline... one way could be by only pushing images if the current test workflow succeeds? (I mean, you merge to release manually, so at this stage, it should be a deliberate decision).

There's also the issue that if tests sometimes break for no good reasons, then the deploy isn't started... but that's good to know if things should be more automated 💡

I think if you run the current main workflow on the release branch as well, you can write something like...

on:
  workflow_run:
    workflows: [main]
    types: [completed]
    branches: [release]

...then adding if: ${{ github.event.workflow_run.conclusion == 'success' }} in the jobs.

https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#limiting-your-workflow-to-run-based-on-branches

https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-a-workflow-based-on-the-conclusion-of-another-workflow

@richardolsson
Copy link
Member Author

richardolsson commented Jun 16, 2024

Thank you @voxpelli and @benjaoming for having a look!

Considering that this is perhaps gradually going to mature into more automated setups, you could also additionally experiment with getting closer to some "build=>test=>deploy" pipeline... one way could be by only pushing images if the current test workflow succeeds? (I mean, you merge to release manually, so at this stage, it should be a deliberate decision).

The way I've solved this for now is by setting up branch protection rules on GitHub. In order to update release, we have to make a PR, and that PR will run the tests and needs to be up to date (i.e. it is not allowed to be behind the release branch).

So the workflow will be like this:

  1. Create PR from main to release (and document the changes in the PR)
  2. GitHub runs all our tests on the PR, and blocks merge if it fails
  3. Merge the PR into release
  4. GitHub builds and pushes docker images from release
  5. GitHub triggers our deployment scripts via webhook

Copy link
Contributor

@ziggabyte ziggabyte left a comment

Choose a reason for hiding this comment

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

I don't see anything obviously strange, and I trust you, Benjamin and Pelle to have good skills around this area! Merge it!

@ziggabyte ziggabyte merged commit 8417778 into main Jun 17, 2024
5 checks passed
@ziggabyte ziggabyte deleted the undocumented/build-docker-image-from-gh-action branch June 17, 2024 15:03
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.

4 participants