Skip to content

Commit

Permalink
Push container images properly: (#223)
Browse files Browse the repository at this point in the history
## Description

<!--- Please describe what this PR is going to change -->
Because of the way CI is built (2 self-hosted runners), CI was not
pushing container images when building on main. This was because PR's
would build the images and the would be locally in the Docker cache.
Then when main ran, hook-lk containers.sh would run and see that the
image existed in the local Docker cache already and stop before pushing.

## Why is this needed

<!--- Link to issue you have raised -->

Fixes: #

## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->


## How are existing users impacted? What migration steps/scripts do we
need?

<!--- Fixes a bug, unblocks installation, removes a component of the
stack etc -->
<!--- Requires a DB migration script, etc. -->


## Checklist:

I have:

- [ ] updated the documentation and/or roadmap (if required)
- [ ] added unit or e2e tests
- [ ] provided instructions on how to upgrade
  • Loading branch information
jacobweinstock authored May 17, 2024
2 parents 9323116 + e0d143c commit 74e114f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions bash/hook-lk-containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ function build_hook_linuxkit_container() {
log debug "Checking if image ${container_oci_ref} exists in local registry"
if [[ -n "$(docker images -q "${container_oci_ref}")" ]]; then
log info "Image ${container_oci_ref} exists in local registry, skipping build"
# we try to push here because a previous build may have created the image
# this is the case for GitHub Actions CI because we build PRs on the same self-hosted runner
push_hook_linuxkit_container "${container_oci_ref}"
return 0
fi

Expand All @@ -55,6 +58,15 @@ function build_hook_linuxkit_container() {

log info "Built ${container_oci_ref} from ${container_dir} for platform ${DOCKER_ARCH}"

push_hook_linuxkit_container "${container_oci_ref}"

return 0
}


function push_hook_linuxkit_container() {
declare container_oci_ref="${1}"

# Push the image to the registry, if DO_PUSH is set to yes
if [[ "${DO_PUSH}" == "yes" ]]; then
docker push "${container_oci_ref}" || {
Expand All @@ -64,6 +76,4 @@ function build_hook_linuxkit_container() {
else
log info "Skipping push of ${container_oci_ref} to registry; set DO_PUSH=yes to push."
fi

return 0
}

0 comments on commit 74e114f

Please sign in to comment.