Build multi-architecture images
To build multi-architecture images in a CI pipeline, use a separate stage to build and push each architecture.
For example, the following pipeline has two stages. The two stages have similar components, but they differ according to the architecture of the image that the stage builds. Each stage has:
- A variation of a Kubernetes cluster build infrastructure. Notice that each stage uses a different Kubernetes cluster connector (
infrastructure.spec.connectorRef
) and other settings due to the different architecture requirements. - A Run step that prepares the Dockerfile.
- A Build and Push step that builds and uploads the image. If the images are uploaded to the same repository, use
tags
to differentiate them, such as1.0-linux-amd64
and1.0-linux-arm64
.
pipeline:
allowStageExecutions: true
projectIdentifier: default
orgIdentifier: default
identifier: CI_MultiArch
name: CI_MultiArch
tags:
CI: ""
properties:
ci:
codebase:
connectorRef: YOUR_CODEBASE_CONNECTOR_ID
repoName: YOUR_REPO_NAME
build: <+input>
stages:
- stage:
name: K8
identifier: upload
type: CI
spec:
cloneCodebase: true
infrastructure:
type: KubernetesDirect
spec:
connectorRef: k8Linux
namespace: <+input>
runAsUser: ""
automountServiceAccountToken: true
nodeSelector: {}
containerSecurityContext:
runAsUser: ""
os: Linux
execution:
steps:
- step:
type: Run
name: CreateDockerFile
identifier: CreateDockerFile
spec:
connectorRef: account.harnessImage
image: alpine:latest
command: |-
touch harnessDockerfileui
cat > harnessDockerfileui <<- EOM
FROM alpine:latest AS dev-env
ARG foo
RUN echo "$foo bar"
ENTRYPOINT ["pwd"]
FROM alpine:latest AS release-env
ARG hello
RUN echo "$hello world"
ENTRYPOINT ["ls"]
EOM
cat harnessDockerfileui
resources:
limits:
memory: 100M
- step:
type: BuildAndPushDockerRegistry
name: DockerPushStep
identifier: DockerPushStep
spec:
connectorRef: YOUR_DOCKER_CONNECTOR_ID
repo: my-repo/ci-demo
tags:
- "1.0-linux-amd64"
dockerfile: harnessDockerfileui
target: dev-env
resources:
limits:
memory: 100M
- stage:
name: K8s Linux arm
identifier: CI_Golden_ARM
type: CI
spec:
cloneCodebase: true
infrastructure:
type: KubernetesDirect
spec:
connectorRef: k8sarm
namespace: ci-gold-arm-delegate
automountServiceAccountToken: true
tolerations:
- effect: NoSchedule
key: kubernetes.io/arch
operator: Equal
value: arm64
nodeSelector:
kubernetes.io/arch: arm64
os: Linux
execution:
steps:
- step:
type: Run
name: CreateDockerFile
identifier: CreateDockerFile
spec:
connectorRef: account.harnessImage
image: alpine:latest
command: |-
touch harnessDockerfileui
cat > harnessDockerfileui <<- EOM
FROM alpine:latest AS dev-env
ARG foo
RUN echo "$foo bar"
ENTRYPOINT ["pwd"]
FROM alpine:latest AS release-env
ARG hello
RUN echo "$hello world"
ENTRYPOINT ["ls"]
EOM
cat harnessDockerfileui
resources:
limits:
memory: 100M
- step:
type: BuildAndPushDockerRegistry
name: DockerPushStep
identifier: DockerPushStep
spec:
connectorRef: YOUR_DOCKER_CONNECTOR_ID
repo: my-repo/ci-demo
tags:
- "1.0-linux-arm64"
dockerfile: harnessDockerfileui
target: dev-env
resources:
limits:
memory: 100M