Skip to content

Commit

Permalink
CICD improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mateipopa committed Dec 23, 2024
1 parent 48b7224 commit ad60f78
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 30 deletions.
56 changes: 45 additions & 11 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,28 @@ jobs:
SHA=$(git rev-parse --short HEAD)
echo "image_name=node-base" >> $GITHUB_OUTPUT
echo "image_tag=${SHA}" >> $GITHUB_OUTPUT
- name: Generate build arguments
id: build-args
run: |
# Extract all ARG declarations that end with _IMAGE from Dockerfile
BUILD_ARGS=$(grep "^ARG.*_IMAGE=" ./${{ matrix.image_path }}/Dockerfile | while read -r line; do
# Extract the variable name (everything before =)
var_name=$(echo "$line" | sed 's/ARG \(.*\)=.*/\1/')
# Construct the full image path with version
echo "${var_name}=ghcr.io/blockjoy/${var_name/_IMAGE/}:${{ steps.version.outputs.image_tag }}"
done | tr '\n' ',' | sed 's/,$//')
# Add the standard build args
BUILD_ARGS="${BUILD_ARGS},GRAFANA_LOKI_API_KEY=${{ secrets.GRAFANA_LOKI_API_KEY }},GRAFANA_PROM_API_KEY=${{ secrets.GRAFANA_PROM_API_KEY }}"
echo "args=${BUILD_ARGS}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push base image
uses: docker/build-push-action@v5
with:
context: ./${{ matrix.image_path }}
push: true
build-args: |
GRAFANA_LOKI_API_KEY=${{ secrets.GRAFANA_LOKI_API_KEY }}
GRAFANA_PROM_API_KEY=${{ secrets.GRAFANA_PROM_API_KEY }}
build-args: ${{ steps.build-args.outputs.args }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ghcr.io/blockjoy/${{ steps.version.outputs.image_name }}:${{ steps.version.outputs.image_tag }}
Expand Down Expand Up @@ -125,17 +137,28 @@ jobs:
fi
echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
echo "image_tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Generate build arguments
id: build-args
run: |
# Extract all ARG declarations that end with _IMAGE from Dockerfile
BUILD_ARGS=$(grep "^ARG.*_IMAGE=" ./${{ matrix.image_path }}/Dockerfile | while read -r line; do
# Extract the variable name (everything before =)
var_name=$(echo "$line" | sed 's/ARG \(.*\)=.*/\1/')
# Construct the full image path with version
echo "${var_name}=ghcr.io/blockjoy/${var_name/_IMAGE/}:${{ steps.version.outputs.image_tag }}"
done | tr '\n' ',' | sed 's/,$//')
# Add the standard build args
BUILD_ARGS="${BUILD_ARGS},GRAFANA_LOKI_BASICAUTH=${{ secrets.GRAFANA_LOKI_BASICAUTH }},GRAFANA_PROM_BASICAUTH=${{ secrets.GRAFANA_PROM_BASICAUTH }},CLOUDFLARE_API_KEY=${{ secrets.CLOUDFLARE_API_KEY }}"
echo "args=${BUILD_ARGS}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push client images
uses: docker/build-push-action@v5
with:
context: ./${{ matrix.image_path }}
push: true
build-args: |
GRAFANA_LOKI_BASICAUTH=${{ secrets.GRAFANA_LOKI_BASICAUTH }}
GRAFANA_PROM_BASICAUTH=${{ secrets.GRAFANA_PROM_BASICAUTH }}
CLOUDFLARE_API_KEY=${{ secrets.CLOUDFLARE_API_KEY }}
build-args: ${{ steps.build-args.outputs.args }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ghcr.io/blockjoy/${{ steps.version.outputs.image_name }}:${{ steps.version.outputs.image_tag }}
Expand Down Expand Up @@ -164,17 +187,28 @@ jobs:
IMAGE_NAME=$(basename $(dirname ${{ matrix.image_path }}))"-"$(basename ${{ matrix.image_path }})
echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
echo "image_tag=${SHA}" >> $GITHUB_OUTPUT
- name: Generate build arguments
id: build-args
run: |
# Extract all ARG declarations that end with _IMAGE from Dockerfile
BUILD_ARGS=$(grep "^ARG.*_IMAGE=" ./${{ matrix.image_path }}/Dockerfile | while read -r line; do
# Extract the variable name (everything before =)
var_name=$(echo "$line" | sed 's/ARG \(.*\)=.*/\1/')
# Construct the full image path with version
echo "${var_name}=ghcr.io/blockjoy/${var_name/_IMAGE/}:${{ steps.version.outputs.image_tag }}"
done | tr '\n' ',' | sed 's/,$//')
# Add the standard build args
BUILD_ARGS="${BUILD_ARGS},GRAFANA_LOKI_BASICAUTH=${{ secrets.GRAFANA_LOKI_BASICAUTH }},GRAFANA_PROM_BASICAUTH=${{ secrets.GRAFANA_PROM_BASICAUTH }},CLOUDFLARE_API_KEY=${{ secrets.CLOUDFLARE_API_KEY }}"
echo "args=${BUILD_ARGS}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push protocol images
uses: docker/build-push-action@v5
with:
context: ./${{ matrix.image_path }}
push: true
build-args: |
GRAFANA_LOKI_BASICAUTH=${{ secrets.GRAFANA_LOKI_BASICAUTH }}
GRAFANA_PROM_BASICAUTH=${{ secrets.GRAFANA_PROM_BASICAUTH }}
CLOUDFLARE_API_KEY=${{ secrets.CLOUDFLARE_API_KEY }}
build-args: ${{ steps.build-args.outputs.args }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ghcr.io/blockjoy/${{ steps.version.outputs.image_name }}:${{ steps.version.outputs.image_tag }}
5 changes: 3 additions & 2 deletions clients/consensus/lighthouse/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM node-base:latest
ARG BASE_IMAGE=ghcr.io/blockjoy/node-base:57f9ec4

FROM ${BASE_IMAGE}

ENV DEBIAN_FRONTEND=noninteractive

Expand Down Expand Up @@ -30,4 +32,3 @@ WORKDIR /root/lighthouse
RUN . "$HOME/.cargo/env" && cargo build --release --features portable && \
mkdir -p /root/bin && \
cp /root/lighthouse/target/release/lighthouse /root/bin/lighthouse

5 changes: 3 additions & 2 deletions clients/exec/erigon/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM node-base:latest
ARG BASE_IMAGE=ghcr.io/blockjoy/node-base:57f9ec4

# Add build arguments for Cloudflare and Grafana push credentials
ARG CLOUDFLARE_API_KEY
ARG GRAFANA_LOKI_BASICAUTH
ARG GRAFANA_PROM_BASICAUTH

FROM ${BASE_IMAGE}

ENV DEBIAN_FRONTEND=noninteractive
ENV CLOUDFLARE_API_KEY=${CLOUDFLARE_API_KEY}
ENV GRAFANA_LOKI_BASICAUTH=${GRAFANA_LOKI_BASICAUTH}
Expand All @@ -26,4 +28,3 @@ WORKDIR /root/erigon
RUN make erigon

RUN cp /root/erigon/build/bin/erigon /root/bin/erigon

8 changes: 5 additions & 3 deletions clients/exec/reth/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
FROM node-base:latest
ARG BASE_IMAGE=ghcr.io/blockjoy/node-base:57f9ec4
ARG RETH_VERSION=v1.1.4
ARG LIGHTHOUSE_VERSION=v5.3.0

FROM ${BASE_IMAGE}

ENV DEBIAN_FRONTEND=noninteractive

ENV RETH_VERSION=v1.1.4
ENV LIGHTHOUSE_VERSION=v5.3.0
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true

# Install system dependencies including libclang
Expand Down
15 changes: 9 additions & 6 deletions ethereum/ethereum-erigon/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
FROM ethereum-erigon:latest as erigon-build

FROM lighthouse:latest AS lighthouse-build

FROM node-base:latest

ARG ERIGON_IMAGE=erigon:latest
ARG LIGHTHOUSE_IMAGE=lighthouse:latest
ARG BASE_IMAGE=node-base:latest
ARG CLOUDFLARE_API_KEY
ARG GRAFANA_LOKI_BASICAUTH
ARG GRAFANA_PROM_BASICAUTH
Expand All @@ -12,6 +9,12 @@ ENV CLOUDFLARE_API_KEY=${CLOUDFLARE_API_KEY}
ENV GRAFANA_LOKI_BASICAUTH=${GRAFANA_LOKI_BASICAUTH}
ENV GRAFANA_PROM_BASICAUTH=${GRAFANA_PROM_BASICAUTH}

FROM ${ERIGON_IMAGE} as erigon-build

FROM ${LIGHTHOUSE_IMAGE} AS lighthouse-build

FROM ${BASE_IMAGE}

RUN mkdir -p /root/bin
COPY --from=erigon-build /root/bin/erigon /root/bin/
COPY --from=lighthouse-build /root/bin/lighthouse /root/bin/
Expand Down
14 changes: 9 additions & 5 deletions ethereum/ethereum-reth/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
FROM reth:latest AS reth-build

FROM lighthouse:latest AS lighthouse-build

FROM node-base:latest
ARG RETH_IMAGE=reth:latest
ARG LIGHTHOUSE_IMAGE=lighthouse:latest
ARG BASE_IMAGE=node-base:latest

ARG CLOUDFLARE_API_KEY
ARG GRAFANA_LOKI_BASICAUTH
Expand All @@ -12,6 +10,12 @@ ENV CLOUDFLARE_API_KEY=${CLOUDFLARE_API_KEY}
ENV GRAFANA_LOKI_BASICAUTH=${GRAFANA_LOKI_BASICAUTH}
ENV GRAFANA_PROM_BASICAUTH=${GRAFANA_PROM_BASICAUTH}

FROM ${RETH_IMAGE} AS reth-build

FROM ${LIGHTHOUSE_IMAGE} AS lighthouse-build

FROM ${BASE_IMAGE}

RUN mkdir -p /root/bin
COPY --from=reth-build /root/bin/reth /root/bin/
COPY --from=lighthouse-build /root/bin/lighthouse /root/bin/
Expand Down
4 changes: 3 additions & 1 deletion node-base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM debian:bookworm-slim@sha256:a165446a88794db4fec31e35e9441433f9552ae048fb1ed26df352d2b537cb96
ARG BASE_IMAGE=debian:bookworm-slim@sha256:a165446a88794db4fec31e35e9441433f9552ae048fb1ed26df352d2b537cb96

FROM ${BASE_IMAGE}

ARG GRAFANA_LOKI_API_KEY
ARG GRAFANA_PROM_API_KEY
Expand Down

0 comments on commit ad60f78

Please sign in to comment.