From 5451561c8e3d99a4b194c9b197dc8bd6fc5c28d1 Mon Sep 17 00:00:00 2001 From: Stefano Charissis Date: Thu, 6 Feb 2025 13:03:15 +1100 Subject: [PATCH] feat(nat): build & release docker images. (#162) * feat(nat): build & release docker images. --- .circleci/continue_config.yml | 21 ++++++- op-nat/.dockerignore | 8 +++ op-nat/.goreleaser.yaml | 58 +++++++++++++++++++ op-nat/Dockerfile | 6 +- op-nat/docker-compose.yml | 4 +- .../ci-docker-tag-op-stack-release.sh | 2 +- 6 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 op-nat/.dockerignore create mode 100644 op-nat/.goreleaser.yaml diff --git a/.circleci/continue_config.yml b/.circleci/continue_config.yml index 833d253b..a86f1889 100644 --- a/.circleci/continue_config.yml +++ b/.circleci/continue_config.yml @@ -96,6 +96,7 @@ jobs: echo "run-build-pms: << pipeline.parameters.run-build-pms >>" echo "run-build-op-ufm: << pipeline.parameters.run-build-op-ufm >>" echo "run-build-proxyd: << pipeline.parameters.run-build-proxyd >>" + echo "run-build-op-nat: << pipeline.parameters.run-build-op-nat >>" echo "run-all: << pipeline.parameters.run-all >>" echo "" echo "Pipeline Trigger Information:" @@ -141,6 +142,13 @@ jobs: else echo "op-ufm tag regex match: false" fi + + if [[ $CURRENT_TAG =~ ^op-nat/v.* ]]; then + echo "op-nat tag regex match: true" + else + echo "op-nat tag regex match: false" + fi + docker-build: environment: DOCKER_BUILDKIT: 1 @@ -521,19 +529,25 @@ workflows: - go-test: name: op-nat-tests module: op-nat + - docker-build: + name: op-nat-docker-build + docker_file: op-nat/Dockerfile + docker_name: op-nat + docker_tags: <>,<> + docker_context: . release: jobs: - log-config-results: filters: tags: - only: /^(cci-stats|peer-mgmt-service|proxyd|ufm-[a-z0-9\-]*|op-[a-z0-9\-]*)\/v.*/ + only: /^(op-nat|cci-stats|peer-mgmt-service|proxyd|ufm-[a-z0-9\-]*|op-[a-z0-9\-]*)\/v.*/ branches: ignore: /.*/ - hold: type: approval filters: tags: - only: /^(cci-stats|peer-mgmt-service|proxyd|ufm-[a-z0-9\-]*|op-[a-z0-9\-]*)\/v.*/ + only: /^(op-nat|cci-stats|peer-mgmt-service|proxyd|ufm-[a-z0-9\-]*|op-[a-z0-9\-]*)\/v.*/ branches: ignore: /.*/ - docker-build: @@ -547,6 +561,7 @@ workflows: - op-conductor-mon - peer-mgmt-service - cci-stats + - op-nat name: <>-docker-build filters: tags: @@ -569,6 +584,7 @@ workflows: - op-conductor-mon - peer-mgmt-service - cci-stats + - op-nat name: <>-docker-publish filters: tags: @@ -589,6 +605,7 @@ workflows: - op-conductor-mon - peer-mgmt-service - cci-stats + - op-nat name: <>-docker-tag filters: tags: diff --git a/op-nat/.dockerignore b/op-nat/.dockerignore new file mode 100644 index 00000000..8d8ed935 --- /dev/null +++ b/op-nat/.dockerignore @@ -0,0 +1,8 @@ +.git +.gitignore +README.md +Dockerfile +*.md +*.log +bin/ +tmp/ \ No newline at end of file diff --git a/op-nat/.goreleaser.yaml b/op-nat/.goreleaser.yaml new file mode 100644 index 00000000..876e2d11 --- /dev/null +++ b/op-nat/.goreleaser.yaml @@ -0,0 +1,58 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema-pro.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 2 + +project_name: op-nat + +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + +builds: + - id: main + main: ./cmd/main + binary: bin/op-nat + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + ignore: + - goos: windows + goarch: arm64 + - goos: linux + goarch: arm64 + mod_timestamp: "{{ .CommitTimestamp }}" + ldflags: + - -X main.GitCommit={{ .FullCommit }} + - -X main.GitDate={{ .CommitDate }} + - -X main.Version={{ .Version }} + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: "{{ .ProjectName }}-{{.Version}}-{{ tolower .Os }}-{{ .Arch }}" + # use zip for windows archives + wrap_in_directory: true + format_overrides: + - goos: windows + format: zip + +changelog: + sort: asc + +release: + github: + owner: ethereum-optimism + name: infra + make_latest: false + +monorepo: + tag_prefix: op-nat/ + dir: op-nat diff --git a/op-nat/Dockerfile b/op-nat/Dockerfile index e6dd1d2f..40665281 100644 --- a/op-nat/Dockerfile +++ b/op-nat/Dockerfile @@ -1,8 +1,12 @@ FROM golang:1.23.5-alpine3.21 AS builder WORKDIR /app -COPY . . + +# Install dependencies first for better caching RUN apk add --no-cache just + +COPY op-nat/ . + RUN just build FROM alpine:3.21 diff --git a/op-nat/docker-compose.yml b/op-nat/docker-compose.yml index 57d1b978..f540f1a7 100644 --- a/op-nat/docker-compose.yml +++ b/op-nat/docker-compose.yml @@ -27,7 +27,9 @@ services: op-nat: container_name: op-nat - build: . + build: + context: .. + dockerfile: op-nat/Dockerfile volumes: - ./devnets:/devnets command: ["--kurtosis.devnet.manifest", "/devnets/simple-devnet.json"] diff --git a/ops/ci-tag-docker-release/ci-docker-tag-op-stack-release.sh b/ops/ci-tag-docker-release/ci-docker-tag-op-stack-release.sh index c18a8fb0..2baac4a5 100755 --- a/ops/ci-tag-docker-release/ci-docker-tag-op-stack-release.sh +++ b/ops/ci-tag-docker-release/ci-docker-tag-op-stack-release.sh @@ -6,7 +6,7 @@ DOCKER_REPO=$1 GIT_TAG=$2 GIT_SHA=$3 -IMAGE_NAME=$(echo "$GIT_TAG" | grep -Eow '^(cci-stats|peer-mgmt-service|proxyd|ufm-[a-z0-9\-]*|op-[a-z0-9\-]*)' || true) +IMAGE_NAME=$(echo "$GIT_TAG" | grep -Eow '^(op-nat|cci-stats|peer-mgmt-service|proxyd|ufm-[a-z0-9\-]*|op-[a-z0-9\-]*)' || true) if [ -z "$IMAGE_NAME" ]; then echo "image name could not be parsed from git tag '$GIT_TAG'" exit 1