Skip to content

Commit

Permalink
Update scripts to reflect 3-stage build
Browse files Browse the repository at this point in the history
Apart from this commit, it was necessary to create 2 new repositories in
the nextstrain Docker Hub organization.
  • Loading branch information
victorlin committed Jun 13, 2023
1 parent b178d54 commit 4c364f3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 25 deletions.
42 changes: 31 additions & 11 deletions devel/build
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,36 @@ if ! docker buildx inspect "$builder" &>/dev/null; then
docker buildx create --name "$builder" --driver docker-container --driver-opt network=host
fi

BUILDER_IMAGE=nextstrain/base-builder
BUILD_PLATFORM_BUILDER_IMAGE=nextstrain/base-builder-build-platform
TARGET_PLATFORM_BUILDER_IMAGE=nextstrain/base-builder-target-platform
FINAL_IMAGE=nextstrain/base

docker buildx build \
--target builder \
--target builder-build-platform \
--builder "$builder" \
--platform "$platform" \
--build-arg CACHE_DATE \
--cache-from "$BUILDER_IMAGE:latest" \
--cache-from "$BUILDER_IMAGE:$tag" \
--cache-from "$registry/$BUILDER_IMAGE:latest" \
--cache-from "$registry/$BUILDER_IMAGE:$tag" \
--cache-from "$BUILD_PLATFORM_BUILDER_IMAGE:latest" \
--cache-from "$BUILD_PLATFORM_BUILDER_IMAGE:$tag" \
--cache-from "$registry/$BUILD_PLATFORM_BUILDER_IMAGE:latest" \
--cache-from "$registry/$BUILD_PLATFORM_BUILDER_IMAGE:$tag" \
--cache-to type=inline \
--tag "$registry/$BUILDER_IMAGE:$tag" \
--tag "$registry/$BUILD_PLATFORM_BUILDER_IMAGE:$tag" \
--push \
--provenance false \
.

docker buildx build \
--target builder-target-platform \
--builder "$builder" \
--platform "$platform" \
--build-arg CACHE_DATE \
--cache-from "$TARGET_PLATFORM_BUILDER_IMAGE:latest" \
--cache-from "$TARGET_PLATFORM_BUILDER_IMAGE:$tag" \
--cache-from "$registry/$TARGET_PLATFORM_BUILDER_IMAGE:latest" \
--cache-from "$registry/$TARGET_PLATFORM_BUILDER_IMAGE:$tag" \
--cache-to type=inline \
--tag "$registry/$TARGET_PLATFORM_BUILDER_IMAGE:$tag" \
--push \
--provenance false \
.
Expand All @@ -77,12 +93,16 @@ docker buildx build \
--platform "$platform" \
--build-arg GIT_REVISION \
--build-arg CACHE_DATE \
--cache-from "$BUILDER_IMAGE:latest" \
--cache-from "$BUILDER_IMAGE:$tag" \
--cache-from "$BUILD_PLATFORM_BUILDER_IMAGE:latest" \
--cache-from "$BUILD_PLATFORM_BUILDER_IMAGE:$tag" \
--cache-from "$TARGET_PLATFORM_BUILDER_IMAGE:latest" \
--cache-from "$TARGET_PLATFORM_BUILDER_IMAGE:$tag" \
--cache-from "$FINAL_IMAGE:latest" \
--cache-from "$FINAL_IMAGE:$tag" \
--cache-from "$registry/$BUILDER_IMAGE:latest" \
--cache-from "$registry/$BUILDER_IMAGE:$tag" \
--cache-from "$registry/$BUILD_PLATFORM_BUILDER_IMAGE:latest" \
--cache-from "$registry/$BUILD_PLATFORM_BUILDER_IMAGE:$tag" \
--cache-from "$registry/$TARGET_PLATFORM_BUILDER_IMAGE:latest" \
--cache-from "$registry/$TARGET_PLATFORM_BUILDER_IMAGE:$tag" \
--cache-from "$registry/$FINAL_IMAGE:latest" \
--cache-from "$registry/$FINAL_IMAGE:$tag" \
--cache-to type=inline \
Expand Down
33 changes: 22 additions & 11 deletions devel/copy-images
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ if [[ "$tag" = "" ]]; then
exit 1
fi

