Skip to content

Commit

Permalink
feat: rename task to push-dockerfile
Browse files Browse the repository at this point in the history
Signed-off-by: Chenxiong Qi <[email protected]>
  • Loading branch information
tkdchen committed Jul 15, 2024
1 parent b9e9c9d commit 2b12446
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 112 deletions.
6 changes: 3 additions & 3 deletions pipelines/docker-build-oci-ta/patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# 9 clamav-scan
# 10 sbom-json-check
# 11 apply-tags
# 12 push-build-file
# 12 push-dockerfile

# clone-repository Task
- op: replace
Expand Down Expand Up @@ -113,10 +113,10 @@
- op: remove
path: /spec/tasks/8/workspaces/0

# push-build-file
# push-dockerfile
- op: replace
path: /spec/tasks/12/taskRef/name
value: push-build-file-oci-ta
value: push-dockerfile-oci-ta
- op: add
path: /spec/tasks/12/params/-
value:
Expand Down
2 changes: 1 addition & 1 deletion pipelines/docker-build-rhtap/patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
# 9 clamav-scan
# 10 sbom-json-check
# 11 apply-tags
# 12 push-build-file
# 12 push-dockerfile
- op: replace
path: /spec/tasks/3/runAfter/0
value: clone-repository
Expand Down
6 changes: 3 additions & 3 deletions pipelines/template-build/template-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,18 @@ spec:
params:
- name: IMAGE
value: $(tasks.build-container.results.IMAGE_URL)
- name: push-build-file
- name: push-dockerfile
runAfter:
- build-container
taskRef:
name: push-build-file
name: push-dockerfile
version: "0.1"
params:
- name: IMAGE
value: $(tasks.build-container.results.IMAGE_URL)
- name: IMAGE_DIGEST
value: $(tasks.build-container.results.IMAGE_DIGEST)
- name: BUILD_FILE
- name: DOCKERFILE
value: $(params.dockerfile)
- name: CONTEXT
value: $(params.path-context)
Expand Down
20 changes: 0 additions & 20 deletions task/push-build-file-oci-ta/0.1/README.md

This file was deleted.

10 changes: 0 additions & 10 deletions task/push-build-file-oci-ta/0.1/recipe.yaml

This file was deleted.

23 changes: 0 additions & 23 deletions task/push-build-file/0.1/README.md

This file was deleted.

20 changes: 20 additions & 0 deletions task/push-dockerfile-oci-ta/0.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# push-dockerfile-oci-ta task

Discover Dockerfile from source code and push it to registry as an OCI artifact.

## Parameters
|name|description|default value|required|
|---|---|---|---|
|ARTIFACT_TYPE|Artifact type of the Dockerfile image.|application/vnd.konflux.dockerfile|false|
|CONTEXT|Path to the directory to use as context.|.|false|
|DOCKERFILE|Path to the Dockerfile.|./Dockerfile|false|
|IMAGE|The built binary image. The Dockerfile is pushed to the same image repository alongside.||true|
|IMAGE_DIGEST|The built binary image digest, which is used to construct the tag of Dockerfile image.||true|
|SOURCE_ARTIFACT|The Trusted Artifact URI pointing to the artifact with the application source code.||true|
|TAG_SUFFIX|Suffix of the Dockerfile image tag.|.dockerfile|false|

