Skip to content

Commit a69af9f

Browse files
authored
Merge pull request #31 from Jakob-Naucke/operator-build-container
Build operator on container with debug support
2 parents 58ed676 + d6f8e36 commit a69af9f

File tree

6 files changed

+53
-15
lines changed

6 files changed

+53
-15
lines changed

Containerfile

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,28 @@
33
#
44
# SPDX-License-Identifier: CC0-1.0
55

6-
FROM quay.io/fedora/fedora:42
6+
ARG build_type
7+
# Dependency build stage
8+
FROM ghcr.io/confidential-clusters/buildroot AS builder
9+
ARG build_type
10+
WORKDIR /cocl-operator
11+
12+
COPY Cargo.toml Cargo.lock .
13+
COPY crds crds
14+
COPY rv-store rv-store
15+
COPY operator/Cargo.toml operator/
16+
COPY operator/src/lib.rs operator/src/
717

8-
COPY target/debug/operator /usr/bin/operator
18+
# Set only required crates as members to minimize rebuilds upon changes.
19+
# In debug builds, build dependencies to avoid full rebuild.
20+
RUN sed -i 's/members = .*/members = ["crds", "operator", "rv-store"]/' Cargo.toml && \
21+
if [ "$build_type" = debug ]; then cargo build -p operator --lib; fi
922

10-
ENTRYPOINT ["/usr/bin/operator"]
23+
# Target build stage
24+
COPY operator/src operator/src
25+
RUN cargo build -p operator $(if [ "$build_type" = release ]; then echo --release; fi)
26+
27+
# Distribution stage
28+
FROM quay.io/fedora/fedora:42
29+
ARG build_type
30+
COPY --from=builder "/cocl-operator/target/$build_type/operator" /usr/bin

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ REGISTRY ?= quay.io
1111
OPERATOR_IMAGE=$(REGISTRY)/confidential-clusters/cocl-operator:latest
1212
COMPUTE_PCRS_IMAGE=$(REGISTRY)/confidential-clusters/compute-pcrs:latest
1313

14+
BUILD_TYPE ?= release
15+
1416
all: build tools
1517

1618
build:
19+
cargo build -p compute-pcrs
1720
cargo build -p operator
1821

1922
tools:
@@ -34,11 +37,9 @@ cluster-up:
3437
cluster-down:
3538
scripts/delete-cluster-kind.sh
3639

37-
image: build
38-
podman build -t $(OPERATOR_IMAGE) -f Containerfile .
39-
podman build -t $(COMPUTE_PCRS_IMAGE) \
40-
-f compute-pcrs/Containerfile \
41-
--env K8S_OPENAPI_ENABLED_VERSION=$(K8S_VERSION) .
40+
image:
41+
podman build --build-arg build_type=$(BUILD_TYPE) -t $(OPERATOR_IMAGE) -f Containerfile .
42+
podman build --build-arg build_type=$(BUILD_TYPE) -t $(COMPUTE_PCRS_IMAGE) -f compute-pcrs/Containerfile .
4243

4344
# TODO: remove the tls-verify, right now we are pushing only on the local registry
4445
push: image

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ the operator.
3232

3333
```bash
3434
make cluster-up
35-
make REGISTRY=localhost:5000 image
36-
make REGISTRY=localhost:5000 push
35+
make REGISTRY=localhost:5000 image push # optional: use BUILD_TYPE=debug
3736
make REGISTRY=localhost:5000 manifests
3837
make install-trustee
3938
make install

compute-pcrs/Containerfile

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,26 @@
33
#
44
# SPDX-License-Identifier: CC0-1.0
55

6+
ARG build_type
67
FROM ghcr.io/confidential-clusters/buildroot AS builder
8+
ARG build_type
79
WORKDIR /compute-pcrs
10+
811
COPY Cargo.toml Cargo.lock .
9-
COPY compute-pcrs compute-pcrs
1012
COPY rv-store rv-store
11-
# Hack: Set required crates as only members to avoid needing to copy other crates.
12-
# In that case, a rebuild would be triggered upon any change in those crates.
13+
COPY compute-pcrs/Cargo.toml compute-pcrs/
14+
COPY compute-pcrs/src/lib.rs compute-pcrs/src/
15+
16+
# Set only required crates as members to minimize rebuilds upon changes.
17+
# In debug builds, build dependencies to avoid full rebuild.
1318
RUN sed -i 's/members =.*/members = ["compute-pcrs", "rv-store"]/' Cargo.toml && \
1419
git clone --depth 1 https://github.com/confidential-clusters/reference-values && \
15-
cargo build --release -p compute-pcrs
20+
if [ "$build_type" = debug ]; then cargo build -p compute-pcrs --lib; fi
21+
22+
COPY compute-pcrs/src compute-pcrs/src
23+
RUN cargo build -p compute-pcrs $(if [ "$build_type" = release ]; then echo --release; fi)
1624

1725
FROM quay.io/fedora/fedora:42
18-
COPY --from=builder /compute-pcrs/target/release/compute-pcrs /usr/local/bin
26+
ARG build_type
27+
COPY --from=builder "/compute-pcrs/target/$build_type/compute-pcrs" /usr/bin
1928
COPY --from=builder /compute-pcrs/reference-values /reference-values

compute-pcrs/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// SPDX-FileCopyrightText: Jakob Naucke <jnaucke@redhat.com>
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
// This pseudo-library exists to build dependencies in a lower
6+
// container layer, which speeds up development.

operator/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// SPDX-FileCopyrightText: Jakob Naucke <jnaucke@redhat.com>
2+
//
3+
// SPDX-License-Identifier: MIT

0 commit comments

Comments
 (0)