Skip to content

Commit

Permalink
Fix step action
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsauter committed Mar 12, 2024
1 parent 4c1e3bb commit 6812ed8
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.ods/
.vscode/
23 changes: 17 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,29 @@ image-go-toolset: ## Build go-toolset image.
.PHONY: image-go-toolset

tasks: ## Render tasks. Use VERSION=1.0.0 make tasks to render specific version.
go run github.com/opendevstack/ods-pipeline/cmd/taskmanifest \
go run github.com/opendevstack/ods-pipeline/cmd/render-manifest \
-data ImageRepository=ghcr.io/opendevstack/ods-pipeline-go \
-data Version=$$(cat version) \
-template build/tasks/build.yaml \
-destination tasks/build.yaml
.PHONY: tasks

docs: tasks ## Render documentation for tasks.
go run github.com/opendevstack/ods-pipeline/cmd/taskdoc \
-task tasks/build.yaml \
-description build/docs/build.adoc \
-destination docs/build.adoc
step-actions: ## Render step-actions. Use VERSION=1.0.0 make step-actions to render specific version.
go run github.com/opendevstack/ods-pipeline/cmd/render-manifest \
-data ImageRepository=ghcr.io/opendevstack/ods-pipeline-go \
-data Version=$$(cat version) \
-template build/step-actions/build.yaml \
-destination step-actions/build.yaml
.PHONY: step-actions

docs: tasks step-actions ## Render documentation for tasks and step-actions.
go run github.com/opendevstack/ods-pipeline/cmd/render-doc \
-manifest=step-actions/build.yaml \
-destination=docs/step-action-build.adoc
go run github.com/opendevstack/ods-pipeline/cmd/render-doc \
-manifest=tasks/build.yaml \
-description=build/docs/build.adoc \
-destination=docs/task-build.adoc
.PHONY: docs

