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(scorecard): update multiarch build steps #610

Merged
merged 12 commits into from
Aug 25, 2023
9 changes: 2 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,13 @@ jobs:
- uses: jpkrohling/setup-operator-sdk@v1.1.0
with:
operator-sdk-version: v1.28.0
- name: Install qemu
continue-on-error: false
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- name: Build scorecard image for test
id: build-scorecard
run: |
CUSTOM_SCORECARD_IMG=ghcr.io/${{ github.repository_owner }}/cryostat-operator-scorecard:ci-$GITHUB_SHA \
PLATFORMS=${{ env.CI_PLATFORMS }} \
PLATFORMS=linux/amd64 \
MANIFEST_PUSH=false \
make scorecard-build
make scorecard-build
echo "tag=ci-$GITHUB_SHA" >> $GITHUB_OUTPUT
- name: Push scorecard image to ghcr.io for test
id: push-scorecard-to-ghcr
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -279,26 +279,26 @@ oci-build: manifests generate fmt vet test-envtest
# To properly provided solutions that supports more than one platform you should use this option.
.PHONY: oci-buildx
oci-buildx: manifests generate fmt vet test-envtest ## Build OCI image for the manager for cross-platform support
ifeq ($(IMAGE_BUILDER), docker)
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
ifeq ($(IMAGE_BUILDER), docker)
- $(IMAGE_BUILDER) buildx create --name project-v3-builder
$(IMAGE_BUILDER) buildx use project-v3-builder
- $(IMAGE_BUILDER) buildx build --push --platform=$(PLATFORMS) --tag $(OPERATOR_IMG) -f Dockerfile.cross .
- $(IMAGE_BUILDER) buildx rm project-v3-builder
rm Dockerfile.cross
else ifeq ($(IMAGE_BUILDER), podman)
for platform in $$(echo $(PLATFORMS) | sed "s/,/ /g"); do \
os=$$(echo $${platform} | cut -d/ -f 1); \
arch=$$(echo $${platform} | cut -d/ -f 2); \
BUILDAH_FORMAT=docker $(IMAGE_BUILDER) buildx build --manifest $(OPERATOR_IMG) --platform $${platform} --build-arg TARGETOS=$${os} --build-arg TARGETARCH=$${arch} . ; \
BUILDAH_FORMAT=docker $(IMAGE_BUILDER) buildx build -f Dockerfile.cross --manifest $(OPERATOR_IMG) --platform $${platform} --build-arg TARGETOS=$${os} --build-arg TARGETARCH=$${arch} . ; \
tthvo marked this conversation as resolved.
Show resolved Hide resolved
done
if [ "${MANIFEST_PUSH}" = "true" ] ; then \
$(IMAGE_BUILDER) manifest push $(OPERATOR_IMG) $(OPERATOR_IMG) ; \
fi
else
$(error unsupported IMAGE_BUILDER: $(IMAGE_BUILDER))
endif
rm Dockerfile.cross

