Skip to content

Commit a4b799e

Browse files
authored
Merge pull request #1855 from kube-rs/e2e-deb-distroless
Shift e2e to official rust image with distroless
2 parents a12559d + 7bea4a4 commit a4b799e

File tree

4 files changed

+80
-36
lines changed

4 files changed

+80
-36
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.git/
2+
target/
3+
e2e/Dockerfile
4+
e2e/target
5+
justfile

.github/workflows/ci.yml

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -227,40 +227,71 @@ jobs:
227227
tls: [openssl, rustls]
228228
steps:
229229
- uses: actions/checkout@v6
230-
- uses: actions/cache@v4
230+
231+
- name: Setup Docker buildx
232+
id: setup-buildx
233+
uses: docker/setup-buildx-action@v3
234+
235+
# clux: i can never get the buildkit cache dance seems to work reliably so commenting it out
236+
# would like to get this to work long term, but at least the build is pretty fast
237+
# - uses: actions/cache@v4
238+
# id: cache
239+
# with:
240+
# path: |
241+
# target
242+
# .cargo/registry
243+
# .cargo/git
244+
# key: docker-cargo4-${{matrix.tls}}-${{ hashFiles('**/Cargo.toml', 'e2e/Dockerfile') }}
245+
# restore-keys: |
246+
# docker-cargo4-${{matrix.tls}}-
247+
- name: Create folders on cache miss (blank cache always atm)
248+
run: mkdir -p ~/.cargo/{git,registry} && mkdir -p target
249+
250+
# - name: Inject cache into docker
251+
# uses: reproducible-containers/buildkit-cache-dance@v3
252+
# with:
253+
# dockerfile: e2e/Dockerfile
254+
# builder: ${{ steps.setup-buildx.outputs.name }}
255+
# cache-map: |
256+
# {
257+
# "target": {
258+
# "target": "/app/target",
259+
# "id": "target"
260+
# },
261+
# ".cargo/registry": "/root/.cargo/registry",
262+
# ".cargo/git": "/root/.cargo/git"
263+
# }
264+
# skip-extraction: ${{ steps.cache.outputs.cache-hit }}
265+
266+
- name: Build and push Docker image
267+
id: build
268+
uses: docker/build-push-action@v6
231269
with:
232-
path: |
233-
~/.cargo/registry/index
234-
~/.cargo/registry/cache
235-
~/.cargo/git
236-
target
237-
key: musl-cargo-${{ hashFiles('**/Cargo.toml') }}-${{matrix.tls}}
270+
context: .
271+
cache-from: type=gha
272+
cache-to: type=gha,mode=min
273+
platforms: linux/amd64
274+
push: false
275+
load: true
276+
file: e2e/Dockerfile
277+
tags: clux/kube-e2e:${{ github.sha }}
278+
build-args: |
279+
FEATURES=latest,${{matrix.tls}}
238280
239281
- uses: nolar/setup-k3d-k3s@v1
240282
with:
241283
version: latest
242-
# k3d-kube
243284
k3d-name: kube
244285
# Used to avoid rate limits when fetching the releases from k3s repo.
245286
# Anonymous access is limited to 60 requests / hour / worker
246287
# github-token: ${{ secrets.GITHUB_TOKEN }}
247288
k3d-args: "--no-lb --no-rollback --k3s-arg --disable=traefik,servicelb,metrics-server@server:*"
248-
- name: Compile e2e job against ${{matrix.tls}}
249-
run: |
250-
mkdir -p ~/.cargo/{git,registry}
251-
docker run --rm -t \
252-
--mount type=bind,source=${{ github.workspace }},target=/volume \
253-
--mount type=bind,source=$HOME/.cargo/registry,target=/root/.cargo/registry \
254-
--mount type=bind,source=$HOME/.cargo/git,target=/root/.cargo/git \
255-
clux/muslrust:1.86.0-stable \
256-
cargo build -p e2e --release --bin=job --features=latest,${{matrix.tls}} -v
257-
cp target/x86_64-unknown-linux-musl/release/job e2e/
258-
259-
- name: Build image
260-
run: "docker build -t clux/kube-e2e:${{ github.sha }} e2e/"
261289
- name: Import image
262290
run: "k3d image import clux/kube-e2e:${{ github.sha }} --cluster kube"
263-
- run: sed -i 's/latest/${{ github.sha }}/g' e2e/deployment.yaml
291+
- name: Template the yaml and verify we are testing what we built
292+
run: |
293+
sed -i 's/latest/${{ github.sha }}/g' e2e/deployment.yaml
294+
grep -q "${{ github.sha }}" e2e/deployment.yaml
264295
265296
- name: Create resource
266297
run: kubectl apply -f e2e/deployment.yaml -n apps

