Skip to content

Commit

Permalink
Merge pull request #326 from pjbgf/publish-image-gha
Browse files Browse the repository at this point in the history
Publish Prime images using ecm-distro-tools GHA
  • Loading branch information
pjbgf authored Aug 1, 2024
2 parents 69d20ce + da3d28a commit 758ba25
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 31 deletions.
69 changes: 44 additions & 25 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,61 @@ on:
tags:
- 'v*'

permissions:
contents: write # Upload artefacts to release.
id-token: write # required by read-vault-secrets.

jobs:

publish-public:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
# write is needed for:
# - OIDC for cosign's use in ecm-distro-tools/publish-image.
# - Read vault secrets in rancher-eio/read-vault-secrets.
id-token: write

strategy:
matrix:
include:
# Three images are created:
# - Multi-arch manifest for both amd64 and arm64
- tag-suffix: ""
platforms: linux/amd64,linux/arm64
# - arm64 manifest
- tag-suffix: "-arm64"
platforms: linux/arm64
# - amd64 manifest
- tag-suffix: "-amd64"
platforms: linux/amd64

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Load Secrets from Vault
uses: rancher-eio/read-vault-secrets@main
with:
secrets: |
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ;
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_PASSWORD
- name: Login to Docker Hub
uses: docker/login-action@v3
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_PASSWORD ;
secret/data/github/repo/${{ github.repository }}/rancher-prime-registry/credentials registry | PRIME_REGISTRY ;
secret/data/github/repo/${{ github.repository }}/rancher-prime-registry/credentials username | PRIME_REGISTRY_USERNAME ;
secret/data/github/repo/${{ github.repository }}/rancher-prime-registry/credentials password | PRIME_REGISTRY_PASSWORD
- name: Publish manifest
uses: rancher/ecm-distro-tools/actions/publish-image@master
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PASSWORD }}
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Checkout code
uses: actions/checkout@v4

- name: Build and push all image variations
run: |
make image-push
TAG="${TAG}-amd64" TARGET_PLATFORMS=linux/amd64 make image-push
TAG="${TAG}-arm64" TARGET_PLATFORMS=linux/arm64 make image-push
env:
TAG: ${{ github.ref_name }}
REPO: ${{ vars.PUBLIC_REGISTRY }}/${{ vars.PUBLIC_REGISTRY_REPO }}
image: cis-operator
tag: ${{ github.ref_name }}${{ matrix.tag-suffix }}
platforms: ${{ matrix.platforms }}

public-registry: docker.io
public-repo: rancher
public-username: ${{ env.DOCKER_USERNAME }}
public-password: ${{ env.DOCKER_PASSWORD }}

prime-registry: ${{ env.PRIME_REGISTRY }}
prime-repo: rancher
prime-username: ${{ env.PRIME_REGISTRY_USERNAME }}
prime-password: ${{ env.PRIME_REGISTRY_PASSWORD }}

- run: make upload
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
uses: actions/checkout@v4

- name: Test building images
run: make test-build
run: make test-image

- name: E2E Tests
run: make e2e
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ test: ## run unit tests.
build: ## build project and output binary to TARGET_BIN.
CGO_ENABLED=0 $(GO) build -trimpath -tags "$(GO_TAGS)" -ldflags "$(LINKFLAGS)" -o $(TARGET_BIN)

test-build:
test-image:
# Instead of loading image, target all platforms, effectivelly testing
# the build for the target architectures.
$(MAKE) image-build BUILD_ACTION="--platform=$(TARGET_PLATFORMS)"
$(MAKE) build-image BUILD_ACTION="--platform=$(TARGET_PLATFORMS)"

image-build: buildx-machine ## build (and load) the container image targeting the current platform.
build-image: buildx-machine ## build (and load) the container image targeting the current platform.
$(IMAGE_BUILDER) build -f package/Dockerfile \
--builder $(MACHINE) $(IMAGE_ARGS) \
--build-arg VERSION=$(VERSION) -t "$(IMAGE)" $(BUILD_ACTION) .
@echo "Built $(IMAGE)"

image-push: buildx-machine ## build the container image targeting all platforms defined by TARGET_PLATFORMS and push to a registry.
push-image: buildx-machine ## build the container image targeting all platforms defined by TARGET_PLATFORMS and push to a registry.
$(IMAGE_BUILDER) build -f package/Dockerfile \
--builder $(MACHINE) $(IMAGE_ARGS) $(IID_FILE_FLAG) $(BUILDX_ARGS) \
--build-arg VERSION=$(VERSION) --platform=$(TARGET_PLATFORMS) -t "$(IMAGE)" --push .
@echo "Pushed $(IMAGE)"

e2e: $(K3D) $(KUBECTL) image-build ## Run E2E tests.
e2e: $(K3D) $(KUBECTL) build-image ## Run E2E tests.
K3D=$(K3D) KUBECTL=$(KUBECTL) VERSION=$(VERSION) \
IMAGE=$(IMAGE) SECURITY_SCAN_VERSION=$(SECURITY_SCAN_VERSION) \
SONOBUOY_VERSION=$(SONOBUOY_VERSION) CORE_DNS_VERSION=$(CORE_DNS_VERSION) \
Expand Down
1 change: 1 addition & 0 deletions hack/make/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ endif
RUNNER := docker
IMAGE_BUILDER := $(RUNNER) buildx
MACHINE := rancher
BUILDX_ARGS ?= --sbom=true --attest type=provenance,mode=max

ifeq ($(TAG),)
TAG = $(VERSION)
Expand Down

0 comments on commit 758ba25

Please sign in to comment.