Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build multiarch images #215

Merged
merged 1 commit into from
Feb 18, 2025
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
143 changes: 121 additions & 22 deletions .github/workflows/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ env:
jobs:
build-and-push-image:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
permissions:
contents: read # for trivy scan upload
packages: write
Expand All @@ -27,9 +33,18 @@ jobs:
attestations: write

steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v4

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

- name: Log in to the Container registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
Expand Down Expand Up @@ -62,38 +77,40 @@ jobs:
run: go version
- name: Build it
id: go_build
run: make V=1

run: |
platform=${{ matrix.platform }}
echo "Building for $GOOS/$GOARCH"
make V=1 GOOS=${platform%/*} GOARCH=${platform#*/}
- name: Build and push Docker image
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991
id: docker_build_controller
uses: docker/build-push-action@v6
with:
file: Dockerfile.controller
context: .
push: true
visibility: public
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }}
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta_manager.outputs.labels }}
outputs: type=image,"name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}",push-by-digest=true,name-canonical=true,push=true
- name: Build and push Sidecar image
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991
id: docker_build_sidecar
with:
file: Dockerfile.sidecar
context: .
push: true
visibility: public
tags: ${{ env.REGISTRY }}/hyperspike/valkey-sidecar:${{ env.RELEASE_VERSION }}
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta_sidecar.outputs.labels }}
outputs: type=image,"name=${{ env.REGISTRY }}/hyperspike/valkey-sidecar",push-by-digest=true,name-canonical=true,push=true
- name: Build and push Valkey image
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991
id: docker_build_valkey
with:
file: Dockerfile.valkey
context: .
push: true
visibility: public
tags: ${{ env.REGISTRY }}/hyperspike/valkey:${{ env.VALKEY_VERSION }}
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta_valkey.outputs.labels }}
outputs: type=image,"name=${{ env.REGISTRY }}/hyperspike/valkey",push-by-digest=true,name-canonical=true,push=true

- name: Set up Cosign
uses: sigstore/cosign-installer@c56c2d3e59e4281cc41dea2217323ba5694b171e # v3.8.0
Expand Down Expand Up @@ -129,18 +146,100 @@ jobs:
subject-name: ${{ env.REGISTRY }}/hyperspike/valkey
subject-digest: ${{ steps.docker_build_valkey.outputs.digest }}
push-to-registry: true

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
- name: Export digest
run: |
mkdir -p ${{ runner.temp }}/digests/controller
mkdir -p ${{ runner.temp }}/digests/sidecar
mkdir -p ${{ runner.temp }}/digests/valkey
digest="${{ steps.docker_build_controller.outputs.digest }}"
touch "${{ runner.temp }}/digests/controller/${digest#sha256:}"
digest="${{ steps.docker_build_sidecar.outputs.digest }}"
touch "${{ runner.temp }}/digests/sidecar/${digest#sha256:}"
digest="${{ steps.docker_build_valkey.outputs.digest }}"
touch "${{ runner.temp }}/digests/valkey/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }}'
format: 'sarif'
output: 'trivy-results.sarif'
name: digests-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
merge:
runs-on: ubuntu-latest
needs:
- build-and-push-image
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-*
merge-multiple: true

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-results.sarif'
#env:
# GITHUB_TOKEN: ${{ secrets.TOKEN }}
- name: Log in to the Container registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

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

- name: Docker meta
id: meta_controller
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: ${{ env.RELEASE_VERSION }}
- name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
run: |
cd controller
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
- name: Docker meta
id: meta_sidecar
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/hyperspike/valkey-sidecar
tags: ${{ env.RELEASE_VERSION }}
- name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
run: |
cd sidecar
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY }}/hyperspike/valkey-sidecar@sha256:%s ' *)
- name: Docker meta
id: meta_valkey
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/hyperspike/valkey
tags: ${{ env.VALKEY_VERSION }}
- name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
run: |
cd valkey
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY }}/hyperspike/valkey@sha256:%s ' *)

- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta_controller.outputs.version }}
docker buildx imagetools inspect ${{ env.REGISTRY }}/hyperspike/valkey-sidecar:${{ steps.meta_sidecar.outputs.version }}
docker buildx imagetools inspect ${{ env.REGISTRY }}/hyperspike/valkey:${{ steps.meta_valkey.outputs.version }}

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }}'
format: 'sarif'
output: 'trivy-results.sarif'

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-results.sarif'
#env:
# GITHUB_TOKEN: ${{ secrets.TOKEN }}
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ VERSION ?= $(shell if [ ! -z $$(git tag --points-at HEAD) ] ; then git tag --po
DATE ?= $(shell date -u +'%Y%m%d')
SHA ?= $(shell git rev-parse --short HEAD)
PKG ?= hyperspike.io/valkey-operator
GOOS ?= linux
GOARCH ?= amd64

# CONTAINER_TOOL defines the container tool to be used for building images.
# Be aware that the target commands are only tested with Docker which is
Expand Down Expand Up @@ -107,7 +109,7 @@ gosec: gosec-bin ## Run gosec scanner
##@ Build

manager: manifests generate fmt vet ## Build manager binary.
$QCGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build $(VV) \
$QCGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) build $(VV) \
-trimpath \
-gcflags all="-N -l -trimpath=/src -trimpath=$(PWD)" \
-asmflags all="-trimpath=/src -trimpath=$(PWD)" \
Expand All @@ -117,7 +119,7 @@ manager: manifests generate fmt vet ## Build manager binary.
-o $@ ./cmd/manager/

sidecar: manifests generate fmt vet ## Build sidecar binary.
$QCGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build $(VV) \
$QCGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) build $(VV) \
-trimpath \
-gcflags all="-N -l -trimpath=/src -trimpath=$(PWD)" \
-asmflags all="-trimpath=/src -trimpath=$(PWD)" \
Expand Down Expand Up @@ -313,7 +315,7 @@ define go-install-tool
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
GOOS=linux GOARCH=amd64 GOBIN=$(LOCALBIN) go install $${package} ;\
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
}
endef
Loading