Skip to content

Commit

Permalink
chore: push Docker images with latest tag by default (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Oct 10, 2023
1 parent 656836b commit 7de4271
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build regtest image
run: ./docker/build.py buildx regtest

- name: Build backend image
run: ./docker/build.py buildx boltz
- name: Push backend image
# Cross compiling to ARM64 is broken right now
run: ./docker/build.py buildx --platform linux/amd64 boltz
6 changes: 4 additions & 2 deletions docker/boltz/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ RUN git clone https://github.com/BoltzExchange/boltz-backend.git
WORKDIR /boltz-backend

RUN git checkout ${VERSION}
RUN npm install -g npm

RUN npm ci
# Remove dependency that is not needed for the build and unavailable on ARM64
RUN sed -i "/grpc-tools/d" package.json

RUN npm install
RUN npm run compile

FROM node:${NODE_VERSION} AS final
Expand Down
30 changes: 17 additions & 13 deletions docker/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def build_images(
to_build: list[str],
organisation: str,
no_cache: bool,
no_latest: bool,
buildx: bool,
platform: str = "",
) -> None:
Expand All @@ -196,21 +197,20 @@ def build_images(
# join the array to a string
args = " ".join(["--build-arg " + entry for entry in build_args])

name = f"{organisation}/{image}"
dockerfile = f"{image}/Dockerfile"

if buildx:
extra_tag = "" if no_latest else f"--tag {name}:latest"
command = (
"docker buildx build --push {args} --platform "
+ platform
+ " --file {dockerfile} --tag {name}:{tag} ."
f"docker buildx build --push {args} --platform {platform} "
f"--file {dockerfile} --tag {name}:{tag} {extra_tag} ."
)
else:
command = "docker build -t {name}:{tag} -f {dockerfile} {args} ."

command = command.format(
tag=tag,
args=args,
name=f"{organisation}/{image}",
dockerfile=f"{image}/Dockerfile",
)
extra_tag = "" if no_latest else f"-t {name}:latest"
command = (
f"docker build -t {name}:{tag} {extra_tag} -f {dockerfile} {args} ."
)

if no_cache:
command = command + " --no-cache"
Expand Down Expand Up @@ -253,6 +253,7 @@ def parse_images(to_parse: list[str]) -> list[str]:

BUILD_PARSER.add_argument("images", type=str, nargs="*")
BUILD_PARSER.add_argument("--no-cache", dest="no_cache", action="store_true")
BUILD_PARSER.add_argument("--no-latest", dest="no_latest", action="store_true")
BUILD_PARSER.add_argument(
"--organisation",
default="boltz",
Expand All @@ -261,9 +262,9 @@ def parse_images(to_parse: list[str]) -> list[str]:

BUILDX_PARSER.add_argument("images", type=str, nargs="*")
BUILDX_PARSER.add_argument("--no-cache", dest="no_cache", action="store_true")
BUILDX_PARSER.add_argument("--no-latest", dest="no_latest", action="store_true")
BUILDX_PARSER.add_argument(
"--platform",
action="store_true",
default="linux/amd64,linux/arm64",
help="The platforms to build for",
)
Expand All @@ -280,12 +281,15 @@ def parse_images(to_parse: list[str]) -> list[str]:
if ARGS.command == "list":
list_images(PARSED_IMAGES)
elif ARGS.command == "build":
build_images(PARSED_IMAGES, ARGS.organisation, ARGS.no_cache, False)
build_images(
PARSED_IMAGES, ARGS.organisation, ARGS.no_cache, ARGS.no_latest, False
)
elif ARGS.command == "buildx":
build_images(
PARSED_IMAGES,
ARGS.organisation,
ARGS.no_cache,
ARGS.no_latest,
True,
ARGS.platform,
)

0 comments on commit 7de4271

Please sign in to comment.