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

MultiArchitecture support #3309

Merged
merged 35 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
899f8f0
restore core to upstream version
May 13, 2022
680fc7f
correct image and make file script
robertonav20 May 15, 2022
aaef9e4
update buildah image version for multi platform support
robertonav20 May 16, 2022
868d9aa
replace arch with platform
robertonav20 May 17, 2022
9610b54
add variant field and change the policy
May 17, 2022
82de032
add docker.io inside baseimage
May 17, 2022
883606f
obtain architecture value from PublishStrategyOptions
robertonav20 May 24, 2022
0d25484
replace name of buildah property
robertonav20 May 24, 2022
80b5fa6
correct buildah attribute
robertonav20 May 24, 2022
f0a2e7a
correct attribute name
May 26, 2022
b28dd3a
add Dockerfile.arch to support arm64
robertonav20 May 26, 2022
6b6a3b0
remove useless import
May 27, 2022
db4cfa1
execute goimports lint
May 27, 2022
4bfb4ad
Merge branch 'apache:main' into main
robertonav20 May 27, 2022
90a0fa6
correct docker file for buildx
May 27, 2022
83c7256
correct makefile command
May 31, 2022
9b9cc8d
fix platform initialize
May 31, 2022
ee084aa
improve readibility of bud command
May 31, 2022
9f55b65
remove useless containerd dependency
May 31, 2022
8b6d1c8
Fix makefile images-arch command
Jun 1, 2022
6b65f16
correct docker image name
Jun 1, 2022
cb94bb5
add default docker.io to baseimage because buildah required it
Jun 1, 2022
ae3509c
correct bud command
Jun 1, 2022
88029ed
Merge branch 'apache:main' into main
robertonav20 Jun 1, 2022
ddba5aa
correct bud command with platform
Jun 1, 2022
746ec58
add log to trace platform attribute
Jun 1, 2022
aed28da
Merge branch 'main' of https://github.com/robertonav20/camel-k into main
Jun 1, 2022
b7b37eb
add docs page to describe multi architecture use
robertonav20 Jun 2, 2022
8017221
add note
robertonav20 Jun 2, 2022
2d8239e
Generate CRD
Jun 3, 2022
69dd576
Merge branch 'apache:main' into main
robertonav20 Jun 8, 2022
b52c2a9
Merge branch 'apache:main' into main
robertonav20 Jun 16, 2022
b95f642
regenerate crd
Jun 18, 2022
b6c8d50
Merge remote-tracking branch 'refs/remotes/origin/main'
Jun 18, 2022
75f13c9
Merge branch 'apache:main' into main
robertonav20 Jun 20, 2022
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
47 changes: 47 additions & 0 deletions build/Dockerfile.arch
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

FROM --platform=$BUILDPLATFORM ghcr.io/graalvm/graalvm-ce:ol8-java11-22.1.0

ARG MAVEN_VERSION="3.8.4"
ARG MAVEN_HOME="/usr/share/maven"
ARG SHA="a9b2d825eacf2e771ed5d6b0e01398589ac1bfa4171f36154d1b5787879605507802f699da6f7cfc80732a5282fd31b28e4cd6052338cbef0fa1358b48a5e3c8"
ARG BASE_URL="https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries"

USER 0

RUN mkdir -p ${MAVEN_HOME} \
&& curl -Lso /tmp/maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
&& echo "${SHA} /tmp/maven.tar.gz" | sha512sum -c - \
&& tar -xzC ${MAVEN_HOME} --strip-components=1 -f /tmp/maven.tar.gz \
&& rm -v /tmp/maven.tar.gz \
&& ln -s ${MAVEN_HOME}/bin/mvn /usr/bin/mvn \
&& rm ${MAVEN_HOME}/lib/maven-slf4j-provider*

ADD build/_maven_output /tmp/artifacts/m2
ADD build/_kamelets /kamelets
COPY build/_maven_overlay/ /usr/share/maven/lib/
ADD build/logback.xml /usr/share/maven/conf/

ENV MAVEN_OPTS="${MAVEN_OPTS} -Dlogback.configurationFile=/usr/share/maven/conf/logback.xml"

RUN chgrp -R 0 /tmp/artifacts/m2 \
&& chmod -R g=u /tmp/artifacts/m2 \
&& chgrp -R 0 /kamelets \
&& chmod -R g=u /kamelets

USER 1000

