Skip to content

Commit

Permalink
switching to a multi-stage build
Browse files Browse the repository at this point in the history
Signed-off-by: Adam D. Cornett <[email protected]>
  • Loading branch information
acornett21 committed Oct 8, 2024
1 parent 36380eb commit a4dd600
Show file tree
Hide file tree
Showing 16 changed files with 769 additions and 92 deletions.
6 changes: 3 additions & 3 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ $(GOLANGCI_LINT): $(BINGO_DIR)/golangci-lint.mod
@echo "(re)installing $(GOBIN)/golangci-lint-v1.55.2"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.55.2 "github.com/golangci/golangci-lint/cmd/golangci-lint"

GORELEASER := $(GOBIN)/goreleaser-v1.16.2
GORELEASER := $(GOBIN)/goreleaser-v1.26.2
$(GORELEASER): $(BINGO_DIR)/goreleaser.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/goreleaser-v1.16.2"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=goreleaser.mod -o=$(GOBIN)/goreleaser-v1.16.2 "github.com/goreleaser/goreleaser"
@echo "(re)installing $(GOBIN)/goreleaser-v1.26.2"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=goreleaser.mod -o=$(GOBIN)/goreleaser-v1.26.2 "github.com/goreleaser/goreleaser"

KIND := $(GOBIN)/kind-v0.20.0
$(KIND): $(BINGO_DIR)/kind.mod
Expand Down
6 changes: 4 additions & 2 deletions .bingo/goreleaser.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.21.3
go 1.22

require github.com/goreleaser/goreleaser v1.16.2
toolchain go1.22.5

require github.com/goreleaser/goreleaser v1.26.2
495 changes: 495 additions & 0 deletions .bingo/goreleaser.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .bingo/variables.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ BINGO="${GOBIN}/bingo-v0.9.0"

GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.55.2"

GORELEASER="${GOBIN}/goreleaser-v1.16.2"
GORELEASER="${GOBIN}/goreleaser-v1.26.2"

KIND="${GOBIN}/kind-v0.20.0"

Expand Down
94 changes: 93 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,107 @@ on:
- main

