Skip to content

Commit 7b20d2f

Browse files
committed
Ported the build script over to the justfile
1 parent 346eea4 commit 7b20d2f

5 files changed

Lines changed: 185 additions & 166 deletions

File tree

build-linux.sh

Lines changed: 0 additions & 144 deletions
This file was deleted.

docs/docs/get_started/building.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,27 @@ Commit-Boost's components are all written in [Rust](https://www.rust-lang.org/).
55

66
## Building via the Docker Builder
77

8-
For convenience, Commit-Boost has Dockerized the build environment for Linux `x64` and `arm64` platforms. All of the prerequisites, cross-compilation tooling, and configuration are handled by the builder image. If you would like to build the CLI, PBS module, or Signer binaries and Docker images from source, you are welcome to use the Docker builder process.
8+
For convenience, Commit-Boost has Dockerized the build environment for Linux `x64` and `arm64` platforms. It utilizes Docker's powerful [buildx](https://docs.docker.com/reference/cli/docker/buildx/) system. All of the prerequisites, cross-compilation tooling, and configuration are handled by the builder image. If you would like to build the CLI, PBS module, or Signer binaries and Docker images from source, you are welcome to use the Docker builder process.
99

1010
To use the builder, you will need to have [Docker Engine](https://docs.docker.com/engine/install/) installed on your system. Please follow the instructions to install it first.
1111

1212
:::note
13-
The build script assumes that you've added your user account to the `docker` group with the Linux [post-install steps](https://docs.docker.com/engine/install/linux-postinstall/). If you haven't, then you'll need to run the build script below as `root` or modify it so each call to `docker` within it is run as the root user (e.g., with `sudo`).
13+
The build system assumes that you've added your user account to the `docker` group with the Linux [post-install steps](https://docs.docker.com/engine/install/linux-postinstall/). If you haven't, then you'll need to run the build script below as `root` or modify it so each call to `docker` within it is run as the root user (e.g., with `sudo`).
1414
:::
1515

16-
We provide a build script called `build-linux.sh` to automate the process:
16+
The Docker builder is built into the project's `justfile` which is used to invoke many facets of Commit Boost development. To use it, you'll need to install [Just](https://github.com/casey/just) on your system.
1717

18-
```
19-
$ ./build-linux.sh
20-
Usage: build.sh [options] -v <version number>
21-
This script assumes it is in the commit-boost-client repository directory.
22-
Options:
23-
-a Build all of the artifacts (CLI, PBS, and Signer, along with Docker images)
24-
-c Build the Commit-Boost CLI binaries
25-
-p Build the PBS module binary and its Docker container
26-
-s Build the Signer module binary and its Docker container
27-
-o When passed with a build, upload the resulting image tags to a local Docker registry specified in $LOCAL_DOCKER_REGISTRY
28-
```
18+
Use `just --list` to show all of the actions - there are many. The `justfile` provides granular actions, called "recipes", for building just the binaries of a specific crate (such as the CLI, `pbs`, or `signer`), as well as actions to build the Docker images for the PBS and Signer modules.
19+
20+
Below is a brief summary of the relevant ones for building the Commit-Boost artifacts:
21+
22+
- `build-all <version>` will build the `commit-boost-cli`, `commit-boost-pbs`, and `commit-boost-signer` binaries for your local system architecture. It will also create Docker images called `commit-boost/pbs:<version>` and `commit-boost/signer:<version>` and load them into your local Docker registry for use.
23+
- `build-cli-bin <version>`, `build-pbs-bin <version>`, and `build-signer-bin <version>` can be used to create the `commit-boost-cli`, `commit-boost-pbs`, and `commit-boost-signer` binaries, respectively.
24+
- `build-pbs-img <version>` and `build-signer-img <version>` can be used to create the Docker images for the PBS and Signer modules, respectively.
2925

30-
The script utilizes Docker's [buildx](https://docs.docker.com/reference/cli/docker/buildx/) system to both create a multiarch-capable builder and cross-compile for both Linux architectures. You are free to modify it to produce only the artifacts relevant to you if so desired.
26+
The `version` provided will be used to house the output binaries in `./build/<version>`, and act as the version tag for the Docker images when they're added to your local system or uploaded to your local Docker repository.
3127

32-
The `version` provided will be used to house the output binaries in `./build/$VERSION`, and act as the version tag for the Docker images when they're added to your local system or uploaded to your local Docker repository.
28+
If you're interested in building the binaries and/or Docker images for multiple architectures (currently Linux `amd64` and `arm64`), use the variants of those recipes that have the `-multiarch` suffix. Note that building a multiarch Docker image manifest will require the use of a [custom Docker registry](https://www.digitalocean.com/community/tutorials/how-to-set-up-a-private-docker-registry-on-ubuntu-20-04), as the local registry built into Docker does not have multiarch manifest support.
3329

3430

3531
## Building Manually

justfile

Lines changed: 171 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,183 @@ fmt-check:
1212
clippy:
1313
cargo +{{toolchain}} clippy --all-features --no-deps -- -D warnings
1414

15-
docker-build-pbs:
16-
docker build -t commitboost_pbs_default . -f ./provisioning/pbs.Dockerfile
15+
# ===================================
16+
# === Build Commands for Services ===
17+
# ===================================
1718

18-
docker-build-signer:
19-
docker build -t commitboost_signer . -f ./provisioning/signer.Dockerfile
19+
[doc("""
20+
Builds the commit-boost-cli binary to './build/<version>'.
21+
""")]
22+
build-cli version: \
23+
(_docker-build-binary version "cli")
24+
25+
[doc("""
26+
Builds amd64 and arm64 binaries for the commit-boost-cli crate to './build/<version>/<platform>', where '<platform>' is
27+
the OS / arch platform of the binary (linux_amd64 and linux_arm64).
28+
""")]
29+
build-cli-multiarch version: \
30+
(_docker-build-binary-multiarch version "cli")
31+
32+
[doc("""
33+
Builds the commit-boost-pbs binary to './build/<version>'.
34+
""")]
35+
build-pbs-bin version: \
36+
(_docker-build-binary version "pbs")
37+
38+
[doc("""
39+
Creates a Docker image named 'commit-boost/pbs:<version>' and loads it to the local Docker repository.
40+
Requires the binary to be built first, but this command won't build it automatically if you just need to build the
41+
Docker image without recompiling the binary.
42+
""")]
43+
build-pbs-img version: \
44+
(_docker-build-image version "pbs")
45+
46+
[doc("""
47+
Builds the commit-boost-pbs binary to './build/<version>' and creates a Docker image named 'commit-boost/pbs:<version>'.
48+
""")]
49+
build-pbs version: \
50+
(build-pbs-bin version) \
51+
(build-pbs-img version)
52+
53+
[doc("""
54+
Builds amd64 and arm64 binaries for the commit-boost-pbs crate to './build/<version>/<platform>', where '<platform>' is the
55+
OS / arch platform of the binary (linux_amd64 and linux_arm64).
56+
Used when creating the pbs Docker image.
57+
""")]
58+
build-pbs-bin-multiarch version: \
59+
(_docker-build-binary-multiarch version "pbs")
60+
61+
[doc("""
62+
Creates a multiarch Docker image manifest named 'commit-boost/pbs:<version>' and pushes it to a custom Docker registry
63+
(such as '192.168.1.10:5000').
64+
Used for testing multiarch images locally instead of using a public registry like GHCR or Docker Hub.
65+
""")]
66+
build-pbs-img-multiarch version local-docker-registry: \
67+
(_docker-build-image-multiarch version "pbs" local-docker-registry)
68+
69+
[doc("""
70+
Builds amd64 and arm64 binaries for the commit-boost-pbs crate to './build/<version>/<platform>', where '<platform>' is the
71+
OS / arch platform of the binary (linux_amd64 and linux_arm64).
72+
Creates a multiarch Docker image manifest named 'commit-boost/pbs:<version>' and pushes it to a custom Docker registry
73+
(such as '192.168.1.10:5000').
74+
Used for testing multiarch images locally instead of using a public registry like GHCR or Docker Hub.
75+
""")]
76+
build-pbs-multiarch version local-docker-registry: \
77+
(build-pbs-bin-multiarch version) \
78+
(build-pbs-img-multiarch version local-docker-registry)
79+
80+
[doc("""
81+
Builds the commit-boost-signer binary to './build/<version>'.
82+
""")]
83+
build-signer-bin version: \
84+
(_docker-build-binary version "signer")
85+
86+
[doc("""
87+
Creates a Docker image named 'commit-boost/signer:<version>' and loads it to the local Docker repository.
88+
Requires the binary to be built first, but this command won't build it automatically if you just need to build the
89+
Docker image without recompiling the binary.
90+
""")]
91+
build-signer-img version: \
92+
(_docker-build-image version "signer")
93+
94+
[doc("""
95+
Builds the commit-boost-signer binary to './build/<version>' and creates a Docker image named 'commit-boost/signer:<version>'.
96+
""")]
97+
build-signer version: \
98+
(build-signer-bin version) \
99+
(build-signer-img version)
100+
101+
[doc("""
102+
Builds amd64 and arm64 binaries for the commit-boost-signer crate to './build/<version>/<platform>', where '<platform>' is
103+
the OS / arch platform of the binary (linux_amd64 and linux_arm64).
104+
Used when creating the signer Docker image.
105+
""")]
106+
build-signer-bin-multiarch version: \
107+
(_docker-build-binary-multiarch version "signer")
108+
109+
[doc("""
110+
Creates a multiarch Docker image manifest named 'commit-boost/signer:<version>' and pushes it to a custom Docker registry
111+
(such as '192.168.1.10:5000').
112+
Used for testing multiarch images locally instead of using a public registry like GHCR or Docker Hub.
113+
""")]
114+
build-signer-img-multiarch version local-docker-registry: \
115+
(_docker-build-image-multiarch version "signer" local-docker-registry)
116+
117+
[doc("""
118+
Builds amd64 and arm64 binaries for the commit-boost-signer crate to './build/<version>/<platform>', where '<platform>' is
119+
the OS / arch platform of the binary (linux_amd64 and linux_arm64).
120+
Creates a multiarch Docker image manifest named 'commit-boost/signer:<version>' and pushes it to a custom Docker registry
121+
(such as '192.168.1.10:5000').
122+
Used for testing multiarch images locally instead of using a public registry like GHCR or Docker Hub.
123+
""")]
124+
build-signer-multiarch version local-docker-registry: \
125+
(build-signer-bin-multiarch version) \
126+
(build-signer-img-multiarch version local-docker-registry)
127+
128+
[doc("""
129+
Builds the CLI, PBS, and Signer binaries and Docker images for the specified version.
130+
The binaries will be placed in './build/<version>'.
131+
The Docker images will be named 'commit-boost/cli:<version>', 'commit-boost/pbs:<version>', and
132+
'commit-boost/signer:<version>'.
133+
""")]
134+
build-all version: \
135+
(build-cli version) \
136+
(build-pbs version) \
137+
(build-signer version)
138+
139+
[doc("""
140+
Builds amd64 and arm64 flavors of the CLI, PBS, and Signer binaries and Docker images for the specified version.
141+
The binaries will be placed in './build/<version>/<platform>', where '<platform>' is the
142+
OS / arch platform of the binary (linux_amd64 and linux_arm64).
143+
Also creates multiarch Docker image manifests for each crate and pushes them to a custom Docker registry
144+
(such as '192.168.1.10:5000').
145+
Used for testing multiarch images locally instead of using a public registry like GHCR or Docker Hub.
146+
""")]
147+
build-all-multiarch version local-docker-registry: \
148+
(build-cli-multiarch version) \
149+
(build-pbs-multiarch version local-docker-registry) \
150+
(build-signer-multiarch version local-docker-registry)
151+
152+
# ===============================
153+
# === Builder Implementations ===
154+
# ===============================
155+
156+
# Creates a Docker buildx builder if it doesn't already exist
157+
_create-docker-builder:
158+
docker buildx create --name multiarch-builder --driver docker-container --use > /dev/null 2>&1 || true
159+
160+
# Builds a binary for a specific crate and version
161+
_docker-build-binary version crate: _create-docker-builder
162+
export PLATFORM=$(docker buildx inspect --bootstrap | awk -F': ' '/Platforms/ {print $2}' | cut -d',' -f1 | xargs | tr '/' '_'); \
163+
docker buildx build --rm --platform=local -f provisioning/build.Dockerfile --output "build/{{version}}/$PLATFORM" --target output --build-arg TARGET_CRATE=commit-boost-{{crate}} .
164+
165+
# Builds a Docker image for a specific crate and version
166+
_docker-build-image version crate: _create-docker-builder
167+
docker buildx build --rm --load --build-arg BINARIES_PATH=build/{{version}} -t commit-boost/{{crate}}:{{version}} -f provisioning/{{crate}}.Dockerfile .
168+
169+
# Builds multiple binaries (for Linux amd64 and arm64 architectures) for a specific crate and version
170+
_docker-build-binary-multiarch version crate: _create-docker-builder
171+
docker buildx build --rm --platform=linux/amd64,linux/arm64 -f provisioning/build.Dockerfile --output build/{{version}} --target output --build-arg TARGET_CRATE=commit-boost-{{crate}} .
172+
173+
# Builds a multi-architecture (Linux amd64 and arm64) Docker manifest for a specific crate and version.
174+
# Uploads to the custom Docker registry (such as '192.168.1.10:5000') instead of a public registry like GHCR or Docker Hub.
175+
_docker-build-image-multiarch version crate local-docker-registry: _create-docker-builder
176+
docker buildx build --rm --platform=linux/amd64,linux/arm64 --build-arg BINARIES_PATH=build/{{version}} -t {{local-docker-registry}}/commit-boost/{{crate}}:{{version}} -f provisioning/{{crate}}.Dockerfile --push .
177+
178+
# =================
179+
# === Utilities ===
180+
# =================
20181

21182
docker-build-test-modules:
22183
docker build -t test_da_commit . -f examples/da_commit/Dockerfile
23184
docker build -t test_builder_log . -f examples/builder_log/Dockerfile
24185
docker build -t test_status_api . -f examples/status_api/Dockerfile
25186

187+
# Cleans the build directory, removing all built binaries.
188+
# Docker images are not removed by this command.
189+
clean:
190+
rm -rf build
191+
192+
# Runs the suite of tests for all commit-boost crates.
26193
test:
27194
cargo test --all-features

provisioning/pbs.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM debian:bookworm-slim
22
ARG BINARIES_PATH TARGETOS TARGETARCH
3-
COPY ${BINARIES_PATH}/commit-boost-pbs-${TARGETOS}-${TARGETARCH} /usr/local/bin/commit-boost-pbs
3+
COPY ${BINARIES_PATH}/${TARGETOS}_${TARGETARCH}/commit-boost-pbs /usr/local/bin/commit-boost-pbs
44
RUN apt-get update && apt-get install -y \
55
openssl \
66
ca-certificates \

provisioning/signer.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM debian:bookworm-slim
22
ARG BINARIES_PATH TARGETOS TARGETARCH
3-
COPY ${BINARIES_PATH}/commit-boost-signer-${TARGETOS}-${TARGETARCH} /usr/local/bin/commit-boost-signer
3+
COPY ${BINARIES_PATH}/${TARGETOS}_${TARGETARCH}/commit-boost-signer /usr/local/bin/commit-boost-signer
44
RUN apt-get update && apt-get install -y \
55
openssl \
66
ca-certificates \

0 commit comments

Comments
 (0)