Skip to content

Commit

Permalink
Use CI build artifacts for docker container to improve build performa…
Browse files Browse the repository at this point in the history
…nce (#1179)
  • Loading branch information
tarrencev committed Nov 10, 2023
1 parent be16762 commit 104afa0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 35 deletions.
42 changes: 37 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,39 @@ jobs:
const prunePrereleases = require('./.github/scripts/prune-prereleases.js')
await prunePrereleases({github, context})
docker-build-and-push:
name: Build and push Docker image
docker-build-and-push-linux-arm64:
name: Build and push linux-arm64 docker image
runs-on: ubuntu-latest-4-cores
needs: prepare
needs: [prepare, release]

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push docker image
uses: docker/build-push-action@v4
with:
push: true
tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:${{ needs.prepare.outputs.tag_name }}
platforms: linux/arm64
target: arm64
cache-from: type=gha
cache-to: type=gha,mode=max

docker-build-and-push-linux-amd64:
name: Build and push linux-amd64 docker image
runs-on: ubuntu-latest-4-cores
needs: [prepare, release]

steps:
- name: Checkout repository
Expand All @@ -236,9 +265,12 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
- name: Build and push docker image
uses: docker/build-push-action@v4
with:
push: true
tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:${{ needs.prepare.outputs.tag_name }}
platforms: linux/amd64,linux/arm64
platforms: linux/amd64
target: amd64
cache-from: type=gha
cache-to: type=gha,mode=max
39 changes: 9 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,16 @@
FROM rust:slim-buster as builder
RUN apt-get -y update; \
apt-get install -y --no-install-recommends \
curl libssl-dev make clang-11 g++ llvm protobuf-compiler \
pkg-config libz-dev zstd git; \
apt-get autoremove -y; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*
FROM debian:buster-slim as base

WORKDIR /dojo
COPY . .
RUN cargo build --release --config net.git-fetch-with-cli=true

FROM debian:buster-slim
LABEL description="Dojo is a provable game engine and toolchain for building onchain games and autonomous worlds with Cairo" \
authors="tarrence <[email protected]>" \
source="https://github.com/dojoengine/dojo" \
documentation="https://book.dojoengine.org/"

RUN apt-get -y update; \
apt-get install -y --no-install-recommends \
curl; \
apt-get autoremove -y; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*

# Set an environment variable for the port
ENV HEALTH_CHECK_PORT=5050

HEALTHCHECK --interval=3s --timeout=5s --start-period=1s --retries=5 \
CMD curl --request POST \
--header "Content-Type: application/json" \
--data '{"jsonrpc": "2.0","method": "starknet_chainId","id":1}' http://localhost:${HEALTH_CHECK_PORT} || exit 1
FROM base as amd64
COPY target/x86_64-unknown-linux-gnu/release/katana /usr/local/bin/katana
COPY target/x86_64-unknown-linux-gnu/release/sozo /usr/local/bin/sozo
COPY target/x86_64-unknown-linux-gnu/release/torii /usr/local/bin/torii

COPY --from=builder /dojo/target/release/katana /usr/local/bin/katana
COPY --from=builder /dojo/target/release/sozo /usr/local/bin/sozo
COPY --from=builder /dojo/target/release/torii /usr/local/bin/torii
FROM base as arm64
COPY target/aarch64-unknown-linux-gnu/release/katana /usr/local/bin/katana
COPY target/aarch64-unknown-linux-gnu/release/sozo /usr/local/bin/sozo
COPY target/aarch64-unknown-linux-gnu/release/torii /usr/local/bin/torii

0 comments on commit 104afa0

Please sign in to comment.