-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Docker-based CI/CD workflow for publishing (#3)
- Loading branch information
Showing
3 changed files
with
117 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,3 @@ | ||
.git/ | ||
.idea/ | ||
target/ |
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,77 @@ | ||
name: release | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- hotfix | ||
tags: | ||
- "v*" | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
REGISTRY: ghcr.io | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
attestations: write | ||
id-token: write | ||
|
||
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 | ||
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: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ github.repository }} | ||
|
||
- name: Build and push Docker image | ||
id: push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
||
- name: Generate artifact attestation | ||
uses: actions/attest-build-provenance@v1 | ||
with: | ||
subject-name: ${{ env.REGISTRY }}/${{ github.repository }} | ||
subject-digest: ${{ steps.push.outputs.digest }} | ||
push-to-registry: true | ||
|
||
- # 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 | ||
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
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,37 @@ | ||
FROM rust:1-alpine AS chef | ||
RUN rustup install 1.79.0 | ||
RUN rustup component add cargo clippy rust-docs rust-std rustc rustfmt | ||
|
||
# Use apk for package management in Alpine | ||
RUN apk add --no-cache build-base libressl-dev | ||
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 | ||
|
||
# Build application | ||
COPY . . | ||
ENV PATH="/root/.cargo/bin:${PATH}" | ||
|
||
RUN cargo build --release | ||
|
||
FROM rust:1-alpine | ||
|
||
WORKDIR / | ||
|
||
COPY --from=builder /app/target/release/vrf_demo-rpc-server /usr/local/bin/server | ||
|
||
EXPOSE 3000 | ||
|
||
ENTRYPOINT [ "server" ] |