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

feat: add task for updating and pushing image to quay.io with new tag #14

Merged
merged 30 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
18f9133
test: update tekton chains config
StinkyBenji Oct 27, 2023
d2a0819
fix: update the image tag param in build task
StinkyBenji Oct 30, 2023
55a6ae6
feat: add task to push the ee image for release
StinkyBenji Oct 30, 2023
42356d7
fix: the name of tasks in pac
StinkyBenji Oct 30, 2023
044b787
fix: the name of cleanup task
StinkyBenji Oct 30, 2023
441d577
fix: parameters for image build tag
StinkyBenji Oct 30, 2023
d0b6a8a
test: test the image push on feature branch
StinkyBenji Oct 30, 2023
c985ac5
fix: change back to delete image stream after merging to main
StinkyBenji Oct 31, 2023
a1687ad
fix: release only on main
StinkyBenji Oct 31, 2023
b6c6799
test: not yet finished
StinkyBenji Oct 31, 2023
8844085
fix: skopeo copy environment variable for registry auth
StinkyBenji Oct 31, 2023
65aff87
fix: pipeline as code cel expression
StinkyBenji Oct 31, 2023
89dadb7
test: test cel expression on pull request
StinkyBenji Nov 1, 2023
ef6a4b8
fix: typos
StinkyBenji Nov 1, 2023
623cfe7
fix: typos and test on cel expression
StinkyBenji Nov 1, 2023
2e9e877
test: test cel expression on push and branch
StinkyBenji Nov 1, 2023
877157e
test: add cel filtering on push event
StinkyBenji Nov 1, 2023
bedc440
test: add cel filtering event title on push event
StinkyBenji Nov 1, 2023
44bf82d
test: only push event
StinkyBenji Nov 1, 2023
d48ee16
test: now add the pull request event
StinkyBenji Nov 1, 2023
a740099
perf: small cleanup on the repo
StinkyBenji Nov 1, 2023
cd3bf8d
fix: add semantic release exec plugin to extract next release version
StinkyBenji Nov 1, 2023
ec4711f
test: test cel expression on pull_request
StinkyBenji Nov 1, 2023
bd7e088
test: test cel expression on pull_request with target branch
StinkyBenji Nov 1, 2023
9d67f78
chore: still need to fix on-cel-expression
StinkyBenji Nov 1, 2023
c4cbbf9
test: cel expression
StinkyBenji Nov 1, 2023
f644edd
test: cel expression with refs
StinkyBenji Nov 1, 2023
f52bc92
test: cel expression with more random stuff
StinkyBenji Nov 1, 2023
ae4c7a1
test: cel expression with more random stuff
StinkyBenji Nov 1, 2023
9265486
fix: use parenthese on cel expression
StinkyBenji Nov 1, 2023
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
57 changes: 49 additions & 8 deletions .tekton/ansible-ee-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ metadata:
pipelinesascode.tekton.dev/task-4: "[.tekton/tasks/buildah.yaml]"
pipelinesascode.tekton.dev/task-5: "[.tekton/tasks/ansible-ee-sanity-test.yaml]"
pipelinesascode.tekton.dev/task-6: "[.tekton/tasks/semantic-release.yaml]"
pipelinesascode.tekton.dev/task-7: "[.tekton/tasks/delete-image-stream.yaml]"
pipelinesascode.tekton.dev/task-7: "[.tekton/tasks/skopeo-copy.yaml]"
pipelinesascode.tekton.dev/task-8: "[.tekton/tasks/delete-image-stream.yaml]"
pipelinesascode.tekton.dev/on-cel-expression: |
event == "pull_request" || event == "push" && target_branch == "main" && "examples/ansible-ee/***".pathChanged() || ".tekton/ansible-ee-pipeline.yaml".pathChanged()
(event == "push" || event == "pull_request") && target_branch == "main" && ("ansible-ee/***".pathChanged() || ".tekton/ansible-ee-pipeline.yaml".pathChanged())
spec:
params:
- name: repo_url
Expand All @@ -27,7 +28,6 @@ spec:
- name: revision
workspaces:
- name: source
- name: quay-credentials
- name: registry-credentials
tasks:
- name: fetch-repository
Expand Down Expand Up @@ -80,7 +80,7 @@ spec:
- name: OUTPUT_FILENAME
value: Dockerfile
- name: PATH
value: "examples/ansible-ee"
value: "ansible-ee"

- name: build-image-tag
taskRef:
Expand All @@ -97,8 +97,10 @@ spec:
value: "false"
- name: IMAGE
value: image-registry.openshift-image-registry.svc:5000/ansible-tekton-demo/custom-ansible-ee
- name: TAG
value: "{{ pull_request_number }}"
- name: CONTEXT
value: "examples/ansible-ee"
value: "ansible-ee"

- name: ee-sanity-test
taskRef:
Expand All @@ -111,6 +113,8 @@ spec:
params:
- name: IMAGE
value: image-registry.openshift-image-registry.svc:5000/ansible-tekton-demo/custom-ansible-ee
- name: TAG
value: "{{ pull_request_number }}"

