Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.git
.github
.cache
.env
.env.*
*.log
*.out
archive-wrapper
coverage*
tmp
v2/data
FLEXIBLE_DEPLOYMENT_REQUIREMENTS.md
183 changes: 183 additions & 0 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
name: Container

on:
pull_request:
push:
branches:
- development

permissions:
contents: read

concurrency:
group: container-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
go:
name: Go validation
runs-on: ubuntu-24.04
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true

- name: Run unit tests
env:
GOCACHE: /tmp/go-build-cache
run: go test -tags=purego ./... -count=1

- name: Run focused race tests
env:
GOCACHE: /tmp/go-build-cache
run: go test -race -tags=purego ./config ./cmd/archive-wrapper -count=1

- name: Run vet
env:
GOCACHE: /tmp/go-build-cache
run: go vet -tags=purego ./...

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.11.4
args: --build-tags=purego ./...

- name: Verify module files
run: go mod tidy -diff

container:
name: Container validation
needs: go
runs-on: ubuntu-24.04
env:
IMAGE: archive-wrapper:${{ github.sha }}
BUILDER_IMAGE: archive-wrapper-builder:${{ github.sha }}
GOCACHE: /tmp/go-build-cache
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v4

- name: Build multi-platform OCI image
run: |
make docker-build-multiarch \
DOCKER_BUILDER="${{ steps.buildx.outputs.name }}" \
IMAGE="$IMAGE" \
OCI_OUTPUT="$RUNNER_TEMP/archive-wrapper.oci.tar"
sha256sum "$RUNNER_TEMP/archive-wrapper.oci.tar"

- name: Verify reproducible artifacts
run: |
make reproducible-build
make reproducible-image DOCKER_BUILDER="${{ steps.buildx.outputs.name }}"

- name: Build native test image
run: make docker-build IMAGE="$IMAGE"

- name: Build builder stage for security scanning
run: |
docker buildx build --load --target builder --platform=linux/amd64 \
-t "$BUILDER_IMAGE" .

- name: Prepare security report directory
run: mkdir -p .cache/container-artifacts

- name: Install govulncheck
env:
CGO_ENABLED: "0"
GOBIN: ${{ runner.temp }}/govulncheck-bin
run: |
mkdir -p "$GOBIN"
go install golang.org/x/vuln/cmd/govulncheck@v1.6.0

- name: Report reachable Go vulnerabilities
run: |
raw_report="$RUNNER_TEMP/govulncheck.sarif"
docker run --rm \
--env GOTELEMETRY=off \
--entrypoint /tools/govulncheck \
--volume "$RUNNER_TEMP/govulncheck-bin:/tools:ro" \
"$BUILDER_IMAGE" \
-tags=purego -format sarif ./cmd/archive-wrapper \
> "$raw_report"
jq -e '
.runs |= map(
(.results // []) |= map(select(.level == "error"))
| . as $run
| .tool.driver.rules = [
(.tool.driver.rules // [])[]
| select(.id as $id | any($run.results[]; .ruleId == $id))
]
)
' "$raw_report" > .cache/container-artifacts/govulncheck.sarif

- name: Enforce builder OS vulnerability policy
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
image-ref: ${{ env.BUILDER_IMAGE }}
format: table
exit-code: "1"
ignore-unfixed: true
vuln-type: os
severity: CRITICAL,HIGH
scanners: vuln
version: v0.73.0

- name: Enforce runtime OS vulnerability policy
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
image-ref: ${{ env.IMAGE }}
format: table
exit-code: "1"
ignore-unfixed: true
vuln-type: os
severity: CRITICAL,HIGH
scanners: vuln
skip-setup-trivy: true

- name: Run container smoke tests
env:
ARCHIVE_WRAPPER_SKIP_BUILD: "1"
ARCHIVE_WRAPPER_ARTIFACT_DIR: .cache/container-artifacts
run: make docker-test IMAGE="$IMAGE"

- name: Upload OCI artifact
uses: actions/upload-artifact@v4
with:
name: archive-wrapper-oci-${{ github.sha }}
path: ${{ runner.temp }}/archive-wrapper.oci.tar
if-no-files-found: error
retention-days: 7

- name: Upload vulnerability report
if: always()
uses: actions/upload-artifact@v4
with:
name: go-vulnerabilities-${{ github.sha }}
path: .cache/container-artifacts/govulncheck.sarif
if-no-files-found: warn
retention-days: 7

- name: Upload failure diagnostics
if: failure()
uses: actions/upload-artifact@v4
with:
name: container-failure-${{ github.sha }}
path: .cache/container-artifacts
if-no-files-found: ignore
retention-days: 7
53 changes: 53 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# syntax=docker/dockerfile:1.10

ARG SOURCE_DATE_EPOCH=0

FROM --platform=$BUILDPLATFORM golang:1.26.5-alpine3.24@sha256:0178a641fbb4858c5f1b48e34bdaabe0350a330a1b1149aabd498d0699ff5fb2 AS builder

ARG TARGETOS
ARG TARGETARCH
ARG VERSION=dev
ARG COMMIT_SHA=unknown
ARG BUILD_DATE=unknown

WORKDIR /src

COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download

COPY . .
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
go build -tags=purego -trimpath -buildvcs=false \
-ldflags="-s -w -X 'main.version=$VERSION' -X 'main.commitSHA=$COMMIT_SHA' -X 'main.buildDate=$BUILD_DATE'" \
-o /out/archive-wrapper ./cmd/archive-wrapper && \
mkdir -p /out/rootfs/var/lib/archive-wrapper/data

FROM gcr.io/distroless/static-debian12:nonroot@sha256:f5b485ea962d9bd1186b2f6b3a061191539b905b82ec395de78cbfae51f20e35

ARG VERSION=dev
ARG COMMIT_SHA=unknown
ARG BUILD_DATE=unknown

LABEL org.opencontainers.image.title="archive-wrapper" \
org.opencontainers.image.description="Mina archive sidecar for Pulsar validators" \
org.opencontainers.image.source="https://github.com/node101-io/archive-wrapper" \
org.opencontainers.image.version=$VERSION \
org.opencontainers.image.revision=$COMMIT_SHA \
org.opencontainers.image.created=$BUILD_DATE

ENV ARCHIVE_WRAPPER_CONFIG=/etc/archive-wrapper/config.yaml \
ARCHIVE_WRAPPER_CHAIN_HOME=/var/lib/pulsar

COPY --from=builder --chown=65532:65532 /out/rootfs/var/lib/archive-wrapper /var/lib/archive-wrapper
COPY --from=builder --chown=65532:65532 /out/archive-wrapper /usr/local/bin/archive-wrapper

USER 65532:65532
EXPOSE 9095
STOPSIGNAL SIGTERM
HEALTHCHECK --interval=10s --timeout=5s --start-period=30s --retries=6 \
CMD ["/usr/local/bin/archive-wrapper", "healthcheck", "--timeout", "3s"]
ENTRYPOINT ["/usr/local/bin/archive-wrapper"]
CMD ["run"]
53 changes: 51 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
GO_BUILD_TAGS := purego
VERSION ?= dev
COMMIT_SHA ?= $(shell git rev-parse HEAD 2>/dev/null || printf unknown)
SOURCE_DATE_EPOCH ?= $(shell git show -s --format=%ct HEAD 2>/dev/null || printf 0)
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || printf unknown)
BUILD_LDFLAGS := -s -w -X 'main.version=$(VERSION)' -X 'main.commitSHA=$(COMMIT_SHA)' -X 'main.buildDate=$(BUILD_DATE)'

IMAGE ?= archive-wrapper:$(COMMIT_SHA)
DOCKER_PLATFORM ?= linux/amd64
DOCKER_PLATFORMS ?= linux/amd64,linux/arm64
OCI_OUTPUT ?= $(CURDIR)/.cache/archive-wrapper.oci.tar
DOCKER_BUILDER ?= archive-wrapper-builder
DOCKER_BUILD_ARGS := \
--build-arg VERSION=$(VERSION) \
--build-arg COMMIT_SHA=$(COMMIT_SHA) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH)

