Skip to content

Commit

Permalink
Auto-update experimental tekton resources
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions authored and vdemeester committed Oct 2, 2023
1 parent 25db114 commit 685016e
Show file tree
Hide file tree
Showing 6 changed files with 393 additions and 24 deletions.
12 changes: 12 additions & 0 deletions .github/actions/go/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: go
description: Go setup action

runs:
using: composite
steps:
# "setup-go" setup Golang and configure build cache.
- uses: actions/setup-go@v4
with:
go-version: 1.20.x
cache: true
20 changes: 20 additions & 0 deletions .github/actions/tektoncd/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: tektoncd
description: Setup Tekton Pipeline on KinD

runs:
using: composite
steps:
# "kind-action" provides a running KinD instance and configured kubectl client.
- uses: helm/[email protected]
with:
cluster_name: kind

# "setup-tektoncd" provides Tekton Pipeline, CLI and a local container registry.
- uses: openshift-pipelines/setup-tektoncd@v1
with:
pipeline_version: latest
feature_flags: "{}"
cli_version: latest
setup_registry: "true"
patch_etc_hosts: "true"
54 changes: 31 additions & 23 deletions .github/workflows/test-kubernetes-tasks.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
---
name: test-k8s-pipeline-latest

on:
pull_request:
branches: [ main, p ]
branches:
- main
- p
push:
branches: [ main, p ]
branches:
- main
- p
schedule:
- cron: '0 0 * * *'
- cron: "0 0 * * *"
workflow_dispatch: # allow manual triggering

name: test-k8s-pipeline-latest

jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
# using KinD to provide the Kubernetes instance and kubectl
- uses: helm/[email protected]
with:
cluster_name: kind
# setting up Tekton Pipelines, CLI and additional components...
- uses: openshift-pipelines/setup-tektoncd@v1
with:
pipeline_version: latest
feature_flags: '{}'
cli_version: latest
setup_registry: "true"
patch_etc_hosts: "true"
# pipeline-feature-flags: '{"enable-api-fields": "alpha"}'
- name: run-tests
run: |
kubectl version
make test-e2e/kubernetes
- uses: actions/checkout@v4
- uses: ./.github/actions/tektoncd

- name: End-to-End Tests
run: |
kubectl version
make test-e2e/kubernetes
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/go

- name: Linting tekton resources
run: |
# Lint experimental
go run ./cmd/catalog-cd lint experimental/tasks || true
go run ./cmd/catalog-cd lint experimental/pipelines || true
go run ./cmd/catalog-cd lint tasks || true
go run ./cmd/catalog-cd lint pipelines || true
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ OUTPUT_DIR ?= bin
BIN = $(OUTPUT_DIR)/$(APP)

CMD ?= ./cmd/$(APP)/...
PKG ?= ./pkg/...
PKG ?= ./internal/...