- name: image-scan
taskRef:
Expand Down Expand Up @@ -145,8 +149,48 @@ spec:
- name: source-branch
value: "{{ source_branch }}"

- name: push-image-tag
when:
- input: "{{ source_branch }}"
operator: in
values: ["main"]
runAfter:
- semantic-release
taskRef:
name: skopeo-copy
workspaces:
- name: source
workspace: source
params:
- name: srcImageURL
value: "docker://$(tasks.build-image-tag.results.IMAGE_URL)"
- name: destImageURL
value: "docker://quay.io/stbenji/ansible-tekton-demo:$(tasks.semantic-release.results.version)"

- name: update-image-latest
when:
- input: "{{ source_branch }}"
operator: in
values: ["main"]
runAfter:
- semantic-release
taskRef:
name: skopeo-copy
workspaces:
- name: source
workspace: source
params:
- name: srcImageURL
value: "docker://$(tasks.build-image-tag.results.IMAGE_URL)"
- name: destImageURL
value: "docker://quay.io/stbenji/ansible-tekton-demo:latest"

finally:
- name: clean-up
when:
- input: "{{ source_branch }}"
operator: in
values: ["main"]
taskRef:
name: delete-image-stream
workspaces:
Expand All @@ -165,9 +209,6 @@ spec:
resources:
requests:
storage: 5Gi
- name: quay-credentials
secret:
secretName: quay-credentials
- name: registry-credentials
secret:
secretName: registry-credentials
2 changes: 1 addition & 1 deletion .tekton/chains/tekton-chains-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ metadata:
app.kubernetes.io/part-of: tekton-chains
operator.tekton.dev/operand-name: tektoncd-chains
data:
artifacts.oci.repository: "image-registry.openshift-image-registry.svc:5000"
artifacts.oci.repository: "image-registry.openshift-image-registry.svc:5000,quay.io"
artifacts.oci.storage: "tekton,oci"
artifacts.pipelinerun.format: slsa/v1
artifacts.pipelinerun.storage: "tekton,oci"
Expand Down
2 changes: 1 addition & 1 deletion .tekton/credentials/registry-credentials.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ metadata:
tekton.dev/docker-0: quay.io
tekton.dev/docker-1: registry.redhat.io
stringData:
config.json: |
.dockerconfigjson: |
{your-auth}
type: kubernetes.io/dockerconfigjson
11 changes: 10 additions & 1 deletion .tekton/tasks/ansible-ee-sanity-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ metadata:
spec:
description: A task for testing the built ansible execution environment.
params:
- name: TAG
type: string
description: Tag of the image tp be tested.
- name: IMAGE
type: string
description: The name of the image to be tested.
Expand All @@ -26,7 +29,13 @@ spec:
- name: source
steps:
- name: test-image
image: $(params.IMAGE)
image: $(params.IMAGE):$(params.TAG)
securityContext:
runAsNonRoot: true
runAsUser: 65532
env:
- name: HOME
value: /tekton/home
workingDir: $(workspaces.source.path)
script: |
#!/usr/bin/env sh
Expand Down
11 changes: 7 additions & 4 deletions .tekton/tasks/buildah.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ spec:
Dockerfile to assemble a container image, then pushes that image to a
container registry.
params:
- description: Tag of the image buildah will produce.
name: TAG
type: string
- description: Name of the image buildah will produce.
name: IMAGE
type: string
Expand Down Expand Up @@ -99,16 +102,16 @@ spec:
buildah --storage-driver=$(params.STORAGE_DRIVER) bud \
$(params.BUILD_EXTRA_ARGS) --format=$(params.FORMAT) \
--tls-verify=$(params.TLSVERIFY) --no-cache \
-f $(params.DOCKERFILE) -t "$(params.IMAGE)" $(params.CONTEXT)
-f $(params.DOCKERFILE) -t "$(params.IMAGE):$(params.TAG)" $(params.CONTEXT)

[[ "$(params.SKIP_PUSH)" == "true" ]] && echo "Push skipped" && exit 0