BUILDER_IMAGE=nextstrain/base-builder
BUILD_PLATFORM_BUILDER_IMAGE=nextstrain/base-builder-build-platform
TARGET_PLATFORM_BUILDER_IMAGE=nextstrain/base-builder-target-platform
FINAL_IMAGE=nextstrain/base


Expand Down Expand Up @@ -77,26 +78,36 @@ copy-image() {

# Copy $tag between registries.

echo "Copying $registry_in/$BUILD_PLATFORM_BUILDER_IMAGE:$tag to $registry_out/$BUILD_PLATFORM_BUILDER_IMAGE:$tag."
copy-image \
"$registry_in/$BUILD_PLATFORM_BUILDER_IMAGE:$tag" \
"$registry_out/$BUILD_PLATFORM_BUILDER_IMAGE:$tag"

echo "Copying $registry_in/$TARGET_PLATFORM_BUILDER_IMAGE:$tag to $registry_out/$TARGET_PLATFORM_BUILDER_IMAGE:$tag."
copy-image \
"$registry_in/$TARGET_PLATFORM_BUILDER_IMAGE:$tag" \
"$registry_out/$TARGET_PLATFORM_BUILDER_IMAGE:$tag"

echo "Copying $registry_in/$FINAL_IMAGE:$tag to $registry_out/$FINAL_IMAGE:$tag."
copy-image \
"$registry_in/$FINAL_IMAGE:$tag" \
"$registry_out/$FINAL_IMAGE:$tag"

echo "Copying $registry_in/$BUILDER_IMAGE:$tag to $registry_out/$BUILDER_IMAGE:$tag."
copy-image \
"$registry_in/$BUILDER_IMAGE:$tag" \
"$registry_out/$BUILDER_IMAGE:$tag"

if [[ "$push_latest" = true ]]; then
# Copy $tag to latest.

echo "Copying $registry_in/$BUILD_PLATFORM_BUILDER_IMAGE:$tag to $registry_out/$BUILD_PLATFORM_BUILDER_IMAGE:latest."
copy-image \
"$registry_in/$BUILD_PLATFORM_BUILDER_IMAGE:$tag" \
"$registry_out/$BUILD_PLATFORM_BUILDER_IMAGE:latest"

echo "Copying $registry_in/$TARGET_PLATFORM_BUILDER_IMAGE:$tag to $registry_out/$TARGET_PLATFORM_BUILDER_IMAGE:latest."
copy-image \
"$registry_in/$TARGET_PLATFORM_BUILDER_IMAGE:$tag" \
"$registry_out/$TARGET_PLATFORM_BUILDER_IMAGE:latest"

echo "Copying $registry_in/$FINAL_IMAGE:$tag to $registry_out/$FINAL_IMAGE:latest."
copy-image \
"$registry_in/$FINAL_IMAGE:$tag" \
"$registry_out/$FINAL_IMAGE:latest"

echo "Copying $registry_in/$BUILDER_IMAGE:$tag to $registry_out/$BUILDER_IMAGE:latest."
copy-image \
"$registry_in/$BUILDER_IMAGE:$tag" \
"$registry_out/$BUILDER_IMAGE:latest"
fi
6 changes: 5 additions & 1 deletion devel/delete-from-ghcr.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

module.exports = async ({octokit, tag}) => {
org = 'nextstrain';
packages = ['base', 'base-builder'];
packages = [
'base',
'base-builder-build-platform',
'base-builder-target-platform',
];

// Try all packages before terminating with any errors.
let errorEncountered = false;
Expand Down
6 changes: 4 additions & 2 deletions devel/pull-from-registry
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ while getopts "r:t:" opt; do
esac
done

BUILDER_IMAGE=nextstrain/base-builder
BUILD_PLATFORM_BUILDER_IMAGE=nextstrain/base-builder-build-platform
TARGET_PLATFORM_BUILDER_IMAGE=nextstrain/base-builder-target-platform
FINAL_IMAGE=nextstrain/base

docker pull "$registry/$BUILDER_IMAGE:$tag"
docker pull "$registry/$BUILD_PLATFORM_BUILDER_IMAGE:$tag"
docker pull "$registry/$TARGET_PLATFORM_BUILDER_IMAGE:$tag"
docker pull "$registry/$FINAL_IMAGE:$tag"

0 comments on commit 4c364f3

Please sign in to comment.