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

Add Task to build base multi-arch image #3402

Merged
merged 1 commit into from
Oct 23, 2020
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
100 changes: 100 additions & 0 deletions tekton/build-push-ma-base-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: build-multiarch-base-image
spec:
params:
- name: imageRegistry
- name: pathToProject
description: The path to the folder in the go/src dir that contains the project, which is used by `ko` to name the resulting images
resources:
inputs:
- name: source
type: git
targetPath: go/src/github.com/tektoncd/pipeline
outputs:
- name: builtBaseImage
type: image
steps:
- image: gcr.io/google.com/cloudsdktool/cloud-sdk
name: build-image
env:
# Connect to the sidecar over TCP, with TLS.
- name: DOCKER_HOST
value: tcp://localhost:2376
# Verify TLS.
- name: DOCKER_TLS_VERIFY
value: '1'
# Use the certs generated by the sidecar daemon.
- name: DOCKER_CERT_PATH
value: /certs/client
- name: GOOGLE_APPLICATION_CREDENTIALS
value: "/secret/release.json"
script: |
#!/usr/bin/env sh

# Activate service account
gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}

# Setup docker-auth
gcloud auth configure-docker

# add qemu bins
docker run --rm --privileged tonistiigi/binfmt:latest --install all

#install buildx
mkdir -p ~/.docker/cli-plugins
curl -fsSL https://github.com/docker/buildx/releases/download/v0.4.2/buildx-v0.4.2.linux-amd64 > ~/.docker/cli-plugins/docker-buildx
chmod u+x ~/.docker/cli-plugins/docker-buildx

#create docker context
docker context create context1

#create builder
docker buildx create context1 --name builder-buildx1 --driver docker-container --platform linux/amd64,linux/s390x,linux/ppc64le,linux/arm64 --use

#check the state
docker buildx inspect --bootstrap --builder builder-buildx1

#build multi-arch image
docker buildx build \
--platform linux/amd64,linux/s390x,linux/ppc64le,linux/arm64 \
--tag $(params.imageRegistry)/$(params.pathToProject)/$(resources.outputs.builtBaseImage.url) \
--push \
/workspace/go/src/github.com/tektoncd/pipeline/images

volumeMounts:
- mountPath: /certs/client
name: dind-certs
- name: gcp-secret
mountPath: /secret

sidecars:
- image: docker:dind
name: server
args:
- --storage-driver=vfs
- --userland-proxy=false
- --debug
securityContext:
privileged: true
env:
# Write generated certs to the path shared with the client.
- name: DOCKER_TLS_CERTDIR
value: /certs
volumeMounts:
- mountPath: /certs/client
name: dind-certs
# Wait for the dind daemon to generate the certs it will share with the
# client.
readinessProbe:
periodSeconds: 1
exec:
command: ['ls', '/certs/client/ca.pem']

volumes:
- name: dind-certs
emptyDir: {}
- name: gcp-secret
secret:
secretName: release-secret
16 changes: 0 additions & 16 deletions tekton/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,6 @@ spec:
type: cloudEvent
steps:

- name: build-push-base-images
image: gcr.io/kaniko-project/executor:v0.17.1
command:
- /kaniko/executor
args:
- --dockerfile=/workspace/go/src/github.com/tektoncd/pipeline/images/Dockerfile
- --destination=$(params.imageRegistry)/$(params.pathToProject)/$(resources.outputs.builtBaseImage.url)
- --context=/workspace/go/src/github.com/tektoncd/pipeline

volumeMounts:
- name: gcp-secret
mountPath: /secret
env:
- name: GOOGLE_APPLICATION_CREDENTIALS
value: /secret/release.json

- name: create-ko-yaml
image: busybox
script: |
Expand Down
20 changes: 17 additions & 3 deletions tekton/release-pipeline-nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,24 @@ spec:
inputs:
- name: source
resource: source-repo
- name: publish-images
- name: build-base-image
runAfter: [build, unit-tests]
taskRef:
name: build-multiarch-base-image
params:
- name: pathToProject
value: $(params.package)
- name: imageRegistry
value: $(params.imageRegistry)
resources:
inputs:
- name: source
resource: source-repo
outputs:
- name: builtBaseImage
resource: builtBaseImage
- name: publish-images
runAfter: [build-base-image, build, unit-tests]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: since build-base-image already depends on [build, unit-tests], this can depend on build-base-image alone.

taskRef:
name: publish-tekton-pipelines
params:
Expand All @@ -81,8 +97,6 @@ spec:
outputs:
- name: bucket
resource: bucket
- name: builtBaseImage
resource: builtBaseImage
- name: builtEntrypointImage
resource: builtEntrypointImage
- name: builtNopImage
Expand Down