## Results
|name|description|
|---|---|
|IMAGE_URL|Digest-pinned image URL.|

Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,43 @@
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: push-build-file-oci-ta
name: push-dockerfile-oci-ta
annotations:
tekton.dev/pipelines.minVersion: 0.12.1
tekton.dev/tags: image-build, appstudio
labels:
app.kubernetes.io/version: "0.1"
build.appstudio.redhat.com/build_type: docker
spec:
description: Discover build file from source code and push it to registry
as an OCI artifact. The build file could be named Dockerfile or Containerfile,
which can be specified via parameter.
description: Discover Dockerfile from source code and push it to registry
as an OCI artifact.
params:
- name: ARTIFACT_TYPE
description: Artifact type of the build file image.
description: Artifact type of the Dockerfile image.
type: string
default: application/vnd.konflux.dockerfile
- name: BUILD_FILE
description: Path to the build file.
type: string
default: ./Dockerfile
- name: CONTEXT
description: Path to the directory to use as context.
type: string
default: .
- name: DOCKERFILE
description: Path to the Dockerfile.
type: string
default: ./Dockerfile
- name: IMAGE
description: The built binary image. The build file is pushed to the
description: The built binary image. The Dockerfile is pushed to the
same image repository alongside.
type: string
- name: IMAGE_DIGEST
description: The built binary image digest, which is used to construct
the tag of build file image.
the tag of Dockerfile image.
type: string
- name: SOURCE_ARTIFACT
description: The Trusted Artifact URI pointing to the artifact with
the application source code.
type: string
- name: TAG_SUFFIX
description: Suffix of the build file image tag.
description: Suffix of the Dockerfile image tag.
type: string
default: .dockerfile
results:
Expand All @@ -50,7 +49,7 @@ spec:
emptyDir: {}
steps:
- name: use-trusted-artifact
image: quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:bf4bfae950fe31d08f44488bb788bea8800cd6d75f5e09fcc21cf98689c61185
image: quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:0651a06076d809c2daf63a2d54abfef1a1d9b00e39aa6238b47f43c4f152f9b1
args:
- use
- $(params.SOURCE_ARTIFACT)=/var/workdir/source
Expand All @@ -67,46 +66,47 @@ spec:
value: $(params.IMAGE_DIGEST)
- name: TAG_SUFFIX
value: $(params.TAG_SUFFIX)
- name: BUILD_FILE
value: $(params.BUILD_FILE)
- name: DOCKERFILE
value: $(params.DOCKERFILE)
- name: CONTEXT
value: $(params.CONTEXT)
- name: ARTIFACT_TYPE
value: $(params.ARTIFACT_TYPE)
- name: IMAGE_URL_RESULT
value: $(results.IMAGE_URL.path)
script: |
set -eu
set -o pipefail
# Same discovery logic used in buildah task
SOURCE_CODE_DIR=source
if [ -e "$SOURCE_CODE_DIR/$CONTEXT/$BUILD_FILE" ]; then
build_file_path="$(pwd)/$SOURCE_CODE_DIR/$CONTEXT/$BUILD_FILE"
elif [ -e "$SOURCE_CODE_DIR/$BUILD_FILE" ]; then
build_file_path="$(pwd)/$SOURCE_CODE_DIR/$BUILD_FILE"
elif echo "$BUILD_FILE" | grep -q "^https\?://"; then
echo "Fetch build file from $BUILD_FILE"
build_file_path=$(mktemp --suffix=-build-file)
http_code=$(curl -s -L -w "%{http_code}" --output "$build_file_path" "$BUILD_FILE")
if [ -e "$SOURCE_CODE_DIR/$CONTEXT/$DOCKERFILE" ]; then
dockerfile_path="$(pwd)/$SOURCE_CODE_DIR/$CONTEXT/$DOCKERFILE"
elif [ -e "$SOURCE_CODE_DIR/$DOCKERFILE" ]; then
dockerfile_path="$(pwd)/$SOURCE_CODE_DIR/$DOCKERFILE"
elif echo "$DOCKERFILE" | grep -q "^https\?://"; then
echo "Fetch Dockerfile from $DOCKERFILE"
dockerfile_path=$(mktemp --suffix=-dockerfile)
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path" "$DOCKERFILE")
if [ $http_code != 200 ]; then
echo "No build file is fetched. Server responds $http_code"
echo "No Dockerfile is fetched. Server responds $http_code"
exit 1
fi
else
echo "Cannot find build file $BUILD_FILE"
echo "Cannot find Dockerfile $DOCKERFILE"
exit 1
fi
echo "Selecting auth for $IMAGE"
auth_json=$(mktemp)
select-oci-auth $IMAGE >"$auth_json"
build_file_image=${IMAGE%:*}:${IMAGE_DIGEST/:/-}${TAG_SUFFIX}
dockerfile_image=${IMAGE%:*}:${IMAGE_DIGEST/:/-}${TAG_SUFFIX}
cd "$(dirname $build_file_path)"
cd "$(dirname $dockerfile_path)"
retry oras push --no-tty \
--format json \
--registry-config "$auth_json" \
--artifact-type "$ARTIFACT_TYPE" \
"$build_file_image" "$(basename $build_file_path)" |
"$dockerfile_image" "$(basename $dockerfile_path)" |
yq '.reference' >"$IMAGE_URL_RESULT"
10 changes: 10 additions & 0 deletions task/push-dockerfile-oci-ta/0.1/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
base: ../../push-dockerfile/0.1/push-dockerfile.yaml
add:
- use-source
removeWorkspaces:
- workspace
replacements:
workspaces.workspace.path: /var/workdir
description: |-
Discover Dockerfile from source code and push it to registry as an OCI artifact.
File renamed without changes.
23 changes: 23 additions & 0 deletions task/push-dockerfile/0.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# push-dockerfile task

Discover Dockerfile from source code and push it to registry as an OCI artifact.

## Parameters
|name|description|default value|required|
|---|---|---|---|
|IMAGE|The built binary image. The Dockerfile is pushed to the same image repository alongside.||true|
|IMAGE_DIGEST|The built binary image digest, which is used to construct the tag of Dockerfile image.||true|
|DOCKERFILE|Path to the Dockerfile.|./Dockerfile|false|
|CONTEXT|Path to the directory to use as context.|.|false|
|TAG_SUFFIX|Suffix of the Dockerfile image tag.|.dockerfile|false|
|ARTIFACT_TYPE|Artifact type of the Dockerfile image.|application/vnd.konflux.dockerfile|false|

## Results
|name|description|
|---|---|
|IMAGE_URL|Digest-pinned image URL.|

## Workspaces
|name|description|optional|
|---|---|---|
|workspace|Workspace containing the source code from where the Dockerfile is discovered.|false|
Loading

0 comments on commit 2b12446

Please sign in to comment.