buildah --storage-driver=$(params.STORAGE_DRIVER) push \
$(params.PUSH_EXTRA_ARGS) --tls-verify=$(params.TLSVERIFY) \
--digestfile /tmp/image-digest "$(params.IMAGE)" \
docker://"$(params.IMAGE)"
--digestfile /tmp/image-digest "$(params.IMAGE):$(params.TAG)" \
docker://"$(params.IMAGE):$(params.TAG)"
cat /tmp/image-digest | tee $(results.IMAGE_DIGEST.path)
echo "$(params.IMAGE)" | tee $(results.IMAGE_URL.path)
echo "$(params.IMAGE):$(params.TAG)" | tee $(results.IMAGE_URL.path)
securityContext:
capabilities:
add:
Expand Down
3 changes: 3 additions & 0 deletions .tekton/tasks/delete-image-stream.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ spec:
- name: cleanup-image-stream
image: $(params.RUNNER_IMAGE)
workingDir: $(workspaces.source.path)
env:
- name: HOME
value: /tekton/home
script: |
#!/usr/bin/env sh
echo "Deleting the image stream:"
Expand Down
5 changes: 5 additions & 0 deletions .tekton/tasks/semantic-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ spec:
- name: source-branch
type: string
description: the source-branch that semantic-release will run on
results:
- description: The version to be released
name: version
type: string
workspaces:
- name: source
steps:
Expand Down Expand Up @@ -56,3 +60,4 @@ spec:
git checkout $(params.source-branch)
# run the semantic-release
npx semantic-release --no-ci --branches $(params.source-branch)
cat .VERSION | tee $(results.version.path)
51 changes: 51 additions & 0 deletions .tekton/tasks/skopeo-copy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: skopeo-copy
labels:
app.kubernetes.io/version: "0.1"
annotations:
tekton.dev/pipelines.minVersion: "0.37.4"
tekton.dev/categories: Push image tag
tekton.dev/tags: image push
spec:
description: A task for pushing the built ansible execution environment image.
params:
- name: srcImageURL
type: string
description: the source image to be copied to the destination registry
- name: destImageURL
type: string
description: the image where the image from source should be copied to
- name: srcTLSverify
description: Verify the TLS on the src registry endpoint
type: string
default: "true"
- name: destTLSverify
description: Verify the TLS on the dest registry endpoint
type: string
default: "true"
- name: skopeoImage
description: the skopeo image to be used for the task
type: string
default: "quay.io/skopeo/stable:v1"

workspaces:
- name: source
steps:
- name: skopeo-copy
env:
- name: HOME
value: /tekton/home
- name: REGISTRY_AUTH_FILE
value: $HOME/.docker/config.json
securityContext:
runAsNonRoot: true
runAsUser: 65532
image: $(params.skopeoImage)
workingDir: $(workspaces.source.path)
script: |
#!/bin/sh
set -x
skopeo copy --src-tls-verify="$(params.srcTLSverify)" --dest-tls-verify="$(params.destTLSverify)" $(params.srcImageURL) $(params.destImageURL)
30 changes: 8 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ or automation hub, semantic release and SBOM generator.
- OpenShift 4.13.12
- Ansible
- OpenShift Pipelines 1.12.0
- Semantic Release v22.0.6

## Setup pre-commit

Expand All @@ -36,16 +37,15 @@ in `.tekton/pac/` in the corresponding namespace with the correct values.

## Tekton Pipelines Architecture

There are two `PipelineRun` in `.tekton/`:
There is one `PipelineRun` in `.tekton/`:

- `ansible-ee-pipeline`
- `ansible-collection-pipeline`

### Ansible Execusion Environment Pipeline

There is a basic example for a basic [Ansible execution
environment](https://docs.ansible.com/automation-controller/latest/html/userguide/execution_environments.html)
in the `examples/ansible-ee`.
in the `ansible-ee`.
The pipeline consists of the tasks showed below:

![figure](./assets/ansible-ee-pipeline.png)
Expand All @@ -64,32 +64,18 @@ updated, as well as the git release. A final cleanup will be executed.
### Tekton Chains

In addition, [Tekton Chains](https://tekton.dev/docs/chains/) is used for signing artifacts.
We used cosign
`cosign generate-key-pair k8s://ansible-tekton-demo/signing-secrets`
create a secret where stores registry credentials
`oc create secret registry-credentials --from-file=.dockerconfigjson --type=kubernetes.io/dockerconfigjson -n $NAMESPACE`
`oc patch sa pipeline -p "{\"imagePullSecrets\": [{\"name\": \"registry-credentials\"}]}" -n ansible-tekton-demo`

### Ansible Collection Pipeline

There is a basic ansible collection example in the `examples/collections`
We used cosign

The pipeline consists of the tasks showed below:
`cosign generate-key-pair k8s://ansible-tekton-demo/signing-secrets`

![figure](./assets/ansible-collection-pipeline.png)
create a secret where stores registry credentials

Similar to `ansible-ee-pipeline`, after cloning the Git repo, secret scanning,
and ansible linting on the ansible manifests, a set of tests for the collection
will be executed. The SBOM and corresponding release version and changelog will
be generated.
`oc create secret registry-credentials --from-file=.dockerconfigjson --type=kubernetes.io/dockerconfigjson -n $NAMESPACE`

After the collection passed the test, it will be uploaded to automation
hub or any other desired artifactory registry. It will be published after human approval
Finally, a cleanup will be executed.
`oc patch sa pipeline -p "{\"imagePullSecrets\": [{\"name\": \"registry-credentials\"}]}" -n ansible-tekton-demo`

## Set up semantic-release

[semantic-release](https://github.com/semantic-release/semantic-release) is used for automating
the whole package release workflow

[semantic-release-docker](https://github.com/esatterwhite/semantic-release-docker)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading