Skip to content

Commit

Permalink
Merge pull request #1634 from aleskandro/multiarch-native-builds
Browse files Browse the repository at this point in the history
Native multi-arch ClusterBuildStrategy
  • Loading branch information
openshift-merge-bot[bot] authored Aug 4, 2024
2 parents e5a6321 + be5660b commit 78a3c7b
Show file tree
Hide file tree
Showing 11 changed files with 659 additions and 60 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ install-controller-kind: install-apis

.PHONY: install-strategies
install-strategies: install-apis
kubectl apply -R -f samples/v1beta1/buildstrategy/
[ -n "${TEST_NAMESPACE}" ] && ADDITIONAL_PARAMS="-n ${TEST_NAMESPACE}"; \
kubectl apply $$ADDITIONAL_PARAMS -R -f samples/v1beta1/buildstrategy/

.PHONY: local
local: install-strategies
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: multiarch-native-buildah-pipeline
rules:
- verbs:
- get
- list
- watch
resources:
- pods
apiGroups:
- ""
- verbs:
- create
resources:
- pods/exec
apiGroups:
- ""
- verbs:
- get
- list
- create
- watch
resources:
- jobs
apiGroups:
- batch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: multiarch-native-buildah-pipeline
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: multiarch-native-buildah-pipeline
subjects:
- kind: ServiceAccount
name: pipeline
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# NOTE: This is needed secifically in OKD/OpenShift environments.
# The pipeline service account should be allowed running pods that require
# the privileged SecurityContextConstraint.
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: multiarch-native-buildah-pipeline-scc-privileged
subjects:
- kind: ServiceAccount
name: pipeline
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: 'system:openshift:scc:privileged'
32 changes: 32 additions & 0 deletions test/data/v1beta1/build_multiarch_native_buildah_cr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: multiarch-native-buildah-ex
spec:
source:
type: Git
git:
url: https://github.com/shipwright-io/sample-go
contextDir: docker-build
strategy:
name: multiarch-native-buildah
kind: ClusterBuildStrategy
paramValues:
- name: architectures
values:
# Setting only to amd64 for the tests to run on amd64 only clusters
- value: "amd64"
- name: build-contexts
values:
- value: "ghcr.io/shipwright-io/shipwright-samples/golang:1.18=docker://ghcr.io/shipwright-io/shipwright-samples/golang:1.18"
# The buildah `--from` replaces the first FROM statement
- name: from
value: "" # Using the build-contexts for this example
# The runtime-stage-from implements the logic to replace the last stage FROM image of a Dockerfile
- name: runtime-stage-from
value: docker://gcr.io/distroless/static:nonroot
- name: dockerfile
value: Dockerfile
output:
image: image-registry.openshift-image-registry.svc:5000/build-examples/taxi-app
8 changes: 8 additions & 0 deletions test/data/v1beta1/buildrun_multiarch_native_buildah_cr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
apiVersion: shipwright.io/v1beta1
kind: BuildRun
metadata:
name: multiarch-native-buildah-ex
spec:
build:
name: multiarch-native-buildah-ex
16 changes: 0 additions & 16 deletions test/e2e/v1alpha1/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,10 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun
})

Context("when a heroku Buildpacks build is defined using a namespaced strategy", func() {
var buildStrategy *buildv1alpha1.BuildStrategy

BeforeEach(func() {
testID = generateTestID("buildpacks-v3-heroku-namespaced")

buildStrategy, err = buildStrategyTestData(testBuild.Namespace, "samples/v1alpha1/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3-heroku_namespaced_cr.yaml")
Expect(err).ToNot(HaveOccurred())

err = testBuild.CreateBuildStrategy(buildStrategy)
Expect(err).ToNot(HaveOccurred())

// create the build definition
build = createBuild(
testBuild,
Expand All @@ -169,7 +162,6 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun
})

AfterEach(func() {
err = testBuild.DeleteBuildStrategy(buildStrategy.Name)
Expect(err).ToNot(HaveOccurred())
})
})
Expand Down Expand Up @@ -198,17 +190,10 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun
})

