diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38fdf5e..a33d85e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,6 @@ jobs: #- linux/arm64 steps: - uses: actions/checkout@v5 - - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -30,24 +29,21 @@ jobs: - name: Setup docker buildx uses: docker/setup-buildx-action@v3 with: - config: .github/buildkitd.toml - - - name: Configure tags based on git tags + latest - uses: docker/metadata-action@v5 - id: meta - with: - images: ghcr.io/${{ github.repository }} - tags: | - type=pep440,pattern={{version}} - type=raw,value=latest,enable={{is_default_branch}} - type=ref,event=pr + buildkitd-config: .github/buildkitd.toml - name: Rust Build Cache for Docker uses: actions/cache@v4 id: cache with: - path: rust-build-cache - key: ${{ runner.os }}-build-cache-${{ hashFiles('**/Cargo.toml') }} + path: | + target + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-build-cache2-${{ hashFiles('**/Cargo.toml') }} + restore-keys: | + ${{ runner.os}}-build-cache2 + - name: Create folders on cache miss + run: mkdir -p ~/.cargo/{git,registry} && mkdir -p target - name: Inject cache into docker uses: reproducible-containers/buildkit-cache-dance@v3 @@ -58,7 +54,17 @@ jobs: "~/.cargo/registry": "/root/.cargo/registry", "~/.cargo/git": "/root/.cargo/git" } - skip-extraction: ${{ steps.cache.outputs.cache-hit }} + # skip-extraction: ${{ steps.cache.outputs.cache-hit }} + + - name: Configure tags based on git tags + latest + uses: docker/metadata-action@v5 + id: meta + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=pep440,pattern={{version}} + type=raw,value=latest,enable={{is_default_branch}} + type=ref,event=pr - name: Docker login uses: docker/login-action@v3 @@ -78,10 +84,10 @@ jobs: # when using buildkit-cache-dance cache-from: type=gha cache-to: type=gha,mode=max + load: true push: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags') }} tags: ${{ steps.meta.outputs.tags }} platforms: ${{ matrix.platform }} - sbom: true lint: runs-on: ubuntu-latest diff --git a/Dockerfile b/Dockerfile index 7619952..21c31a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,10 +3,9 @@ COPY Cargo.* . COPY version.rs version.rs RUN --mount=type=cache,target=/volume/target \ --mount=type=cache,target=/root/.cargo/registry \ - cargo build --release --bin version && \ - mv /volume/target/x86_64-unknown-linux-musl/release/version . + cargo install --bin version --path=. FROM cgr.dev/chainguard/static -COPY --from=builder --chown=nonroot:nonroot /volume/version /app/ +COPY --from=builder --chown=nonroot:nonroot /opt/cargo/bin/version /app/ EXPOSE 8080 ENTRYPOINT ["/app/version"] diff --git a/README.md b/README.md index ad208a9..1348b73 100644 --- a/README.md +++ b/README.md @@ -34,4 +34,4 @@ $ curl 0.0.0.0:8000/versions/default/foo-controller - In-cluster: edit and `tilt up` [*](https://tilt.dev/) - Docker build: `just build` -NB: images + docker dev is `linux/amd64` only atm. +NB: pushed images are `linux/amd64` only atm, but local docker build works on `linux/arm64` also. diff --git a/justfile b/justfile index d232b86..67a3f7d 100644 --- a/justfile +++ b/justfile @@ -17,6 +17,6 @@ release: [private] import: - k3d image import ghcr.io/kube-rs/version-rs:local --cluster main + k3d image import ghcr.io/kube-rs/version-rs:local -c=$(k3d cluster list -ojson |jq '.[0].name' -r) sd "image: .*" "image: ghcr.io/kube-rs/version-rs:local" deployment.yaml kubectl apply -f deployment.yaml diff --git a/version.rs b/version.rs index b7e1355..18622c7 100644 --- a/version.rs +++ b/version.rs @@ -69,7 +69,7 @@ async fn main() -> anyhow::Result<()> { let app = Router::new() .route("/versions", routing::get(get_versions)) - .route("/versions/:namespace/:name", routing::get(get_version)) + .route("/versions/{namespace}/{name}", routing::get(get_version)) .with_state(reader) // routes can read from the reflector store .layer(tower_http::trace::TraceLayer::new_for_http()) // NB: routes added after TraceLayer are not traced