Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/cli/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ def image():

@image.command()
@click.option("--repo", required=True, type=str)
@click.option("--branch", required=True, type=str)
@click.option("--commit-sha", required=True, type=str)
@click.option("--registry", required=True, type=str)
@click.option("--tag", required=True, type=str)
@click.option("--build-args", required=False, type=str)
@click.option("--arches", required=False, type=str)
@click.option("--action", required=False, type=str)
def build(repo, branch, registry, tag, build_args, arches, action="load"):
def build(repo, commit_sha, registry, tag, build_args, arches, action="load"):
"""
Build bitcoind and bitcoin-cli from <repo>/<branch> as <registry>:<tag>.
Build bitcoind and bitcoin-cli from <repo> at <commit_sha> as <registry>:<tag>.
Optionally deploy to remote registry using --action=push, otherwise image is loaded to local registry.
"""
res = build_image(repo, branch, registry, tag, build_args, arches, action)
res = build_image(repo, commit_sha, registry, tag, build_args, arches, action)
if not res:
sys.exit(1)
6 changes: 3 additions & 3 deletions src/cli/image_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def run_command(command):

def build_image(
repo: str,
branch: str,
commit_sha: str,
docker_registry: str,
tag: str,
build_args: str,
Expand All @@ -38,7 +38,7 @@ def build_image(
return False

print(f"{repo=:}")
print(f"{branch=:}")
print(f"{commit_sha=:}")
print(f"{docker_registry=:}")
print(f"{tag=:}")
print(f"{build_args=:}")
Expand Down Expand Up @@ -70,7 +70,7 @@ def build_image(
f"docker buildx build"
f" --platform {platforms}"
f" --build-arg REPO={repo}"
f" --build-arg BRANCH={branch}"
f" --build-arg COMMIT_SHA={commit_sha}"
f" --build-arg BUILD_ARGS={build_args}"
f" --tag {image_full_name}"
f" --file src/templates/Dockerfile ."
Expand Down
10 changes: 6 additions & 4 deletions src/templates/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Setup deps stage
FROM alpine as deps
FROM alpine AS deps
ARG REPO
ARG BRANCH
ARG COMMIT_SHA
ARG BUILD_ARGS

RUN --mount=type=cache,target=/var/cache/apk \
Expand All @@ -27,14 +27,16 @@ COPY src/templates/addrman.patch /tmp/


# Clone and patch and build stage
FROM deps as build
FROM deps AS build
ENV BITCOIN_PREFIX=/opt/bitcoin
WORKDIR /build

RUN set -ex \
&& cd /build \
&& git clone --depth 1 --branch "${BRANCH}" "https://github.com/${REPO}" \
&& git clone --depth 1 "https://github.com/${REPO}" \
&& cd bitcoin \
&& git fetch --depth 1 origin "$COMMIT_SHA" \
&& git checkout "$COMMIT_SHA" \
Comment on lines +36 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL you can do this: fetch a commit from another branch even though you cloned depth 1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetch is from the remote, so really the clone is just needed to setup git with the remote, then you can fetch any commit_sha (at depth 1) after that.

It's prob even possible to do in a one-liner, but I don't got time for that

&& git apply /tmp/isroutable.patch \
&& git apply /tmp/addrman.patch \
&& sed -i s:sys/fcntl.h:fcntl.h: src/compat/compat.h \
Expand Down