Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
Update Dockerfile to use cargo-zigbuild for easier cross compilation.…
Browse files Browse the repository at this point in the history
… Update CI workflows
  • Loading branch information
anish-dfg committed Sep 25, 2024
1 parent d33a28d commit 8df168c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 49 deletions.
74 changes: 37 additions & 37 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
# name: CI
#
# on:
# push:
# branches: ["main"]
# pull_request:
# branches: ["main"]
#
# env:
# PROJECT_ID: develop-for-good
# REGION: us-central1
# GAR_LOCATION: us-central1-docker.pkg.dev/developforgood/dfg/
#
# jobs:
# build-push-artifact:
# runs-on: ubuntu-latest
# steps:
# - name: "Checkout"
# uses: "actions/checkout@v3"
# - id: "auth"
# uses: "google-github-actions/auth@v1"
# with:
# credentials_json: "${{ secrets.SERVICE_ACCOUNT_KEY }}"
#
# - name: "Set up Cloud SDK"
# uses: "google-github-actions/setup-gcloud@v1"
#
# - name: "Use gcloud CLI"
# run: "gcloud info"
# - name: "Docker auth"
# run: |-
# gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet
# - name: Build image
# run: docker build . --file Dockerfile --tag alpha
# working-directory: .
# - name: Push image
# run: docker push ${{ env.GAR_LOCATION }}
name: CI

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

env:
PROJECT_ID: develop-for-good
REGION: us-central1
GAR_LOCATION: us-central1-docker.pkg.dev/develop-for-good/dfg/

jobs:
build-push-artifact:
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
- id: "auth"
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.SERVICE_ACCOUNT_KEY }}"

- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v1"

- name: "Use gcloud CLI"
run: "gcloud info"
- name: "Docker auth"
run: |-
gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet
- name: Build image
run: docker build . --file Dockerfile --tag scipio:alpha
working-directory: .
- name: Push image
run: docker push ${{ env.GAR_LOCATION }}
41 changes: 29 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
FROM clux/muslrust:stable AS chef
RUN cargo install cargo-chef
WORKDIR /app
FROM messense/cargo-zigbuild:sha-4e5d0f9 as builder

RUN rustup target add aarch64-unknown-linux-musl && rustup target add x86_64-unknown-linux-musl
WORKDIR /app

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --target aarch64-unknown-linux-musl --recipe-path recipe.json
COPY . .
RUN cargo build --release --target aarch64-unknown-linux-musl --bin scipio
RUN cargo zigbuild --release --target x86_64-unknown-linux-musl
# RUN cargo zigbuild --release --target aarch64-unknown-linux-musl

FROM scratch AS runtime
COPY --from=builder /app/target/aarch64-unknown-linux-musl/release/scipio /usr/local/bin/
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/scipio /usr/local/bin/
# COPY --from=builder /app/target/aarch64-unknown-linux-musl/release/scipio /usr/local/bin/

CMD ["/usr/local/bin/scipio"]

# NOTE: The following is a multi-stage build that works for aarch64-unknown-linux-musl but doesn't cross
# compile correctly. If you can fix this, please submit a PR.

# FROM clux/muslrust:stable AS chef
# RUN cargo install cargo-chef
# WORKDIR /app
#
# RUN rustup target add aarch64-unknown-linux-musl && rustup target add x86_64-unknown-linux-musl
#
# FROM chef AS planner
# COPY . .
# RUN cargo chef prepare --recipe-path recipe.json
#
# FROM chef AS builder
# COPY --from=planner /app/recipe.json recipe.json
# RUN cargo chef cook --release --target aarch64-unknown-linux-musl --recipe-path recipe.json
# COPY . .
# RUN cargo build --release --target aarch64-unknown-linux-musl --bin scipio
#
# FROM scratch AS runtime
# COPY --from=builder /app/target/aarch64-unknown-linux-musl/release/scipio /usr/local/bin/
# CMD ["/usr/local/bin/scipio"]

0 comments on commit 8df168c

Please sign in to comment.