Skip to content

Commit 0b7e36e

Browse files
authored
chore: Add reproducible build docker and github release workflow (#28)
* chore: Add reproducible build docker and github release workflow * use kaniko to build the image container reproducibly
1 parent 8e5c9a1 commit 0b7e36e

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

.github/workflows/release.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
KANIKO_VERSION: gcr.io/kaniko-project/executor@sha256:9e69fd4330ec887829c780f5126dd80edc663df6def362cd22e79bcdf00ac53f
12+
13+
jobs:
14+
build-and-push:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
strategy:
21+
matrix:
22+
binary: [proxy-client, proxy-server]
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Extract metadata
31+
id: meta
32+
uses: docker/metadata-action@9ec57ed1fcdf50867830130cc04c4d1bb9de141d
33+
with:
34+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.binary }}
35+
tags: |
36+
type=semver,pattern={{version}}
37+
type=semver,pattern={{major}}.{{minor}}
38+
type=sha
39+
40+
- name: Build and Push with Kaniko
41+
run: |
42+
mkdir -p /home/runner/.docker
43+
44+
echo '{"auths":{"${{ env.REGISTRY }}":{"auth":"'$(echo -n "${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}" | base64)'"}}}'> /home/runner/.docker/config.json
45+
46+
docker run \
47+
-v ${{ github.workspace }}:/workspace \
48+
-v /home/runner/.docker/config.json:/kaniko/.docker/config.json \
49+
${{ env.KANIKO_VERSION }} \
50+
--context /workspace \
51+
--dockerfile /workspace/Dockerfile \
52+
--reproducible \
53+
--cache=true \
54+
--cache-repo ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-cache \
55+
--build-arg BINARY=${{ matrix.binary }} \
56+
--destination ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.binary }}:${{ steps.meta.outputs.version }} \
57+
${{ join(steps.meta.outputs.tags-csv | split(',') | map(format('--destination %s', @)), ' ') }}

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM golang:1.24rc2-bullseye@sha256:236da40764c1bcf469fcaf6ca225ca881c3f06cbd1934e392d6e4af3484f6cac AS builder
2+
3+
ARG BINARY=proxy-client
4+
WORKDIR /app
5+
COPY ./ /app
6+
RUN make build-${BINARY}
7+
8+
FROM gcr.io/distroless/cc-debian12:nonroot-6755e21ccd99ddead6edc8106ba03888cbeed41a
9+
ARG BINARY
10+
COPY --from=builder /app/build/${BINARY} /app
11+
ENTRYPOINT [ "/app" ]

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ build: clean build-proxy-client build-proxy-server ## Build the proxy client and
2626
.PHONY: build-proxy-client
2727
build-proxy-client: ## Build the proxy client
2828
@mkdir -p ./build
29-
go build -trimpath -ldflags "-X github.com/flashbots/cvm-reverse-proxy/common.Version=${VERSION}" -v -o ./build/proxy-client cmd/proxy-client/main.go
29+
go build -trimpath -ldflags "-s -w -buildid= -X github.com/flashbots/cvm-reverse-proxy/common.Version=${VERSION}" -v -o ./build/proxy-client cmd/proxy-client/main.go
3030

3131
.PHONY: build-proxy-server
3232
build-proxy-server: ## Build the proxy server
3333
@mkdir -p ./build
34-
go build -trimpath -ldflags "-X github.com/flashbots/cvm-reverse-proxy/common.Version=${VERSION}" -v -o ./build/proxy-server cmd/proxy-server/main.go
34+
go build -trimpath -ldflags "-s -w -buildid= -X github.com/flashbots/cvm-reverse-proxy/common.Version=${VERSION}" -v -o ./build/proxy-server cmd/proxy-server/main.go
3535

3636
##@ Test & Development
3737

0 commit comments

Comments
 (0)