Skip to content

Commit

Permalink
feat(MMENG-4168): add mrrc-collect-params task (#493)
Browse files Browse the repository at this point in the history
This commit adds a task for collecting params for MRRC from data
json of collect-data task.

Signed-off-by: Gang Li <[email protected]>
  • Loading branch information
ligangty authored Aug 13, 2024
1 parent 420bd76 commit 806af0c
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tasks/collect-mrrc-params/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# collect-mrrc-params

Tekton task that collects MRRC(maven.repository.redhat.com) configuration options from the data file. MRRC is used to host maven artifacts of Red Hat Middleware products.
This task looks at the data file in the workspace to extract the params like `mrrc.*`, `cosignPubKeySecret` and `charonAWSSecret` keys for MRRC. `mrrc.*` will be stored in a mrrc.env file and are emitted as task results with other three for downstream tasks to use.

## Parameters

| Name | Description | Optional | Default value |
|------|-------------|----------|---------------|
| dataPath | Path to the merged data JSON file generated by collect-data task and containing the mrrc configuration options to use | No | |
52 changes: 52 additions & 0 deletions tasks/collect-mrrc-params/collect-mrrc-params.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: collect-mrrc-params
spec:
params:
- name: dataJsonPath
type: string
description: path to data json file
results:
- name: mrrcParamFilePath
description: path of the env file for following tasks
- name: cosignPubKeyConfig
description: the configmap name for cosign verify public key
- name: charonAWSSecret
description: the secret name for charon aws credential file
steps:
- name: collect-mrrc-params
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env bash
set -eux
WORK_DIR=$(workspaces.data.path)
cd $WORK_DIR
DATA_FILE="$WORK_DIR/$(params.dataJsonPath)"
MRRC_ENV_FILE_PATH="$(dirname $(params.dataJsonPath))/mrrc.env"
environment="$(jq -re '.mrrc.environment' $DATA_FILE)"
release="$(jq -re '.mrrc.release' $DATA_FILE)"
target="$environment-maven-$release"
echo "export MRRC_TARGET=$target" >> "$MRRC_ENV_FILE_PATH"
productName="$(jq -re '.mrrc.product.name' $DATA_FILE)"
productVersion="$(jq -re '.mrrc.product.version' $DATA_FILE)"
echo "export MRRC_PRODUCT_NAME=$productName" >> "$MRRC_ENV_FILE_PATH"
echo "export MRRC_PRODUCT_VERSION=$productVersion" >> "$MRRC_ENV_FILE_PATH"
zipRegistry="$(jq -re '.mrrc.product.zipRegistry' $DATA_FILE)"
echo "export MRRC_ZIP_REGISTRY=$zipRegistry" >> "$MRRC_ENV_FILE_PATH"
awsSecret="$(jq -re '.mrrc.awsSecret' $DATA_FILE)"
echo -n "$awsSecret" > "$(results.charonAWSSecret.path)"
cosignPubKey="$(jq -j '.mrrc.product.cosignPubKeyConfig // "cosign-pub-key"' $DATA_FILE)"
echo -n "$cosignPubKey" > "$(results.cosignPubKeyConfig.path)"
echo -n "$MRRC_ENV_FILE_PATH" > "$(results.mrrcParamFilePath.path)"
workspaces:
- name: data
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: test-collect-mrrc-params-fail-no-data
annotations:
test/assert-task-failure: "run-task"
spec:
description: |
Run the collect-mrrc-params task with no data file and verify the taks fails as expected
workspaces:
- name: tests-workspace
tasks:
- name: run-task
taskRef:
name: collect-mrrc-params
params:
- name: dataJsonPath
value: data.json
workspaces:
- name: data
workspace: tests-workspace
85 changes: 85 additions & 0 deletions tasks/collect-mrrc-params/tests/test-collect-mrrc-params.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: test-collect-mrrc-params
spec:
description: |
Run the collect-mrrc-params task
workspaces:
- name: tests-workspace
tasks:
- name: setup
workspaces:
- name: data
workspace: tests-workspace
taskSpec:
steps:
- name: setup-values
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env sh
set -eux
cat > "$(workspaces.data.path)/data.json" << EOF
{
"mrrc": {
"product": {
"name": "activemq",
"version": "0.0.1",
"cosignPubKeyConfig": "test-cosign-pub-key",
"zipRegistry": "quay.io/ligangty/activemq.zip:0.0.1"
},
"awsSecret": "charon-aws-credentials",
"environment": "dev",
"release": "ga"
}
}
EOF
- name: run-task
taskRef:
name: collect-mrrc-params
params:
- name: dataJsonPath
value: data.json
workspaces:
- name: data
workspace: tests-workspace
runAfter:
- setup
- name: check-result
workspaces:
- name: data
workspace: tests-workspace
params:
- name: mrrcParamFilePath
value: $(tasks.run-task.results.mrrcParamFilePath)
- name: cosignPubKeyConfig
value: $(tasks.run-task.results.cosignPubKeyConfig)
- name: charonAWSSecret
value: $(tasks.run-task.results.charonAWSSecret)
taskSpec:
params:
- name: mrrcParamFilePath
- name: cosignPubKeyConfig
- name: charonAWSSecret
steps:
- name: check-result
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env sh
set -eux
test "$(params.cosignPubKeyConfig)" == "test-cosign-pub-key"
test "$(params.charonAWSSecret)" == "charon-aws-credentials"
MRRC_FILE="$(workspaces.data.path)/$(params.mrrcParamFilePath)"
test -f "$MRRC_FILE"
. "$MRRC_FILE"
test "$MRRC_ZIP_REGISTRY" == "quay.io/ligangty/activemq.zip:0.0.1"
test "$MRRC_TARGET" == "dev-maven-ga"
test "$MRRC_PRODUCT_NAME" == "activemq"
test "$MRRC_PRODUCT_VERSION" == "0.0.1"
runAfter:
- run-task

0 comments on commit 806af0c

Please sign in to comment.