diff --git a/.gitignore b/.gitignore index 7f5003c..11ab2ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .ods/ +.vscode/ diff --git a/Makefile b/Makefile index e8fa1d9..44863b6 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 7c5590d..7227367 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/build/step-actions/build.yaml b/build/step-actions/build.yaml new file mode 100644 index 0000000..cc0465d --- /dev/null +++ b/build/step-actions/build.yaml @@ -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) diff --git a/build/tasks/build.yaml b/build/tasks/build.yaml index 5202a75..decc39d 100644 --- a/build/tasks/build.yaml +++ b/build/tasks/build.yaml @@ -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: | @@ -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. diff --git a/docs/step-action-build.adoc b/docs/step-action-build.adoc new file mode 100644 index 0000000..1f5369a --- /dev/null +++ b/docs/step-action-build.adoc @@ -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. + +|=== diff --git a/docs/build.adoc b/docs/task-build.adoc similarity index 92% rename from docs/build.adoc rename to docs/task-build.adoc index 908fdac..3800ad9 100644 --- a/docs/build.adoc +++ b/docs/task-build.adoc @@ -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 diff --git a/go.mod b/go.mod index 7b6e83a..748b5bf 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 5e20987..508bf41 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/step-actions/build.yaml b/step-actions/build.yaml index aaca9e2..021dc88 100644 --- a/step-actions/build.yaml +++ b/step-actions/build.yaml @@ -1,4 +1,5 @@ # File is generated; DO NOT EDIT. + apiVersion: tekton.dev/v1alpha1 kind: StepAction metadata: @@ -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 @@ -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. @@ -95,4 +100,4 @@ spec: name: $(params.private-cert) readOnly: true subPath: tls.crt - workingDir: $(params.source) + workingDir: $(params.workspace) diff --git a/tasks/build.yaml b/tasks/build.yaml index 45c10e1..90bb78b 100644 --- a/tasks/build.yaml +++ b/tasks/build.yaml @@ -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: | @@ -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.