-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
localhost-to-dockerhub: Use skopeo to "push" images
The old scripts depended on having the built images locally tagged. The new multi-arch images are pushed directly to the local registry. One might think it'd be possible to pull from localhost, tag locally, then push to Docker Hub - but that has problems [1]. The new scripts utilize registry API tooling (skopeo) to interface with the registries directly without unnecessary pull/push. A containerized version is used since the version pre-installed on the GitHub Actions Ubuntu runners does not support --multi-arch [2]. Notably, the tag-latest script is replaced by a conditional block in the new script which copies the tag from localhost to latest on Docker Hub. [1]: https://stackoverflow.com/a/68576882 [2]: https://github.com/containers/skopeo/releases/tag/v1.6.0
- Loading branch information
Showing
5 changed files
with
67 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/bash | ||
# | ||
# Push the nextstrain/base and nextstrain/base-builder images from the local registry to Docker Hub. | ||
# | ||
# This pushes just the provided tag. If "latest" is provided as a second argument, | ||
# the provided tag will also be pushed as "latest" | ||
# | ||
# Errors if any of the tagged images have already been pushed. | ||
# | ||
set -euo pipefail | ||
|
||
if [[ $# -lt 1 ]]; then | ||
echo "Please provide a tag." >&2 | ||
exit 1 | ||
fi | ||
|
||
tag=$1 | ||
|
||
BASE_IMAGE="nextstrain/base" | ||
BASE_BUILDER_IMAGE="nextstrain/base-builder" | ||
|
||
if [[ $(docker image inspect --format "{{.RepoDigests}}" $BASE_IMAGE:$tag) != '[]' || $(docker image inspect --format "{{.RepoDigests}}" $BASE_BUILDER_IMAGE:$tag) != '[]' ]]; then | ||
echo "At least one of $BASE_IMAGE:$tag and $BASE_BUILDER_IMAGE:$tag has already been pushed. This can happen if the newly built image is not available in the local registry." >&2 | ||
exit 1 | ||
fi | ||
|
||
|
||
# Use Skopeo via a Docker container to copy a tagged image. | ||
# https://github.com/containers/skopeo/blob/07da29fd371dd88615a0b86e91c6824237484172/install.md#container-images | ||
copy-image() { | ||
local source="$1" | ||
local dest="$2" | ||
|
||
docker run --rm \ | ||
-v $HOME/.docker/config.json:/docker-auth.json:ro \ | ||
--network="host" \ | ||
quay.io/skopeo/stable \ | ||
copy \ | ||
--multi-arch=all \ | ||
--src-tls-verify=false \ | ||
--dest-authfile /docker-auth.json \ | ||
$source $dest | ||
} | ||
|
||
# copy local $tag to remote $tag | ||
copy-image \ | ||
docker://localhost:5000/$BASE_IMAGE:$tag \ | ||
docker://docker.io/$BASE_IMAGE:$tag | ||
copy-image \ | ||
docker://localhost:5000/$BASE_BUILDER_IMAGE:$tag \ | ||
docker://docker.io/$BASE_BUILDER_IMAGE:$tag | ||
|
||
if [[ "$tag" != latest && "${2:-}" == latest ]]; then | ||
# copy local $tag to remote latest | ||
copy-image \ | ||
docker://localhost:5000/$BASE_IMAGE:$tag \ | ||
docker://docker.io/$BASE_IMAGE:latest | ||
copy-image \ | ||
docker://localhost:5000/$BASE_BUILDER_IMAGE:$tag \ | ||
docker://docker.io/$BASE_BUILDER_IMAGE:latest | ||
fi |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.