-include .env

Expand All @@ -12,13 +28,19 @@ export ARCHIVE_WRAPPER_GRPC_TRANSPORT_MODE
export ARCHIVE_WRAPPER_DB_PATH
export ARCHIVE_WRAPPER_CONTROL_SOCKET_PATH
export ARCHIVE_WRAPPER_LOG_PATH
export ARCHIVE_WRAPPER_HEALTHCHECK_ADDRESS
CONFIG ?= config.yaml

.PHONY: ensure-cache proto fmt test lint build run stop
.PHONY: ensure-cache ensure-docker-builder proto fmt test lint build run stop docker-build docker-build-multiarch docker-inspect docker-test reproducible-build reproducible-image

ensure-cache:
mkdir -p "$(GOCACHE)" "$(GOLANGCI_LINT_CACHE)"

ensure-docker-builder:
@docker buildx inspect $(DOCKER_BUILDER) >/dev/null 2>&1 || \
docker buildx create --name $(DOCKER_BUILDER) --driver docker-container
@docker buildx inspect --bootstrap $(DOCKER_BUILDER) >/dev/null

proto:
cd proto && buf generate --template buf.gen.gogo.yaml

Expand All @@ -33,7 +55,34 @@ lint: ensure-cache
golangci-lint run --build-tags=$(GO_BUILD_TAGS) ./...

build: ensure-cache
go build -tags=$(GO_BUILD_TAGS) -o archive-wrapper ./cmd/archive-wrapper
go build -tags=$(GO_BUILD_TAGS) -trimpath -buildvcs=false \
-ldflags="$(BUILD_LDFLAGS)" -o archive-wrapper ./cmd/archive-wrapper

docker-build: ensure-cache
docker buildx build --load --platform=$(DOCKER_PLATFORM) \
$(DOCKER_BUILD_ARGS) -t $(IMAGE) .

docker-build-multiarch: ensure-cache ensure-docker-builder
docker buildx build --builder=$(DOCKER_BUILDER) --platform=$(DOCKER_PLATFORMS) \
$(DOCKER_BUILD_ARGS) \
--provenance=false \
--output type=oci,dest=$(OCI_OUTPUT),rewrite-timestamp=true .

docker-inspect: docker-build
docker image inspect $(IMAGE) --format '{{json .Config}}'
@docker run --rm --entrypoint /usr/local/bin/archive-wrapper $(IMAGE) version

docker-test:
ARCHIVE_WRAPPER_IMAGE=$(IMAGE) ./scripts/test-container.sh

reproducible-build:
VERSION=$(VERSION) COMMIT_SHA=$(COMMIT_SHA) SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH) \
BUILD_DATE=$(BUILD_DATE) ./scripts/check-reproducible-build.sh

reproducible-image: ensure-cache ensure-docker-builder
VERSION=$(VERSION) COMMIT_SHA=$(COMMIT_SHA) SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH) \
BUILD_DATE=$(BUILD_DATE) DOCKER_BUILDER=$(DOCKER_BUILDER) \
DOCKER_PLATFORMS=$(DOCKER_PLATFORMS) ./scripts/check-reproducible-image.sh

run: build
@test -n "$(CONFIG)" || (echo "CONFIG is required" && exit 1)
Expand Down
Loading
Loading