ADD build/_output/bin/kamel /usr/local/bin/kamel
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/apache/camel-k/pkg/client/camel v0.0.0
github.com/apache/camel-k/pkg/kamelet/repository v0.0.0
github.com/container-tools/spectrum v0.3.8
github.com/containerd/containerd v1.5.8
robertonav20 marked this conversation as resolved.
Show resolved Hide resolved
github.com/evanphx/json-patch v4.12.0+incompatible
github.com/fatih/camelcase v1.0.0
github.com/fatih/structs v1.1.0
Expand Down
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ github.com/containerd/containerd v1.5.0-beta.1/go.mod h1:5HfvG1V2FsKesEGQ17k5/T7
github.com/containerd/containerd v1.5.0-beta.3/go.mod h1:/wr9AVtEM7x9c+n0+stptlo/uBBoBORwEx6ardVcmKU=
github.com/containerd/containerd v1.5.0-beta.4/go.mod h1:GmdgZd2zA2GYIBZ0w09ZvgqEq8EfBp/m3lcVZIvPHhI=
github.com/containerd/containerd v1.5.0-rc.0/go.mod h1:V/IXoMqNGgBlabz3tHD2TWDoTJseu1FGOKuoA4nNb2s=
github.com/containerd/containerd v1.5.8 h1:NmkCC1/QxyZFBny8JogwLpOy2f+VEbO/f6bV2Mqtwuw=
github.com/containerd/containerd v1.5.8/go.mod h1:YdFSv5bTFLpG2HIYmfqDpSYYTDX+mc5qtSuYx1YUb/s=
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/continuity v0.0.0-20190815185530-f2a389ac0a02/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
Expand Down Expand Up @@ -2042,7 +2043,6 @@ k8s.io/code-generator v0.18.3/go.mod h1:TgNEVx9hCyPGpdtCWA34olQYLkh3ok9ar7XfSsr8
k8s.io/code-generator v0.21.3/go.mod h1:K3y0Bv9Cz2cOW2vXUrNZlFbflhuPvuadW6JdnN6gGKo=
k8s.io/code-generator v0.22.1/go.mod h1:eV77Y09IopzeXOJzndrDyCI88UBok2h6WxAlBwpxa+o=
k8s.io/code-generator v0.22.2/go.mod h1:eV77Y09IopzeXOJzndrDyCI88UBok2h6WxAlBwpxa+o=
k8s.io/code-generator v0.22.5 h1:jn+mYXI5q7rzo7Bz/n8xZIgbe61SeXlIjU5jA8jLVps=
k8s.io/code-generator v0.22.5/go.mod h1:sbdWCOVob+KaQ5O7xs8PNNaCTpbWVqNgA6EPwLOmRNk=
k8s.io/component-base v0.18.2/go.mod h1:kqLlMuhJNHQ9lz8Z7V5bxUUtjFZnrypArGl58gmDfUM=
k8s.io/component-base v0.18.3/go.mod h1:bp5GzGR0aGkYEfTj+eTY0AN/vXTgkJdQXjNTTVUaa3k=
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/camel/v1/build_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ type PublishTask struct {
type BuildahTask struct {
BaseTask `json:",inline"`
PublishTask `json:",inline"`
// The platform of build image
Platform string `json:"baseImage,omitempty"`
robertonav20 marked this conversation as resolved.
Show resolved Hide resolved
// log more information
Verbose *bool `json:"verbose,omitempty"`
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/builder/buildah.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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 builder

const BuildahPlatform = "BuildahPlatform"
4 changes: 3 additions & 1 deletion pkg/controller/build/build_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

ctrl "sigs.k8s.io/controller-runtime/pkg/client"

v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
Expand Down Expand Up @@ -243,6 +242,9 @@ func addBuildahTaskToPod(ctx context.Context, c ctrl.Reader, build *v1.Build, ta
"buildah",
"bud",
"--storage-driver=vfs",
"--platform",
robertonav20 marked this conversation as resolved.
Show resolved Hide resolved
task.Platform,
"--pull-always",
"-f",
"Dockerfile",
"-t",
Expand Down
9 changes: 9 additions & 0 deletions pkg/trait/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/apache/camel-k/pkg/builder"
mvn "github.com/apache/camel-k/pkg/util/maven"
"github.com/apache/camel-k/pkg/util/property"
"github.com/containerd/containerd/platforms"
)

// The builder trait is internally used to determine the best strategy to
Expand Down Expand Up @@ -101,7 +102,14 @@ func (t *builderTrait) Apply(e *Environment) error {
}})

case v1.IntegrationPlatformBuildPublishStrategyBuildah:
var platform string
var found bool
if platform, found = e.Platform.Status.Build.PublishStrategyOptions[builder.BuildahPlatform]; !found {
platform = platforms.DefaultSpec().OS + "/" + platforms.DefaultSpec().Architecture + "/" + platforms.DefaultSpec().Variant
robertonav20 marked this conversation as resolved.
Show resolved Hide resolved
}

