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

Multiarch builds #145

Merged
merged 5 commits into from
Nov 6, 2023
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
2 changes: 1 addition & 1 deletion Dockerfile.base
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM registry.access.redhat.com/ubi8/go-toolset:1.19.10-10 as builder
FROM registry.access.redhat.com/ubi8/go-toolset:1.19.13-2.1698062273 as builder

WORKDIR /workspace

Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile.pr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.access.redhat.com/ubi8/go-toolset:1.19.9-2.1687187497
FROM registry.access.redhat.com/ubi8/go-toolset:1.19.13-2.1698062273
USER 0
RUN dnf install -y openssh-clients git podman make which go jq python3
RUN mkdir /root/go -p
Expand Down
9 changes: 1 addition & 8 deletions build_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,4 @@ if [[ "$VALID_TAGS_LENGTH" -eq 0 ]]; then
fi
#### End

docker --config="$DOCKER_CONF" build --platform linux/amd64 --build-arg BASE_IMAGE="$BASE_IMG" --build-arg GOARCH="amd64" -t "${IMAGE}:${IMAGE_TAG}-amd64" --push .
docker --config="$DOCKER_CONF" build --platform linux/arm64 --build-arg BASE_IMAGE="$BASE_IMG" --build-arg GOARCH="arm64" -t "${IMAGE}:${IMAGE_TAG}-arm64" --push .

docker --config="$DOCKER_CONF" manifest create "${IMAGE}:${IMAGE_TAG}" \
"${IMAGE}:${IMAGE_TAG}-amd64" \
"${IMAGE}:${IMAGE_TAG}-arm64"

docker --config="$DOCKER_CONF" manifest push "${IMAGE}:${IMAGE_TAG}"
docker --config="$DOCKER_CONF" buildx build --platform linux/amd64,linux/arm64 --build-arg BASE_IMAGE="$BASE_IMG" -t "${IMAGE}:${IMAGE_TAG}" --push .
212 changes: 106 additions & 106 deletions controllers/frontend_controller_suite_test.go

Large diffs are not rendered by default.

54 changes: 19 additions & 35 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
/*
Copyright 2021 RedHatInsights.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package controllers

import (
"context"
"path/filepath"
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
prom "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -50,19 +34,19 @@ var stopController context.CancelFunc
var MonitoringNamespace = "openshift-customer-monitoring"

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)
gomega.RegisterFailHandler(ginkgo.Fail)

RunSpecs(t, "Controller Suite")
ginkgo.RunSpecs(t, "Controller Suite")
}

var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
var _ = ginkgo.BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(ginkgo.GinkgoWriter), zap.UseDevMode(true)))
k8sscheme := runtime.NewScheme()
utilruntime.Must(clientgoscheme.AddToScheme(k8sscheme))
utilruntime.Must(prom.AddToScheme(k8sscheme))
utilruntime.Must(networking.AddToScheme(k8sscheme))

By("bootstrapping test environment")
ginkgo.By("bootstrapping test environment")
// Here be dragons: env-test does not play nice with third party CRDs
// https://github.com/kubernetes-sigs/controller-runtime/issues/1191#issuecomment-833058115
testEnv = &envtest.Environment{
Expand All @@ -75,29 +59,29 @@ var _ = BeforeSuite(func() {
}

cfg, err := testEnv.Start()
Expect(err).NotTo(HaveOccurred())
Expect(cfg).NotTo(BeNil())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(cfg).NotTo(gomega.BeNil())

err = crd.AddToScheme(k8sscheme)
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())

//+kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: k8sscheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(k8sClient).NotTo(gomega.BeNil())

k8sManager, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: k8sscheme,
})
Expect(err).ToNot(HaveOccurred())
gomega.Expect(err).ToNot(gomega.HaveOccurred())

err = (&FrontendReconciler{
Client: k8sManager.GetClient(),
Scheme: k8sManager.GetScheme(),
Log: ctrl.Log.WithName("controllers").WithName("CronJob"),
}).SetupWithManager(k8sManager)
Expect(err).ToNot(HaveOccurred())
gomega.Expect(err).ToNot(gomega.HaveOccurred())

ctx, cancel := context.WithCancel(context.Background())
stopController = cancel
Expand All @@ -107,18 +91,18 @@ var _ = BeforeSuite(func() {
Name: MonitoringNamespace,
},
}
Expect(k8sClient.Create(ctx, &monitorNs)).Should(Succeed())
gomega.Expect(k8sClient.Create(ctx, &monitorNs)).Should(gomega.Succeed())

go func() {
err = k8sManager.Start(ctx)
Expect(err).ToNot(HaveOccurred())
gomega.Expect(err).ToNot(gomega.HaveOccurred())
}()

}, 60)

var _ = AfterSuite(func() {
By("tearing down the test environment")
var _ = ginkgo.AfterSuite(func() {
ginkgo.By("tearing down the test environment")
stopController()
err := testEnv.Stop()
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})
34 changes: 17 additions & 17 deletions controllers/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package utils
import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
)

func TestCamelCase(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Camel Case Conversion")
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "Camel Case Conversion")

}

var _ = Describe("Camel Case Conversion", func() {
var _ = ginkgo.Describe("Camel Case Conversion", func() {
const (
singleName = "inventory"
dashName = "hac-core"
Expand All @@ -22,24 +22,24 @@ var _ = Describe("Camel Case Conversion", func() {
tripleCamelHump = "frontendTestName"
)

Context("When creating a fed-modules entry", func() {
It("Should convert a dash separated name", func() {
By("Using the ToCamelCase method")
Expect(ToCamelCase(dashName)).Should(Equal(camelName))
ginkgo.Context("When creating a fed-modules entry", func() {
ginkgo.It("Should convert a dash separated name", func() {
ginkgo.By("Using the ToCamelCase method")
gomega.Expect(ToCamelCase(dashName)).Should(gomega.Equal(camelName))
})
})

Context("When creating a fed-modules entry", func() {
It("Should convert dash case to camel case for n dashes", func() {
By("Using the ToCamelCase method")
Expect(ToCamelCase(tripleDash)).Should(Equal(tripleCamelHump))
ginkgo.Context("When creating a fed-modules entry", func() {
ginkgo.It("Should convert dash case to camel case for n dashes", func() {
ginkgo.By("Using the ToCamelCase method")
gomega.Expect(ToCamelCase(tripleDash)).Should(gomega.Equal(tripleCamelHump))
})
})

Context("When creating a fed-modules entry", func() {
It("Should not convert a single word", func() {
By("Using the ToCamelCase method")
Expect(ToCamelCase(singleName)).Should(Equal(singleName))
ginkgo.Context("When creating a fed-modules entry", func() {
ginkgo.It("Should not convert a single word", func() {
ginkgo.By("Using the ToCamelCase method")
gomega.Expect(ToCamelCase(singleName)).Should(gomega.Equal(singleName))
})
})

Expand Down
3 changes: 2 additions & 1 deletion pr_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ docker rm -f $CONTAINER_NAME-run
# This confused me for a while because pr_check_inner.sh is also copied into the pr check container at build time
# but the template_check.sh isn't. I couldn't figure out how it was sourcing it

docker build -t $CONTAINER_NAME -f build/Dockerfile.pr .
docker buildx build --platform linux/amd64,linux/arm64 -t $CONTAINER_NAME -f build/Dockerfile.pr .
docker buildx build --load -t $CONTAINER_NAME -f build/Dockerfile.pr .

docker run -i --name $CONTAINER_NAME-run -v $PWD:/workspace:ro $CONTAINER_NAME /workspace/build/pr_check_inner.sh

Expand Down
Loading