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 our own caddy image #61881

Merged
merged 8 commits into from Apr 15, 2024
Merged

Build our own caddy image #61881

merged 8 commits into from Apr 15, 2024

Conversation

willdollman
Copy link
Contributor

@willdollman willdollman commented Apr 15, 2024

We currently just retag the upstream Caddy image where we use it in deploy-sourcegraph-docker. The upstream is slow to patch go module vulns, and the update process is different to the rest of our images.

Build a caddy container from scratch here to avoid having a separate update process, and to make use of the latest patched version of caddy from the wolfi repo.

Example of creating a new container image

This PR is also a good example of creating a new container image that uses a customised base image. The steps to create this PR were:

  • Create wolfi-images/caddy.yaml
  • Run sg wolfi lock caddy to generate the wolfi-images/caddy.lock.json lockfile
  • Add Bazel configuration (docker-images/caddy/BUILD.bazel) to build the full Caddy image using the base image configuration
    • Optionally test image build locally with sg wolfi image caddy or bazel run //docker-images/caddy:base_tarball
  • Add container structure tests (docker-images/caddy/image_test.yaml)
    • Optionally run tests locally with bazel run //docker-images/caddy:image_test

Test plan

  • Added container structure test
  • CI

@willdollman willdollman self-assigned this Apr 15, 2024
@cla-bot cla-bot bot added the cla-signed label Apr 15, 2024
The old setup resulted in a circular dep where if you added a new image, then to trigger an update you had to edit an existing lockfile.

Ideally we'd only invalidate when a wolfi-images/*.lock.json file changes, but unsure if this is possible
@willdollman willdollman marked this pull request as ready for review April 15, 2024 15:36
Comment on lines 43 to 45
# Used to invalidate this repository when any lockfiles change.
rctx.path(rctx.path("wolfi-images"))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Strum355 this works in some basic testing but not sure if there's a cleaner way to handle this. The issue I ran into was after adding the caddy image's yaml and lock.json files, the new lockfile wasn't in the dependency list -> repo wasn't invalidated -> repo isn't added to list -> GOTO 1.

Copy link
Member

Choose a reason for hiding this comment

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

You can use rctx.watch("wolfi-images") for this now that we're on bazel 7.1

Copy link
Member

Choose a reason for hiding this comment

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

Actually, youll want rctx.watch_tree given this is a directory

@willdollman willdollman requested a review from a team April 15, 2024 15:46
@willdollman
Copy link
Contributor Author

Tested the rctx.watch_tree() change by creating a new yaml + lockfile and running bazel build @mynewfile_apko_lock//:contents. It works, and without the change it fails.

Copy link
Member

@Strum355 Strum355 left a comment

Choose a reason for hiding this comment

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

love a streamlined process

@willdollman willdollman merged commit d8deee1 into main Apr 15, 2024
7 checks passed
@willdollman willdollman deleted the will/create-caddy-image branch April 15, 2024 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants