Skip to content

Commit

Permalink
build: Make platform an argument
Browse files Browse the repository at this point in the history
This is prepping for the option of building with multiple platforms in a
future commit, while keeping the option to build with a single platform
locally.
  • Loading branch information
victorlin committed Dec 16, 2022
1 parent bf2d443 commit 4276b92
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
username: nextstrain-bot
password: ${{ secrets.GH_TOKEN_NEXTSTRAIN_BOT_MANAGE_PACKAGES }}

- run: ./devel/build -r ghcr.io -t $TAG
- run: ./devel/build -p linux/amd64 -r ghcr.io -t $TAG

outputs:
tag: ${{ env.TAG }}
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,16 @@ To build this image locally,
./devel/build
```

By default, this tags the image with `latest` and pushes to
By default, this builds for a single platform `linux/amd64`, tags the image with `latest`, and pushes to
`localhost:5000`. See instructions at the top of the script for additional
options.

If the target platform is different from the build platform, set up emulation before running `./devel/build`. This can be achieved using [`tonistiigi/binfmt`](https://github.com/tonistiigi/binfmt). For example, to set up emulation for `linux/arm64`, run:

```
docker run --privileged --rm tonistiigi/binfmt --install arm64
```

On each subsequent change during your development iterations, you can run just
the `./devel/build` command again.

Expand Down
8 changes: 4 additions & 4 deletions devel/build
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
set -euo pipefail

# Set default values.
platform=linux/amd64
registry=localhost:5000
tag=latest

# Read command-line arguments.
while getopts "r:t:" opt; do
while getopts "p:r:t:" opt; do
case "$opt" in
p) platform="$OPTARG";;
r) registry="$OPTARG";;
t) tag="$OPTARG";;
*) echo "Usage: $0 [-r <registry>] [-t <tag>]" 1>&2; exit 1;;
*) echo "Usage: $0 [-p <platform>] [-r <registry>] [-t <tag>]" 1>&2; exit 1;;
esac
done

Expand All @@ -36,8 +38,6 @@ export GIT_REVISION=$(git describe --tags --abbrev=40 --always --dirty || true)
# Calling `docker run nextstrain/base` will still only pull down the small base
# image rather than pulling down the larger nextstrain/base-builder image.

platform=linux/amd64

# `buildx create` is necessary to use a driver that supports multi-platform
# images.
builder=nextstrain-builder
Expand Down

0 comments on commit 4276b92

Please sign in to comment.