.PHONY: cert_manager
cert_manager: remove_cert_manager
Expand Down Expand Up @@ -440,26 +440,26 @@ custom-scorecard-tests: fmt vet
scorecard-build: custom-scorecard-tests
printf '# Code generated by hack/custom.config.yaml.in. DO NOT EDIT.\n' > config/scorecard/patches/custom.config.yaml
envsubst < hack/custom.config.yaml.in >> config/scorecard/patches/custom.config.yaml
ifeq ($(IMAGE_BUILDER), docker)
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' internal/images/custom-scorecard-tests/Dockerfile > internal/images/custom-scorecard-tests/Dockerfile.cross
ifeq ($(IMAGE_BUILDER), docker)
- $(IMAGE_BUILDER) buildx create --name project-v3-builder
$(IMAGE_BUILDER) buildx use project-v3-builder
- $(IMAGE_BUILDER) buildx build --push --platform=$(PLATFORMS) --tag $(CUSTOM_SCORECARD_IMG) -f internal/images/custom-scorecard-tests/Dockerfile.cross .
- $(IMAGE_BUILDER) buildx rm project-v3-builder
rm internal/images/custom-scorecard-tests/Dockerfile.cross
else ifeq ($(IMAGE_BUILDER), podman)
for platform in $$(echo $(PLATFORMS) | sed "s/,/ /g"); do \
os=$$(echo $${platform} | cut -d/ -f 1); \
arch=$$(echo $${platform} | cut -d/ -f 2); \
BUILDAH_FORMAT=docker $(IMAGE_BUILDER) buildx build --manifest $(CUSTOM_SCORECARD_IMG) --platform $${platform} --build-arg TARGETOS=$${os} --build-arg TARGETARCH=$${arch} . ; \
BUILDAH_FORMAT=docker $(IMAGE_BUILDER) buildx build -f internal/images/custom-scorecard-tests/Dockerfile.cross --manifest $(CUSTOM_SCORECARD_IMG) --platform $${platform} --build-arg TARGETOS=$${os} --build-arg TARGETARCH=$${arch} . ; \
done
if [ "${MANIFEST_PUSH}" = "true" ] ; then \
$(IMAGE_BUILDER) manifest push $(CUSTOM_SCORECARD_IMG) $(CUSTOM_SCORECARD_IMG) ; \
fi
else
$(error unsupported IMAGE_BUILDER: $(IMAGE_BUILDER))
endif
rm internal/images/custom-scorecard-tests/Dockerfile.cross

# Local development/testing helpers
ifneq ($(origin SAMPLE_APP_NAMESPACE), undefined)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ metadata:
capabilities: Seamless Upgrades
categories: Monitoring, Developer Tools
containerImage: quay.io/cryostat/cryostat-operator:2.4.0-dev
createdAt: "2023-08-16T19:16:28Z"
createdAt: "2023-08-24T00:50:46Z"
description: JVM monitoring and profiling tool
operatorframework.io/initialization-resource: |-
{
Expand Down
4 changes: 2 additions & 2 deletions bundle/tests/scorecard/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ stages:
- entrypoint:
- cryostat-scorecard-tests
- operator-install
image: quay.io/cryostat/cryostat-operator-scorecard:2.4.0-20230816190348
image: quay.io/cryostat/cryostat-operator-scorecard:2.4.0-20230824004852
labels:
suite: cryostat
test: operator-install
Expand All @@ -79,7 +79,7 @@ stages:
- entrypoint:
- cryostat-scorecard-tests
- cryostat-cr
image: quay.io/cryostat/cryostat-operator-scorecard:2.4.0-20230816190348
image: quay.io/cryostat/cryostat-operator-scorecard:2.4.0-20230824004852
labels:
suite: cryostat
test: cryostat-cr
Expand Down
4 changes: 2 additions & 2 deletions config/scorecard/patches/custom.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
entrypoint:
- cryostat-scorecard-tests
- operator-install
image: "quay.io/cryostat/cryostat-operator-scorecard:2.4.0-20230816190348"
image: "quay.io/cryostat/cryostat-operator-scorecard:2.4.0-20230824004852"
labels:
suite: cryostat
test: operator-install
Expand All @@ -18,7 +18,7 @@
entrypoint:
- cryostat-scorecard-tests
- cryostat-cr
image: "quay.io/cryostat/cryostat-operator-scorecard:2.4.0-20230816190348"
image: "quay.io/cryostat/cryostat-operator-scorecard:2.4.0-20230824004852"
labels:
suite: cryostat
test: cryostat-cr
4 changes: 3 additions & 1 deletion internal/images/custom-scorecard-tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

# Build the manager binary
FROM docker.io/library/golang:1.20 as builder
ARG TARGETOS
ARG TARGETARCH

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -29,7 +31,7 @@ COPY internal/images/custom-scorecard-tests/main.go internal/images/custom-score
COPY internal/test/scorecard/ internal/test/scorecard/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o cryostat-scorecard-tests \
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} GO111MODULE=on go build -a -o cryostat-scorecard-tests \
internal/images/custom-scorecard-tests/main.go

FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
Expand Down
Loading