e.BuildTasks = append(e.BuildTasks, v1.Task{Buildah: &v1.BuildahTask{
Platform: platform,
BaseTask: v1.BaseTask{
Name: "buildah",
},
Expand Down Expand Up @@ -151,6 +159,7 @@ func (t *builderTrait) builderTask(e *Environment) (*v1.BuilderTask, error) {
for _, repo := range e.IntegrationKit.Spec.Repositories {
maven.Repositories = append(maven.Repositories, mvn.NewRepository(repo))
}

task := &v1.BuilderTask{
BaseTask: v1.BaseTask{
Name: "builder",
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ const (
DefaultRuntimeVersion = "1.13.0"

// BuildahVersion --
BuildahVersion = "1.14.0"
BuildahVersion = "1.23.3"

// KanikoVersion --
KanikoVersion = "0.17.1"

// baseImage --
baseImage = "adoptopenjdk/openjdk11:slim"
baseImage = "docker.io/adoptopenjdk/openjdk11:slim"
robertonav20 marked this conversation as resolved.
Show resolved Hide resolved

// LocalRepository --
LocalRepository = "/tmp/artifacts/m2"
Expand Down
44 changes: 42 additions & 2 deletions script/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ OPERATOR_VERSION := $(subst -SNAPSHOT,,$(VERSION))
LAST_RELEASED_IMAGE_NAME := camel-k-operator
LAST_RELEASED_VERSION := 1.9.1
RUNTIME_VERSION := 1.13.0
BUILDAH_VERSION := 1.14.0
BUILDAH_VERSION := 1.23.3
KANIKO_VERSION := 0.17.1
INSTALL_DEFAULT_KAMELETS := true
CONTROLLER_GEN_VERSION := v0.6.1
OPERATOR_SDK_VERSION := v1.14.0
KUSTOMIZE_VERSION := v4.1.2
OPM_VERSION := v1.21.0
BASE_IMAGE := adoptopenjdk/openjdk11:slim
BASE_IMAGE := docker.io/adoptopenjdk/openjdk11:slim
LOCAL_REPOSITORY := /tmp/artifacts/m2
IMAGE_NAME := docker.io/apache/camel-k
IMAGE_TARGET_PLATFORM := linux/amd64
robertonav20 marked this conversation as resolved.
Show resolved Hide resolved

#
# Situations when user wants to override
Expand Down Expand Up @@ -90,6 +91,15 @@ TEST_PREBUILD = build
#GOLDFLAGS += -X github.com/apache/camel-k/pkg/util/olm.DefaultStartingCSV=
#GOLDFLAGS += -X github.com/apache/camel-k/pkg/util/olm.DefaultGlobalNamespace=openshift-operators

# Define target platform for docker build
robertonav20 marked this conversation as resolved.
Show resolved Hide resolved
ifeq ($(shell uname -m), x86_x64)
IMAGE_TARGET_PLATFORM = linux/amd64
endif

ifeq ($(shell uname -m), aarch64)
IMAGE_TARGET_PLATFORM = linux/arm64
endif

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
Expand Down Expand Up @@ -330,6 +340,18 @@ else
endif
docker build -t $(CUSTOM_IMAGE):$(CUSTOM_VERSION) -f build/Dockerfile .

images-arch: bundle-kamelets test maven-overlay
mkdir -p build/_maven_output
mkdir -p build/_output/bin
ifneq ($(shell uname -s 2>/dev/null || echo Unknown),Linux)
GOOS=linux go build $(GOFLAGS) -o build/_output/bin/kamel ./cmd/kamel/*.go
else
cp kamel build/_output/bin
endif
docker buildx rm --all-inactive --force
docker buildx create --append --name builder
docker buildx build --platform=$(IMAGE_TARGET_PLATFORM) -t $(CUSTOM_IMAGE):$(CUSTOM_VERSION) -f build/Dockerfile.arch .

images-dev: bundle-kamelets test package-artifacts maven-overlay
mkdir -p build/_maven_output
mkdir -p build/_output/bin
Expand All @@ -340,6 +362,18 @@ else
endif
docker build -t $(CUSTOM_IMAGE):$(CUSTOM_VERSION) -f build/Dockerfile .

images-arch-dev: bundle-kamelets test package-artifacts maven-overlay
mkdir -p build/_maven_output
mkdir -p build/_output/bin
ifneq ($(shell uname -s 2>/dev/null || echo Unknown),Linux)
GOOS=linux go build $(GOFLAGS) -o build/_output/bin/kamel ./cmd/kamel/*.go
else
cp kamel build/_output/bin
endif
docker buildx rm --all-inactive --force
docker buildx create --append --name builder
docker buildx build --platform=$(IMAGE_TARGET_PLATFORM) -t $(CUSTOM_IMAGE):$(CUSTOM_VERSION) -f build/Dockerfile.arch .

images-push:
docker push $(CUSTOM_IMAGE):$(CUSTOM_VERSION)

Expand Down Expand Up @@ -547,3 +581,9 @@ endif
# Build the bundle image.
bundle-build: bundle
cd bundle && docker build -f Dockerfile -t $(BUNDLE_IMAGE_NAME) .

# Build the bundle image.
bundle-build-arch: bundle
robertonav20 marked this conversation as resolved.
Show resolved Hide resolved
docker buildx rm --all-inactive --force
docker buildx create --append --name builder
cd bundle && docker buildx build --platform=$(IMAGE_TARGET_PLATFORM) -f Dockerfile.arch -t $(BUNDLE_IMAGE_NAME) .