Skip to content

Commit

Permalink
ci: Refactor Kaniko build step and Dockerfile for improved environmen…
Browse files Browse the repository at this point in the history
…t variable usage and caching

Signed-off-by: Eden Reich <[email protected]>
  • Loading branch information
edenreich committed Feb 19, 2025
1 parent 9d50606 commit c3c5296
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,22 @@ jobs:
EOF
- name: Build and push
env:
REPOSITORY_NAME: coder
REPOSITORY_OWNER: ${{ github.repository_owner }}
CONTAINER_REGISTRY: ghcr.io
VERSION: ${{ needs.github_release.outputs.new_release_version }}
run: |
/kaniko/executor \
--context="${{ github.repositoryUrl }}#${{ github.ref }}" \
--dockerfile=Dockerfile \
--target=minimal \
--destination=ghcr.io/${{ github.repository_owner }}/coder:latest \
--destination=ghcr.io/${{ github.repository_owner }}/coder:minimal \
--destination=ghcr.io/${{ github.repository_owner }}/coder:minimal-${{ needs.github_release.outputs.new_release_version }} \
--destination=${{ env.CONTAINER_REGISTRY }}/${{ env.REPOSITORY_OWNER }}/{{ env.REPOSITORY_NAME }}:latest \
--destination=${{ env.CONTAINER_REGISTRY }}/${{ env.REPOSITORY_OWNER }}/{{ env.REPOSITORY_NAME }}:minimal \
--destination=${{ env.CONTAINER_REGISTRY }}/${{ env.REPOSITORY_OWNER }}/{{ env.REPOSITORY_NAME }}:minimal-${{ env.VERSION }} \
--build-arg=TARGET_ARCH=${{ matrix.target }} \
--cache=true \
--cache-repo=ghcr.io/${{ github.repository_owner }}/coder/cache
--cache-repo=${{ env.CONTAINER_REGISTRY }}/${{ env.REPOSITORY_OWNER }}/{{ env.REPOSITORY_NAME }}/cache
# build_containers_with_tools:
# name: B&P Language specific Containers
Expand Down
14 changes: 12 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,22 @@ RUN apk add --no-cache \
/tmp/* \
/var/tmp/*

# Setup rust target
WORKDIR /app
RUN rustup target add ${TARGET_ARCH}

# Cache dependencies
COPY Cargo.toml Cargo.lock ./
COPY . .
COPY src ./src
RUN cargo build --release --no-default-features --target ${TARGET_ARCH} && \
rm -rf target/${TARGET_ARCH}/release/.fingerprint/coder-* \
target/${TARGET_ARCH}/release/deps/coder-* \
target/${TARGET_ARCH}/release/coder*

RUN rustup target add ${TARGET_ARCH} && \
# Build the actual binary
COPY . .
RUN --mount=type=cache,target=/root/.cargo/registry \
--mount=type=cache,target=/root/.cargo/git \
cargo build --release --no-default-features --target ${TARGET_ARCH}

FROM alpine:3.21.3 AS common
Expand Down

0 comments on commit c3c5296

Please sign in to comment.