GOFLAGS ?= -v
GOFLAGS_TEST ?= -v -cover
Expand Down
151 changes: 151 additions & 0 deletions experimental/tasks/go-crane-image/v0.2.0/go-crane-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: go-crane-image
labels:
app.kubernetes.io/version: "0.2.0"
annotations:
tekton.dev/pipelines.minVersion: "0.40.0"
tekton.dev/categories: language
tekton.dev/tags: go
tekton.dev/displayName: "go crane image"
tekton.dev/platforms: "linux/amd64,linux/s390x,linux/ppc64le,linux/arm64"
spec:
description: >-
The go-crane-image Task will build a container image based of off a go
project to be compiled, using crane.
workspaces:
- name: source
description: The go source to build
- name: dockerconfig
description: Includes a docker `config.json` or `.dockerconfigjson`
optional: true
params:
- name: app
description: >-
The name of the "application" to build. This will have an impact on the binary
and possibly the image reference
- name: package
description: >-
The package to build. It needs to be a package `main` that compiles into a binary.
The default value is `.`, usual value can be `./cmd/{name}`
default: .
- name: image
description: >-
The image specific options such as prefix, labels, env, …
type: object
properties:
base: {type: string}
labels: {type: string}
envs: {type: string}
push: {type: string}
prefix: {type: string}
tag: {type: string}
default:
base: ""
labels: ""
envs: ""
push: "true"
tag: "latest"
- name: go
description: >-
Golang options, such as flags, version, …
type: object
properties:
version: {type: string}
GOFLAGS: {type: string}
GOOS: {type: string}
GOARCH: {type: string}
CGO_ENABLED: {type: string}
default:
version: "1.18"
GOFLAGS: "-v"
GOOS: ""
GOARCH: ""
CGO_ENABLED: "0"
results:
- name: IMAGE_DIGEST
description: Digest of the image just built.
- name: IMAGE_URL
description: URL of the image just built.
steps:
- name: build-go
image: docker.io/library/golang:$(params.go.version)
workingDir: $(workspaces.source.path)
script: |
#!/usr/bin/env bash
set -e
go env
go build -o $(params.app) $(params.package)
env:
- name: GOFLAGS
value: "$(params.go.GOFLAGS)"
- name: GOOS
value: "$(params.go.GOOS)"
- name: GOARCH
value: "$(params.go.GOARCH)"
- name: CGO_ENABLED
value: "$(params.go.CGO_ENABLED)"
- name: publish-image
image: ghcr.io/shortbrain/golang-tasks/crane:main
workingDir: $(workspaces.source.path)
script: |
#!/usr/bin/env bash
set -e
if [[ "$(params.image.push)" == "false" ]]; then
echo "Not doing anything as push is disabled"
echo -n "" > $(resutls.IMAGE_DIGEST.path)
echo -n "" > $(resutls.IMAGE_URL.path)
exit 0
fi
# Prepare the layer to add
mkdir output
cp $(params.app) ./output
# FIXME: extra things to copy ?
if [[ "$(workspaces.dockerconfig.bound)" == "true" ]]; then
# if config.json exists at workspace root, we use that
if test -f "$(workspaces.dockerconfig.path)/config.json"; then
export DOCKER_CONFIG="$(workspaces.dockerconfig.path)"
# else we look for .dockerconfigjson at the root
elif test -f "$(workspaces.dockerconfig.path)/.dockerconfigjson"; then
cp "$(workspaces.dockerconfig.path)/.dockerconfigjson" "$HOME/.docker/config.json"
export DOCKER_CONFIG="$HOME/.docker"
# need to error out if neither files are present
else
echo "neither 'config.json' nor '.dockerconfigjson' found at workspace root"
exit 1
fi
fi
APPEND_FLAGS="--new_tag $(params.image.prefix)/$(params.app):$(params.image.tag)"
if [[ -n "$(params.image.base)" ]]; then
APPEND_FLAGS="--base $(params.image.base) ${APPEND_FLAGS}"
fi
MUTATE_FLAGS="--entrypoint=/$(params.app) --tag $(params.image.prefix)/$(params.app):$(params.image.tag)"
# envs
while IFS=';' read -ra ENVS; do
for ENV in "${ENVS[@]}"; do
MUTATE_FLAGS="${MUTATE_FLAGS} --env ${ENV}"
done
done <<< "$(params.image.envs)"
# labels
while IFS=';' read -ra LABELS; do
for LABEL in "${LABELS[@]}"; do
MUTATE_FLAGS="${MUTATE_FLAGS} --label ${LABEL}"
done
done <<< "$(params.image.labels)"
crane mutate $( \
crane append ${APPEND_FLAGS} \
--new_layer <(cd ./output && tar -f - -c .) \
) \
${MUTATE_FLAGS} > crane_output
CRANE_OUTPUT=$(cat crane_output)
echo -n ${CRANE_OUTPUT#*@} > $(results.IMAGE_DIGEST.path)
echo -n ${CRANE_OUTPUT} > $(results.IMAGE_URL.path)
# echo -n ${CRANE_OUTPUT%@*} > $(results.IMAGE_URL.path)
Loading

0 comments on commit 685016e

Please sign in to comment.