Context("when a Buildpacks v3 build is defined using a namespaced strategy", func() {
var buildStrategy *buildv1alpha1.BuildStrategy

BeforeEach(func() {
testID = generateTestID("buildpacks-v3-namespaced")

buildStrategy, err = buildStrategyTestData(testBuild.Namespace, "samples/v1alpha1/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3_namespaced_cr.yaml")
Expect(err).ToNot(HaveOccurred())

err = testBuild.CreateBuildStrategy(buildStrategy)
Expect(err).ToNot(HaveOccurred())

// create the build definition
build = createBuild(
testBuild,
Expand All @@ -226,7 +211,6 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun
})

AfterEach(func() {
err = testBuild.DeleteBuildStrategy(buildStrategy.Name)
Expect(err).ToNot(HaveOccurred())
})
})
Expand Down
13 changes: 0 additions & 13 deletions test/e2e/v1alpha1/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,19 +292,6 @@ func readAndDecode(filePath string) (runtime.Object, error) {
return obj, err
}

// buildStrategyTestData gets the us the BuildStrategy test data set up
func buildStrategyTestData(ns string, buildStrategyCRPath string) (*buildv1alpha1.BuildStrategy, error) {
obj, err := readAndDecode(buildStrategyCRPath)
if err != nil {
return nil, err
}

buildStrategy := obj.(*buildv1alpha1.BuildStrategy)
buildStrategy.SetNamespace(ns)

return buildStrategy, err
}

func buildTestData(namespace string, identifier string, filePath string) (*buildv1alpha1.Build, error) {
obj, err := readAndDecode(filePath)
if err != nil {
Expand Down
36 changes: 19 additions & 17 deletions test/e2e/v1beta1/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,9 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun
})

Context("when a heroku Buildpacks build is defined using a namespaced strategy", func() {
var buildStrategy *buildv1beta1.BuildStrategy

BeforeEach(func() {
testID = generateTestID("buildpacks-v3-heroku-namespaced")

buildStrategy, err = buildStrategyTestData(testBuild.Namespace, "samples/v1beta1/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3-heroku_namespaced_cr.yaml")
Expect(err).ToNot(HaveOccurred())

err = testBuild.CreateBuildStrategy(buildStrategy)
Expect(err).ToNot(HaveOccurred())

// create the build definition
build = createBuild(
testBuild,
Expand All @@ -168,7 +160,6 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun
})

AfterEach(func() {
err = testBuild.DeleteBuildStrategy(buildStrategy.Name)
Expect(err).ToNot(HaveOccurred())
})
})
Expand Down Expand Up @@ -197,17 +188,10 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun
})

Context("when a Buildpacks v3 build is defined using a namespaced strategy", func() {
var buildStrategy *buildv1beta1.BuildStrategy

BeforeEach(func() {
testID = generateTestID("buildpacks-v3-namespaced")

buildStrategy, err = buildStrategyTestData(testBuild.Namespace, "samples/v1beta1/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3_namespaced_cr.yaml")
Expect(err).ToNot(HaveOccurred())

err = testBuild.CreateBuildStrategy(buildStrategy)
Expect(err).ToNot(HaveOccurred())

// create the build definition
build = createBuild(
testBuild,
Expand All @@ -225,7 +209,6 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun
})

AfterEach(func() {
err = testBuild.DeleteBuildStrategy(buildStrategy.Name)
Expect(err).ToNot(HaveOccurred())
})
})
Expand Down Expand Up @@ -475,6 +458,25 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun
})
})

Context("when a Multiarch Native Buildah build is defined", func() {

BeforeEach(func() {
testID = generateTestID("buildah-multi-arch-native")

// create the build definition
build = createBuild(
testBuild,
testID,
"test/data/v1beta1/build_multiarch_native_buildah_cr.yaml",
)
})

It("successfully runs a build", func() {
buildRun, err = buildRunTestData(testBuild.Namespace, testID, "test/data/v1beta1/buildrun_multiarch_native_buildah_cr.yaml")
Expect(err).ToNot(HaveOccurred())
buildRun = validateBuildRunToSucceed(testBuild, buildRun)
})
})
Context("when a s2i build is defined", func() {

BeforeEach(func() {
Expand Down
13 changes: 0 additions & 13 deletions test/e2e/v1beta1/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,19 +294,6 @@ func readAndDecode(filePath string) (runtime.Object, error) {
return obj, err
}

// buildStrategyTestData gets the us the BuildStrategy test data set up
func buildStrategyTestData(ns string, buildStrategyCRPath string) (*buildv1beta1.BuildStrategy, error) {
obj, err := readAndDecode(buildStrategyCRPath)
if err != nil {
return nil, err
}

buildStrategy := obj.(*buildv1beta1.BuildStrategy)
buildStrategy.SetNamespace(ns)

return buildStrategy, err
}

func buildTestData(namespace string, identifier string, filePath string) (*buildv1beta1.Build, error) {
obj, err := readAndDecode(filePath)
if err != nil {
Expand Down

0 comments on commit 78a3c7b

Please sign in to comment.