Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📦️ Add docker build CI cache #492

Merged
merged 18 commits into from
Jan 2, 2025
Merged
30 changes: 23 additions & 7 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
name: Push to Artifact Registry
name: Docker image

on:
push:
branches:
- 'main'
- 'releases/**'
- 'publish_ghcr'
tags:
- '*'

env:
IMAGE_NAME: 'hyle'
AR_REPO_LOCATION: 'europe-west3-docker.pkg.dev'
AR_URL: 'hyle-413414/hyle-docker'

jobs:
build_and_push:
Expand All @@ -23,7 +20,23 @@ jobs:
packages: 'write'

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
mode:
- file: Dockerfile
name: hyle
push_ghcr: true
images: |
europe-west3-docker.pkg.dev/hyle-413414/hyle-docker/hyle
ghcr.io/hyle-org/hyle
- file: Dockerfile.dependencies
name: hyle dependencies
push_ghcr: false
images: |
europe-west3-docker.pkg.dev/hyle-413414/hyle-docker/hyle

name: ${{ matrix.mode.name }}
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -32,9 +45,8 @@ jobs:
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{env.AR_REPO_LOCATION}}/${{ env.AR_URL }}/${{ env.IMAGE_NAME }}
ghcr.io/hyle-org/${{ env.IMAGE_NAME }}
images: ${{ matrix.mode.images }}


# Will produces tags given this table :
#
Expand All @@ -57,6 +69,7 @@ jobs:

- name: 'Login to GitHub Container Registry'
uses: docker/login-action@v1
if: ${{ matrix.mode.push_ghcr }}
with:
registry: ghcr.io
username: ${{github.actor}}
Expand All @@ -66,7 +79,10 @@ jobs:
uses: docker/build-push-action@v6
with:
push: true
file: ${{ matrix.mode.file }}
context: .
build-args: |
DEP_IMAGE=europe-west3-docker.pkg.dev/hyle-413414/hyle-docker/hyle-dependencies:main
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

12 changes: 3 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
FROM rust:alpine AS builder

RUN apk add pkgconfig openssl-dev gcc musl-dev
RUN apk add --no-cache openssl-libs-static
RUN apk add curl bash

WORKDIR /usr/src/hyle
ARG DEP_IMAGE=hyle-dep
FROM $DEP_IMAGE AS builder

# Build application
COPY Cargo.toml Cargo.lock ./
COPY .cargo/config.toml .cargo/config.toml

COPY src ./src
COPY contract-sdk ./contract-sdk
COPY contracts ./contracts
COPY crates ./crates

RUN cargo build --bin node --bin indexer --release --features node_local_proving

# RUNNER
Expand Down
22 changes: 22 additions & 0 deletions Dockerfile.dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM rust:alpine AS chef
RUN apk add pkgconfig openssl-dev gcc musl-dev
RUN apk add --no-cache openssl-libs-static
RUN apk add curl bash
RUN cargo install cargo-chef
WORKDIR /usr/src/hyle


FROM chef AS planner
COPY Cargo.toml Cargo.lock ./
COPY .cargo/config.toml .cargo/config.toml
COPY src ./src
COPY contract-sdk ./contract-sdk
COPY contracts ./contracts
COPY crates ./crates
RUN cargo chef prepare --recipe-path recipe.json

FROM chef
COPY --from=planner /usr/src/hyle/recipe.json recipe.json

# Build dependencies
RUN cargo chef cook --release --recipe-path recipe.json
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ hyled --help
### Build Locally

```bash
# Build the dependency image, this is a cache layer for faster iteration builds
docker build . -t hyle-dep -f Dockerfile.dependencies
# Build the node image
docker build . -t hyle
```

Expand Down
Loading