diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index cc41fdf2..1a33739c 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -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: @@ -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 @@ -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 : # @@ -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}} @@ -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 }} diff --git a/Dockerfile b/Dockerfile index 9d1d4743..6e1e0af6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/Dockerfile.dependencies b/Dockerfile.dependencies new file mode 100644 index 00000000..f9d15a6d --- /dev/null +++ b/Dockerfile.dependencies @@ -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 diff --git a/README.md b/README.md index aa154157..491c582d 100644 --- a/README.md +++ b/README.md @@ -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 ```