Skip to content

Commit 2377b7e

Browse files
authored
Merge pull request bitcoin-dev-project#397 from willcl-ark/build-by-commit
image: build by commit hash, not branch
2 parents 7f0a082 + 8c52b37 commit 2377b7e

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/cli/image.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ def image():
1212

1313
@image.command()
1414
@click.option("--repo", required=True, type=str)
15-
@click.option("--branch", required=True, type=str)
15+
@click.option("--commit-sha", required=True, type=str)
1616
@click.option("--registry", required=True, type=str)
1717
@click.option("--tag", required=True, type=str)
1818
@click.option("--build-args", required=False, type=str)
1919
@click.option("--arches", required=False, type=str)
2020
@click.option("--action", required=False, type=str)
21-
def build(repo, branch, registry, tag, build_args, arches, action="load"):
21+
def build(repo, commit_sha, registry, tag, build_args, arches, action="load"):
2222
"""
23-
Build bitcoind and bitcoin-cli from <repo>/<branch> as <registry>:<tag>.
23+
Build bitcoind and bitcoin-cli from <repo> at <commit_sha> as <registry>:<tag>.
2424
Optionally deploy to remote registry using --action=push, otherwise image is loaded to local registry.
2525
"""
26-
res = build_image(repo, branch, registry, tag, build_args, arches, action)
26+
res = build_image(repo, commit_sha, registry, tag, build_args, arches, action)
2727
if not res:
2828
sys.exit(1)

src/cli/image_build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def run_command(command):
1414

1515
def build_image(
1616
repo: str,
17-
branch: str,
17+
commit_sha: str,
1818
docker_registry: str,
1919
tag: str,
2020
build_args: str,
@@ -38,7 +38,7 @@ def build_image(
3838
return False
3939

4040
print(f"{repo=:}")
41-
print(f"{branch=:}")
41+
print(f"{commit_sha=:}")
4242
print(f"{docker_registry=:}")
4343
print(f"{tag=:}")
4444
print(f"{build_args=:}")
@@ -70,7 +70,7 @@ def build_image(
7070
f"docker buildx build"
7171
f" --platform {platforms}"
7272
f" --build-arg REPO={repo}"
73-
f" --build-arg BRANCH={branch}"
73+
f" --build-arg COMMIT_SHA={commit_sha}"
7474
f" --build-arg BUILD_ARGS={build_args}"
7575
f" --tag {image_full_name}"
7676
f" --file src/templates/Dockerfile ."

src/templates/Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Setup deps stage
2-
FROM alpine as deps
2+
FROM alpine AS deps
33
ARG REPO
4-
ARG BRANCH
4+
ARG COMMIT_SHA
55
ARG BUILD_ARGS
66

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

2828

2929
# Clone and patch and build stage
30-
FROM deps as build
30+
FROM deps AS build
3131
ENV BITCOIN_PREFIX=/opt/bitcoin
3232
WORKDIR /build
3333

3434
RUN set -ex \
3535
&& cd /build \
36-
&& git clone --depth 1 --branch "${BRANCH}" "https://github.com/${REPO}" \
36+
&& git clone --depth 1 "https://github.com/${REPO}" \
3737
&& cd bitcoin \
38+
&& git fetch --depth 1 origin "$COMMIT_SHA" \
39+
&& git checkout "$COMMIT_SHA" \
3840
&& git apply /tmp/isroutable.patch \
3941
&& git apply /tmp/addrman.patch \
4042
&& sed -i s:sys/fcntl.h:fcntl.h: src/compat/compat.h \

0 commit comments

Comments
 (0)