##@ Testing
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tasks:
- { name: source, workspace: shared-workspace }
```
See the [documentation](https://github.com/opendevstack/ods-pipeline-go/blob/main/docs/build.adoc) for details and available parameters.
See the [documentation](https://github.com/opendevstack/ods-pipeline-go/blob/main/docs/task-build.adoc) for details and available parameters.
## About this repository
Expand Down
101 changes: 101 additions & 0 deletions build/step-actions/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
apiVersion: tekton.dev/v1alpha1
kind: StepAction
metadata:
name: ods-pipeline-go-build
spec:
params:
- name: working-dir
description: |
Working directory. The path must be relative to the root of the repository,
without leading `./` and trailing `/`.
type: string
default: "."
- name: enable-cgo
description: Whether to enable CGO. When not enabled the build will set `CGO_ENABLED=0`.
type: string
default: "false"
- name: go-os
description: "`GOOS` variable (the execution operating system such as `linux`, `windows`)."
type: string
default: "linux"
- name: go-arch
description: "`GOARCH` variable (the execution architecture such as `arm`, `amd64`)."
type: string
default: "amd64"
- name: output-dir
description: >-
Path to the directory into which the resulting Go binary should be copied, relative to `working-dir`.
This directory may then later be used as Docker context for example.
type: string
default: docker
- name: cache-build
description: >-
If enabled tasks uses or populates cache with the output dir contents (and artifacts) so that
a build can be skipped if the `working-dir` contents did not change.
You must set this to `"false"` if the build can be affected by files outside `working-dir`. See ADR caching-build-tasks for more details and workarounds.
type: string
default: "true"
- name: build-extra-inputs
description: >-
List of build source directories (as colon separated string) which in addition working-dir influence the build.
These directories are relative to the repository root.
If the contents in these directories change the cache is invalidated so that the build task will rebuild from scratch.
type: string
default: ""
- name: build-reused-from-location-path
description: >-
The cache location that the build task used. If caching is not enabled this will be an empty string.
type: string
- name: build-script
description: >-
Build script to execute. The
link:https://github.com/opendevstack/ods-pipeline-go/blob/main/build/images/scripts/build.sh[default script]
is located in the container image. If you specify a relative path
instead, it will be resolved from the workspace. See the task definition
for details how the build script is invoked.
type: string
default: "/usr/local/bin/go-build-script"
- name: pre-test-script
description: Script to execute before running tests, relative to the working directory.
type: string
default: ""
- name: private-cert
description: Volume mount name
type: string
- name: debug
description: Whether to turn on debug mode
type: string
default: "false"
- name: workspace
description: Path to workspace
type: string
results:
- description: The cache location that the build task used. If caching is not enabled this will be an empty string.
name: build-reused-from-location
# Image is built from build/images/Dockerfile.go-toolset.
image: '{{.ImageRepository}}/go-toolset:{{.Version}}'
env:
- name: HOME
value: '/tekton/home'
- name: CI
value: "true"
command: [ "go-build-action" ]
args: [
"-build-extra-inputs=$(params.build-extra-inputs)",
"-build-reused-from-location-path=$(params.build-reused-from-location-path)",
"-build-script=$(params.build-script)",
"-cache-build=$(params.cache-build)",
"-debug=$(params.debug)",
"-enable-cgo=$(params.enable-cgo)",
"-go-os=$(params.go-os)",
"-go-arch=$(params.go-arch)",
"-output-dir=$(params.output-dir)",
"-pre-test-script=$(params.pre-test-script)",
"-working-dir=$(params.working-dir)",
]
volumeMounts:
- mountPath: /etc/ssl/certs/private-cert.pem
name: $(params.private-cert)
readOnly: true
subPath: tls.crt
workingDir: $(params.workspace)
4 changes: 2 additions & 2 deletions build/tasks/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ spec:
description: |
Builds Go applications.
See https://github.com/opendevstack/ods-pipeline-go/blob/v{{.Version}}/docs/build.adoc
See https://github.com/opendevstack/ods-pipeline-go/blob/v{{.Version}}/docs/task-build.adoc
params:
- name: working-dir
description: |
Expand Down Expand Up @@ -49,7 +49,7 @@ spec:
- name: build-script
description: >-
Build script to execute. The
link:https://github.com/opendevstack/ods-pipeline-go/blob/main/build/images/scripts/go-build.sh[default script]
link:https://github.com/opendevstack/ods-pipeline-go/blob/main/build/images/scripts/build.sh[default script]
is located in the container image. If you specify a relative path
instead, it will be resolved from the workspace. See the task definition
for details how the build script is invoked.
Expand Down
90 changes: 90 additions & 0 deletions docs/step-action-build.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// File is generated; DO NOT EDIT.

= ods-pipeline-go-build



== Parameters

[cols="1,1,2"]
|===
| Parameter | Default | Description

| working-dir
| .
| Working directory. The path must be relative to the root of the repository,
without leading `./` and trailing `/`.



| enable-cgo
| false
| Whether to enable CGO. When not enabled the build will set `CGO_ENABLED=0`.


| go-os
| linux
| `GOOS` variable (the execution operating system such as `linux`, `windows`).


| go-arch
| amd64
| `GOARCH` variable (the execution architecture such as `arm`, `amd64`).


| output-dir
| docker
| Path to the directory into which the resulting Go binary should be copied, relative to `working-dir`. This directory may then later be used as Docker context for example.


| cache-build
| true
| If enabled tasks uses or populates cache with the output dir contents (and artifacts) so that a build can be skipped if the `working-dir` contents did not change. You must set this to `"false"` if the build can be affected by files outside `working-dir`. See ADR caching-build-tasks for more details and workarounds.


| build-extra-inputs
|
| List of build source directories (as colon separated string) which in addition working-dir influence the build. These directories are relative to the repository root. If the contents in these directories change the cache is invalidated so that the build task will rebuild from scratch.


| build-reused-from-location-path
|
| The cache location that the build task used. If caching is not enabled this will be an empty string.


| build-script
| /usr/local/bin/go-build-script
| Build script to execute. The link:https://github.com/opendevstack/ods-pipeline-go/blob/main/build/images/scripts/build.sh[default script] is located in the container image. If you specify a relative path instead, it will be resolved from the workspace. See the task definition for details how the build script is invoked.


| pre-test-script
|
| Script to execute before running tests, relative to the working directory.


| private-cert
|
| Volume mount name


| debug
| false
| Whether to turn on debug mode


| workspace
|
| Path to workspace

|===

== Results

[cols="1,3"]
|===
| Name | Description

| build-reused-from-location
| The cache location that the build task used. If caching is not enabled this will be an empty string.

|===
2 changes: 1 addition & 1 deletion docs/build.adoc → docs/task-build.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ without leading `./` and trailing `/`.

| build-script
| /usr/local/bin/go-build-script
| Build script to execute. The link:https://github.com/opendevstack/ods-pipeline-go/blob/main/build/images/scripts/go-build.sh[default script] is located in the container image. If you specify a relative path instead, it will be resolved from the workspace. See the task definition for details how the build script is invoked.
| Build script to execute. The link:https://github.com/opendevstack/ods-pipeline-go/blob/main/build/images/scripts/build.sh[default script] is located in the container image. If you specify a relative path instead, it will be resolved from the workspace. See the task definition for details how the build script is invoked.


| pre-test-script
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/opendevstack/ods-pipeline-go
go 1.19

require (
github.com/opendevstack/ods-pipeline v0.15.1-0.20240308101851-9d16db364456
github.com/opendevstack/ods-pipeline v0.15.1-0.20240312132300-000dbc1e0448
github.com/tektoncd/pipeline v0.50.1
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ github.com/onsi/ginkgo/v2 v2.9.1 h1:zie5Ly042PD3bsCvsSOPvRnFwyo3rKe64TJlD6nu0mk=
github.com/onsi/gomega v1.27.4 h1:Z2AnStgsdSayCMDiCU42qIz+HLqEPcgiOCXjAU/w+8E=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opendevstack/ods-pipeline v0.15.1-0.20240308101851-9d16db364456 h1:PDfDCHrCLdnGb4DeJyMm8+lIhM+NGWMn/X1YFycLxCM=
github.com/opendevstack/ods-pipeline v0.15.1-0.20240308101851-9d16db364456/go.mod h1:43sXbO+DpXewW5OEz5JGFloAg9gZ5k9IkfY323l5+QE=
github.com/opendevstack/ods-pipeline v0.15.1-0.20240312132300-000dbc1e0448 h1:DrUW483mrME9C3wRpW4h1Y2jBZzkJbBrvnK2+sVd558=
github.com/opendevstack/ods-pipeline v0.15.1-0.20240312132300-000dbc1e0448/go.mod h1:43sXbO+DpXewW5OEz5JGFloAg9gZ5k9IkfY323l5+QE=
github.com/otiai10/copy v1.12.0 h1:cLMgSQnXBs1eehF0Wy/FAGsgDTDmAqFR7rQylBb1nDY=
github.com/otiai10/copy v1.12.0/go.mod h1:rSaLseMUsZFFbsFGc7wCJnnkTAvdc5L6VWxPE4308Ww=
github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
Expand Down
15 changes: 10 additions & 5 deletions step-actions/build.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# File is generated; DO NOT EDIT.

apiVersion: tekton.dev/v1alpha1
kind: StepAction
metadata:
Expand Down Expand Up @@ -43,15 +44,19 @@ spec:
If the contents in these directories change the cache is invalidated so that the build task will rebuild from scratch.
type: string
default: ""
- name: build-reused-from-location-path
description: >-
The cache location that the build task used. If caching is not enabled this will be an empty string.
type: string
- name: build-script
description: >-
Build script to execute. The
link:https://github.com/opendevstack/ods-pipeline-go/blob/main/build/images/scripts/go-build.sh[default script]
link:https://github.com/opendevstack/ods-pipeline-go/blob/main/build/images/scripts/build.sh[default script]
is located in the container image. If you specify a relative path
instead, it will be resolved from the workspace. See the task definition
for details how the build script is invoked.
type: string
default: "/usr/local/bin/go-build"
default: "/usr/local/bin/go-build-script"
- name: pre-test-script
description: Script to execute before running tests, relative to the working directory.
type: string
Expand All @@ -63,8 +68,8 @@ spec:
description: Whether to turn on debug mode
type: string
default: "false"
- name: source
description: Path to source workspace
- name: workspace
description: Path to workspace
type: string
results:
- description: The cache location that the build task used. If caching is not enabled this will be an empty string.
Expand Down Expand Up @@ -95,4 +100,4 @@ spec:
name: $(params.private-cert)
readOnly: true
subPath: tls.crt
workingDir: $(params.source)
workingDir: $(params.workspace)
4 changes: 2 additions & 2 deletions tasks/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spec:
description: |
Builds Go applications.
See https://github.com/opendevstack/ods-pipeline-go/blob/v0.3.0/docs/build.adoc
See https://github.com/opendevstack/ods-pipeline-go/blob/v0.3.0/docs/task-build.adoc
params:
- name: working-dir
description: |
Expand Down Expand Up @@ -51,7 +51,7 @@ spec:
- name: build-script
description: >-
Build script to execute. The
link:https://github.com/opendevstack/ods-pipeline-go/blob/main/build/images/scripts/go-build.sh[default script]
link:https://github.com/opendevstack/ods-pipeline-go/blob/main/build/images/scripts/build.sh[default script]
is located in the container image. If you specify a relative path
instead, it will be resolved from the workspace. See the task definition
for details how the build script is invoked.
Expand Down

0 comments on commit 6812ed8

Please sign in to comment.