-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(workflows) add GitHub Actions workflow for preview builds (#2446)
* Add GitHub Actions workflow for Docker builds and deployment This commit introduces a new GitHub Actions workflow file, `preview.yml`, to automate building and deploying Docker images. The workflow includes steps for setting up the Rust toolchain, building binaries, archiving artifacts, and deploying them via Docker and Slot. This enhancement streamlines the CI/CD process, ensuring consistency and efficiency in releases. * wip * wip * fix * bin slot * fix * temp * wip * xdg * short sha * uncomment * world input * remove slot * fix * bump * remove branch deploy * dockerify all * temp preview publish * rust toolchain & fixes * docker wip * build local and run * revert * checkout fix * ls * fix * fix * fix artifacts * move cache * separate cache * minor adaptions * bump to 32 cores yolo * remove temp push trigger
- Loading branch information
Showing
4 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
target/ | ||
.git/ | ||
.github/ | ||
.idea/ | ||
.vscode/ | ||
.devcontainer/ | ||
.cargo/ | ||
artifacts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
FROM rust:slim as chef | ||
|
||
# Install libclang and other necessary tools | ||
RUN apt-get update && \ | ||
apt-get install -y clang llvm-dev libclang-dev git libtool automake autoconf make curl protobuf-compiler && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Verify and set LIBCLANG_PATH environment variable | ||
RUN find /usr -name "libclang.so*" && \ | ||
export LIBCLANG_PATH=$(find /usr -name "libclang.so*" | head -n 1 | xargs dirname) | ||
|
||
COPY rust-toolchain.toml . | ||
RUN rustup install $(cat rust-toolchain.toml | grep channel | cut -d' ' -f3 | tr -d '"') | ||
RUN rustup component add cargo clippy rust-docs rust-std rustc rustfmt | ||
|
||
RUN cargo install cargo-chef | ||
|
||
FROM chef AS planner | ||
|
||
WORKDIR /app | ||
COPY . . | ||
RUN cargo chef prepare --recipe-path recipe.json | ||
|
||
FROM chef AS builder | ||
|
||
WORKDIR /app | ||
COPY --from=planner /app/recipe.json recipe.json | ||
# Build dependencies - this is the caching Docker layer! | ||
RUN cargo chef cook --release --recipe-path recipe.json | ||
RUN cargo build --release --bins # pre-cache some stuff | ||
|
||
# Build application | ||
COPY . . | ||
ENV PATH="/root/.cargo/bin:${PATH}" | ||
|
||
RUN cargo build --release --bins | ||
|
||
FROM rust:1-alpine | ||
|
||
WORKDIR / | ||
|
||
COPY --from=builder /app/target/release/katana /app/artifacts/ | ||
COPY --from=builder /app/target/release/torii /app/artifacts/ | ||
COPY --from=builder /app/target/release/sozo /app/artifacts/ | ||
COPY --from=builder /app/target/release/saya /app/artifacts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
name: preview | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest-32-cores | ||
|
||
steps: | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v4 | ||
with: | ||
path: /tmp/.buildx-cache/prebuild | ||
key: ${{ runner.os }}-buildx-${{ github.ref_name }}-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx-${{ github.ref_name }} | ||
${{ runner.os }}-buildx- | ||
- name: Cache Docker layers | ||
uses: actions/cache@v4 | ||
with: | ||
path: /tmp/.buildx-cache/build | ||
key: ${{ runner.os }}-buildx-${{ github.ref_name }}-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx-${{ github.ref_name }} | ||
${{ runner.os }}-buildx- | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set outputs | ||
id: vars | ||
run: | | ||
set -eux | ||
git config --global --add safe.directory "${{ github.workspace }}" | ||
echo "sha_short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" | ||
- name: Build Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: .github/Dockerfile | ||
load: true | ||
tags: build-local:latest | ||
cache-from: type=local,src=/tmp/.buildx-cache/prebuild | ||
cache-to: type=local,dest=/tmp/.buildx-cache-new/prebuild,mode=max | ||
platforms: linux/amd64 | ||
|
||
- name: Build local binaries | ||
run: | | ||
set -eux | ||
docker run --rm -v "$(pwd)/artifacts/$PLATFORM:/artifacts" build-local:latest /bin/sh -c "cp -r /app/artifacts/* /artifacts/" | ||
env: | ||
PLATFORM: linux/amd64 | ||
|
||
- name: Build and push docker image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
push: true | ||
tags: ghcr.io/${{ github.repository }}:preview--${{ steps.vars.outputs.sha_short }} | ||
cache-from: type=local,src=/tmp/.buildx-cache/build | ||
cache-to: type=local,dest=/tmp/.buildx-cache-new/build,mode=max | ||
platforms: linux/amd64 | ||
build-contexts: | | ||
artifacts=artifacts | ||
- # Temp fix | ||
# https://github.com/docker/build-push-action/issues/252 | ||
# https://github.com/moby/buildkit/issues/1896 | ||
name: Move cache | ||
run: | | ||
rm -rf /tmp/.buildx-cache/prebuild | ||
mv /tmp/.buildx-cache-new/prebuild /tmp/.buildx-cache/prebuild | ||
rm -rf /tmp/.buildx-cache/build | ||
mv /tmp/.buildx-cache-new/build /tmp/.buildx-cache/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,5 @@ justfile | |
spawn-and-move-db | ||
types-test-db | ||
examples/spawn-and-move/manifests/saya/** | ||
|
||
artifacts/ |