e2e/Dockerfile

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1-
FROM gcr.io/distroless/static:nonroot
2-
COPY --chown=nonroot:nonroot ./job /app/
3-
ENTRYPOINT ["/app/job"]
1+
# syntax=docker/dockerfile:1
2+
FROM rust:bookworm AS builder
3+
ARG FEATURES=""
4+
WORKDIR /app
5+
COPY . /app
6+
# NB: need rw even on fetch because we do not have a lockfile checked in
7+
RUN --mount=type=bind,rw,target=. \
8+
--mount=type=cache,target=/root/.cargo \
9+
cargo fetch
10+
RUN --mount=type=bind,rw,target=. \
11+
--mount=type=cache,target=/root/.cargo \
12+
--mount=type=cache,target=target,id=target \
13+
cargo install --path=e2e --features=${FEATURES} --bin=job
14+
15+
FROM gcr.io/distroless/cc-debian12
16+
COPY --from=builder /usr/local/cargo/bin/job /app/
17+
CMD ["/app/job"]

justfile

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ e2e-mink8s:
7373
#cargo run -p e2e --bin boot --features=rustls,mk8sv
7474

7575
e2e-incluster features:
76-
just e2e-job-musl {{features}}
77-
docker build -t clux/kube-e2e:{{VERSION}} e2e/
78-
k3d image import clux/kube-e2e:{{VERSION}} --cluster main
76+
docker build --build-arg FEATURES="{{features}}" \
77+
-t clux/kube-e2e:{{VERSION}} . -f e2e/Dockerfile
78+
k3d image import clux/kube-e2e:{{VERSION}} -c=$(k3d cluster list -ojson |jq '.[0].name' -r)
7979
sed -i 's/latest/{{VERSION}}/g' e2e/deployment.yaml
8080
kubectl apply -f e2e/deployment.yaml
8181
sed -i 's/{{VERSION}}/latest/g' e2e/deployment.yaml
@@ -84,14 +84,8 @@ e2e-incluster features:
8484
kubectl wait --for=condition=complete job/e2e -n apps --timeout=50s || kubectl logs -f job/e2e -n apps
8585
kubectl get all -n apps
8686
kubectl wait --for=condition=complete job/e2e -n apps --timeout=10s || kubectl get pods -n apps | grep e2e | grep Completed
87-
e2e-job-musl features:
88-
#!/usr/bin/env bash
89-
docker run \
90-
-v cargo-cache:/root/.cargo/registry \
91-
-v "$PWD:/volume" -w /volume \
92-
--rm -it clux/muslrust:1.86.0-stable cargo build --release --features={{features}} -p e2e
93-
cp target/x86_64-unknown-linux-musl/release/job e2e/job
94-
chmod +x e2e/job
87+
@echo "need to not commit a sha in the deployment.yaml"
88+
rg "latest" e2e/deployment.yaml -q
9589

9690
k3d:
9791
k3d cluster create main --servers 1 --registry-create main --image rancher/k3s:v1.27.3-k3s1 \

0 commit comments

Comments
 (0)