From 898dd5b86f7fda4a9e2fbdf50002dcc443d1d369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Cl=C3=A9roux?= <73357644+gcleroux@users.noreply.github.com> Date: Tue, 30 Jul 2024 13:11:28 -0400 Subject: [PATCH 1/2] Change build process to use busybox --- .github/workflows/docker.yml | 16 ++++------------ Dockerfile | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index d73d8b1..f71bf93 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -19,21 +19,12 @@ jobs: contents: read packages: write - strategy: - matrix: - go-version: [1.22.x] - outputs: tags: ${{ steps.meta.outputs.tags }} steps: - uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: ${{ matrix.go-version }} - - name: Print branch name id: extract_branch shell: bash @@ -41,9 +32,6 @@ jobs: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" echo "##[set-output name=release_train;]$(echo ${GITHUB_REF#refs/heads/release/})" - - name: Build - run: go build -v -ldflags "-X main.version=${{ github.event.ref }} -X main.commit=${{ github.sha }} -X main.date=$(date -u +%Y-%m-%dT%H:%MZ)" -o ./substreams-sink-sql ./cmd/substreams-sink-sql - - name: Log in to the Container registry uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 with: @@ -68,6 +56,10 @@ jobs: uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: context: . + build-args: | + BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} + VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} + REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index 3ecbbdd..bdd0972 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,21 @@ -FROM gcr.io/distroless/base-debian12:latest +FROM golang:1.22.5-alpine3.20 AS build -ADD /substreams-sink-sql /app/substreams-sink-sql +ARG BUILDTIME +ARG VERSION +ARG REVISION -ENV PATH "$PATH:/app" +WORKDIR /build + +COPY . . + +RUN CGO_ENABLED=0 go build -v -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o ./substreams-sink-sql ./cmd/substreams-sink-sql + +FROM gcr.io/distroless/static-debian12:latest + +WORKDIR /app + +COPY --from=busybox:1.36.1-uclibc /bin/sh /bin/sh +COPY --from=busybox:1.36.1-uclibc /bin/touch /bin/touch +COPY --from=build /build/substreams-sink-sql . ENTRYPOINT ["/app/substreams-sink-sql"] From f96fea6f94825e82a8b7fb23511f5844ee3bc4bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Cl=C3=A9roux?= <73357644+gcleroux@users.noreply.github.com> Date: Wed, 31 Jul 2024 10:08:12 -0400 Subject: [PATCH 2/2] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index bdd0972..163b3e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ WORKDIR /build COPY . . -RUN CGO_ENABLED=0 go build -v -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o ./substreams-sink-sql ./cmd/substreams-sink-sql +RUN CGO_ENABLED=0 go build -v -ldflags "-X main.version=${VERSION} -X main.commit=${REVISION} -X main.date=${BUILDTIME}" -o ./substreams-sink-sql ./cmd/substreams-sink-sql FROM gcr.io/distroless/static-debian12:latest