Skip to content

Commit 8b7d6b2

Browse files
authored
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
1 parent 82a23a5 commit 8b7d6b2

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed

.dockerignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
target/
2+
.git/
3+
.github/
4+
.idea/
5+
.vscode/
6+
.devcontainer/
7+
.cargo/
8+
artifacts/

.github/Dockerfile

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
FROM rust:slim as chef
2+
3+
# Install libclang and other necessary tools
4+
RUN apt-get update && \
5+
apt-get install -y clang llvm-dev libclang-dev git libtool automake autoconf make curl protobuf-compiler && \
6+
rm -rf /var/lib/apt/lists/*
7+
8+
# Verify and set LIBCLANG_PATH environment variable
9+
RUN find /usr -name "libclang.so*" && \
10+
export LIBCLANG_PATH=$(find /usr -name "libclang.so*" | head -n 1 | xargs dirname)
11+
12+
COPY rust-toolchain.toml .
13+
RUN rustup install $(cat rust-toolchain.toml | grep channel | cut -d' ' -f3 | tr -d '"')
14+
RUN rustup component add cargo clippy rust-docs rust-std rustc rustfmt
15+
16+
RUN cargo install cargo-chef
17+
18+
FROM chef AS planner
19+
20+
WORKDIR /app
21+
COPY . .
22+
RUN cargo chef prepare --recipe-path recipe.json
23+
24+
FROM chef AS builder
25+
26+
WORKDIR /app
27+
COPY --from=planner /app/recipe.json recipe.json
28+
# Build dependencies - this is the caching Docker layer!
29+
RUN cargo chef cook --release --recipe-path recipe.json
30+
RUN cargo build --release --bins # pre-cache some stuff
31+
32+
# Build application
33+
COPY . .
34+
ENV PATH="/root/.cargo/bin:${PATH}"
35+
36+
RUN cargo build --release --bins
37+
38+
FROM rust:1-alpine
39+
40+
WORKDIR /
41+
42+
COPY --from=builder /app/target/release/katana /app/artifacts/
43+
COPY --from=builder /app/target/release/torii /app/artifacts/
44+
COPY --from=builder /app/target/release/sozo /app/artifacts/
45+
COPY --from=builder /app/target/release/saya /app/artifacts/

.github/workflows/preview.yml

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: preview
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
publish:
8+
runs-on: ubuntu-latest-32-cores
9+
10+
steps:
11+
- name: Set up Docker Buildx
12+
uses: docker/setup-buildx-action@v3
13+
14+
- name: Cache Docker layers
15+
uses: actions/cache@v4
16+
with:
17+
path: /tmp/.buildx-cache/prebuild
18+
key: ${{ runner.os }}-buildx-${{ github.ref_name }}-${{ github.sha }}
19+
restore-keys: |
20+
${{ runner.os }}-buildx-${{ github.ref_name }}
21+
${{ runner.os }}-buildx-
22+
23+
- name: Cache Docker layers
24+
uses: actions/cache@v4
25+
with:
26+
path: /tmp/.buildx-cache/build
27+
key: ${{ runner.os }}-buildx-${{ github.ref_name }}-${{ github.sha }}
28+
restore-keys: |
29+
${{ runner.os }}-buildx-${{ github.ref_name }}
30+
${{ runner.os }}-buildx-
31+
32+
- name: Checkout repository
33+
uses: actions/checkout@v4
34+
35+
- name: Login to GitHub Container Registry
36+
uses: docker/login-action@v3
37+
with:
38+
registry: ghcr.io
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Set outputs
43+
id: vars
44+
run: |
45+
set -eux
46+
git config --global --add safe.directory "${{ github.workspace }}"
47+
echo "sha_short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
48+
49+
- name: Build Docker image
50+
uses: docker/build-push-action@v5
51+
with:
52+
context: .
53+
file: .github/Dockerfile
54+
load: true
55+
tags: build-local:latest
56+
cache-from: type=local,src=/tmp/.buildx-cache/prebuild
57+
cache-to: type=local,dest=/tmp/.buildx-cache-new/prebuild,mode=max
58+
platforms: linux/amd64
59+
60+
- name: Build local binaries
61+
run: |
62+
set -eux
63+
docker run --rm -v "$(pwd)/artifacts/$PLATFORM:/artifacts" build-local:latest /bin/sh -c "cp -r /app/artifacts/* /artifacts/"
64+
env:
65+
PLATFORM: linux/amd64
66+
67+
- name: Build and push docker image
68+
uses: docker/build-push-action@v3
69+
with:
70+
push: true
71+
tags: ghcr.io/${{ github.repository }}:preview--${{ steps.vars.outputs.sha_short }}
72+
cache-from: type=local,src=/tmp/.buildx-cache/build
73+
cache-to: type=local,dest=/tmp/.buildx-cache-new/build,mode=max
74+
platforms: linux/amd64
75+
build-contexts: |
76+
artifacts=artifacts
77+
78+
- # Temp fix
79+
# https://github.com/docker/build-push-action/issues/252
80+
# https://github.com/moby/buildkit/issues/1896
81+
name: Move cache
82+
run: |
83+
rm -rf /tmp/.buildx-cache/prebuild
84+
mv /tmp/.buildx-cache-new/prebuild /tmp/.buildx-cache/prebuild
85+
rm -rf /tmp/.buildx-cache/build
86+
mv /tmp/.buildx-cache-new/build /tmp/.buildx-cache/build

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ justfile
2121
spawn-and-move-db
2222
types-test-db
2323
examples/spawn-and-move/manifests/saya/**
24+
25+
artifacts/

0 commit comments

Comments
 (0)