Skip to content

Commit

Permalink
chore: Added a workflow/docker file using chef instead of cross
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswk committed Sep 18, 2024
1 parent 00aabbe commit 077ff67
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*
!target/aarch64-unknown-linux-gnu/release/unleash-edge
!target/x86_64-unknown-linux-gnu/release/unleash-edge
!target/x86_64-unknown-linux-gnu/release/unleash-edge
!server
!Cargo.toml
!Cargo.lock
74 changes: 74 additions & 0 deletions .github/workflows/build-docker-with-chef.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Build and Push Docker Image

on:
push:
branches:
- main # You can trigger this on other events or branches if needed
workflow_dispatch:

permissions:
id-token: write
contents: read
packages: write
jobs:
build:
runs-on: ubuntu-latest

steps:
# Step 1: Checkout the repository
- name: Checkout repository
uses: actions/checkout@v4

# Step 2: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up Docker cache
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
# Step 3: Log in to DockerHub (or your Docker registry)
- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::726824350591:role/unleash-github-ecr-public-publish-role
role-session-name: edge-actions-push-to-ecr-public
aws-region: us-east-1
- name: Login to AWS ECR
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public # Step 4: Cache Docker layers (optional, but speeds up builds)
- name: Login to Github Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta configuration (set image and tag)
uses: docker/metadata-action@v5
id: meta
with:
images: |
unleashorg/unleash-edge
${{ steps.login-ecr-public.outputs.registry }}/unleashorg/unleash-edge
tags: |
type=edge
# Step 5: Build and push Docker image for multiple platforms (Don't actually push yet)
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile.chef
platforms: linux/amd64,linux/arm64 # Add any platforms you need
push: false
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
41 changes: 41 additions & 0 deletions Dockerfile.chef
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM --platform=$BUILDPLATFORM rust:latest AS chef
WORKDIR /app

# Install cargo-chef CLI
RUN cargo install cargo-chef

# Step 2: Prepare dependency caching
FROM chef AS planner
COPY . .
# Create a recipe file for the dependencies
RUN cargo chef prepare --recipe-path recipe.json

# Step 3: Cache dependencies
FROM chef AS cacher
COPY --from=planner /app/recipe.json recipe.json

# Install system deps
RUN apt-get update && apt-get install -y libssl-dev pkg-config

# Build the deps, cache the output
RUN cargo chef cook --release --recipe-path recipe.json

# Step 4: Build the application
FROM chef AS builder

# Copy the cached dependencies
COPY --from=cacher /app/target target
COPY --from=cacher /usr/local/cargo /usr/local/cargo
# Copy the project source code
COPY . .

# Build the application
RUN cargo build --release

# Step 5: Final image from distroless
FROM gcr.io/distroless/cc-debian12 AS final
WORKDIR /app

COPY --from=builder /app/target/release/unleash-edge /app/unleash-edge

ENTRYPOINT ["/app/unleash-edge"]

0 comments on commit 077ff67

Please sign in to comment.