jobs:
release-architectures:
strategy:
matrix:
arch: [amd64, arm64, ppc64le, s390x]
name: release-${{ matrix.arch }}
runs-on: ubuntu-24.04
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Docker Login
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set the release related variables
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
# Release tags.
echo IMAGE_TAG="${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo GORELEASER_ARGS="--clean --timeout=120m" >> $GITHUB_ENV
echo ENABLE_RELEASE_PIPELINE=true >> $GITHUB_ENV
elif [[ $GITHUB_REF == refs/heads/* ]]; then
# Branch build.
echo IMAGE_TAG="$(echo "${GITHUB_REF#refs/heads/}" | sed -r 's|/+|-|g')" >> $GITHUB_ENV
echo GORELEASER_ARGS="--clean --skip-validate --timeout=120m" >> $GITHUB_ENV
elif [[ $GITHUB_REF == refs/pull/* ]]; then
# PR build.
echo IMAGE_TAG="pr-$(echo "${GITHUB_REF}" | sed -E 's|refs/pull/([^/]+)/?.*|\1|')" >> $GITHUB_ENV
else
echo IMAGE_TAG="$(git describe --tags --always)" >> $GITHUB_ENV
fi
- name: Run goreleaser
run: make release-arch-${{ matrix.arch }}
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Move Binary
run: |
mkdir -p dist-cache
mv dist/ansible-operator dist-cache/ansible-operator_linux_${{ matrix.arch }}
- name: Save binary
uses: actions/cache/save@v4
with:
path: dist-cache/ansible-operator_linux_${{ matrix.arch }}
key: ${{ matrix.arch }}-${{ github.sha }}


goreleaser:
name: goreleaser
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
needs: release-architectures
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Restore amd64 binary
uses: actions/cache/restore@v4
with:
path: dist-cache/ansible-operator_linux_amd64
key: amd64-${{ github.sha }}
fail-on-cache-miss: true

- name: Restore arm64 binary
uses: actions/cache/restore@v4
with:
path: dist-cache/ansible-operator_linux_arm64
key: arm64-${{ github.sha }}
fail-on-cache-miss: true

- name: Restore ppc64le binary
uses: actions/cache/restore@v4
with:
path: dist-cache/ansible-operator_linux_ppc64le
key: ppc64le-${{ github.sha }}
fail-on-cache-miss: true

- name: Restore s390x binary
uses: actions/cache/restore@v4
with:
path: dist-cache/ansible-operator_linux_s390x
key: s390x-${{ github.sha }}
fail-on-cache-miss: true

- name: Install Go
uses: actions/setup-go@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
jobs:
e2e:
name: e2e
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
jobs:
sanity:
name: sanity
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
jobs:
unit:
name: unit
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
with:
Expand Down
34 changes: 34 additions & 0 deletions .goreleaser.amd64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
before:
hooks:
- go mod tidy
- go mod download
builds:
- id: binary
main: ./cmd/ansible-operator/
binary: ansible-operator
asmflags: "{{ .Env.GO_BUILD_ASMFLAGS }}"
gcflags: "{{ .Env.GO_BUILD_GCFLAGS }}"
ldflags: "{{ .Env.GO_BUILD_LDFLAGS }}"
mod_timestamp: "{{ .CommitTimestamp }}"
no_unique_dist_dir: true
goos:
- linux
goarch:
- amd64
dockers:
- image_templates:
- "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-amd64"
dockerfile: images/ansible-operator/Dockerfile
goos: linux
goarch: amd64
use: buildx
build_flag_templates:
- "--platform=linux/amd64"
extra_files:
- "images/ansible-operator/Pipfile"
- "images/ansible-operator/Pipfile.lock"
archives:
- format: binary
name_template: "{{ .Binary }}_{{ .Os }}_{{ .Arch }}"
release:
disable: true
34 changes: 34 additions & 0 deletions .goreleaser.arm64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
before:
hooks:
- go mod tidy
- go mod download
builds:
- id: binary
main: ./cmd/ansible-operator/
binary: ansible-operator
asmflags: "{{ .Env.GO_BUILD_ASMFLAGS }}"
gcflags: "{{ .Env.GO_BUILD_GCFLAGS }}"
ldflags: "{{ .Env.GO_BUILD_LDFLAGS }}"
mod_timestamp: "{{ .CommitTimestamp }}"
no_unique_dist_dir: true
goos:
- linux
goarch:
- arm64
dockers:
- image_templates:
- "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-arm64"
dockerfile: images/ansible-operator/Dockerfile
goos: linux
goarch: arm64
use: buildx
build_flag_templates:
- "--platform=linux/arm64"
extra_files:
- "images/ansible-operator/Pipfile"
- "images/ansible-operator/Pipfile.lock"
archives:
- format: binary
name_template: "{{ .Binary }}_{{ .Os }}_{{ .Arch }}"
release:
disable: true
19 changes: 19 additions & 0 deletions .goreleaser.manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
builds:
- skip: true
docker_manifests:
- name_template: "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}"
image_templates:
- "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-amd64"
- "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-arm64"
- "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-ppc64le"
- "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-s390x"
changelog:
use: github-native
skip: '{{ ne .Env.ENABLE_RELEASE_PIPELINE "true" }}'
release:
disable: '{{ ne .Env.ENABLE_RELEASE_PIPELINE "true" }}'
extra_files:
- glob: ./dist-cache/ansible-operator_linux_amd64
- glob: ./dist-cache/ansible-operator_linux_arm64
- glob: ./dist-cache/ansible-operator_linux_ppc64le
- glob: ./dist-cache/ansible-operator_linux_s390x
34 changes: 34 additions & 0 deletions .goreleaser.ppc64le.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
before:
hooks:
- go mod tidy
- go mod download
builds:
- id: binary
main: ./cmd/ansible-operator/
binary: ansible-operator
asmflags: "{{ .Env.GO_BUILD_ASMFLAGS }}"
gcflags: "{{ .Env.GO_BUILD_GCFLAGS }}"
ldflags: "{{ .Env.GO_BUILD_LDFLAGS }}"
mod_timestamp: "{{ .CommitTimestamp }}"
no_unique_dist_dir: true
goos:
- linux
goarch:
- ppc64le
dockers:
- image_templates:
- "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-ppc64le"
dockerfile: images/ansible-operator/Dockerfile
goos: linux
goarch: ppc64le
use: buildx
build_flag_templates:
- "--platform=linux/ppc64le"
extra_files:
- "images/ansible-operator/Pipfile"
- "images/ansible-operator/Pipfile.lock"
archives:
- format: binary
name_template: "{{ .Binary }}_{{ .Os }}_{{ .Arch }}"
release:
disable: true
34 changes: 34 additions & 0 deletions .goreleaser.s390x.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
before:
hooks:
- go mod tidy
- go mod download
builds:
- id: binary
main: ./cmd/ansible-operator/
binary: ansible-operator
asmflags: "{{ .Env.GO_BUILD_ASMFLAGS }}"
gcflags: "{{ .Env.GO_BUILD_GCFLAGS }}"
ldflags: "{{ .Env.GO_BUILD_LDFLAGS }}"
mod_timestamp: "{{ .CommitTimestamp }}"
no_unique_dist_dir: true
goos:
- linux
goarch:
- s390x
dockers:
- image_templates:
- "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-s390x"
dockerfile: images/ansible-operator/Dockerfile
goos: linux
goarch: s390x
use: buildx
build_flag_templates:
- "--platform=linux/s390x"
extra_files:
- "images/ansible-operator/Pipfile"
- "images/ansible-operator/Pipfile.lock"
archives:
- format: binary
name_template: "{{ .Binary }}_{{ .Os }}_{{ .Arch }}"
release:
disable: true
Loading

0 comments on commit a4dd600

Please sign in to comment.