forked from shipwright-io/build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildstrategy_ko_cr.yaml
116 lines (107 loc) · 4.4 KB
/
buildstrategy_ko_cr.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
---
apiVersion: shipwright.io/v1beta1
kind: ClusterBuildStrategy
metadata:
name: ko
spec:
parameters:
- name: go-flags
description: "Value for the GOFLAGS environment variable."
default: ""
- name: go-version
description: "Version of Go, must match a tag from https://hub.docker.com/_/golang?tab=tags"
default: "1.22"
- name: ko-version
description: "Version of ko, must be either 'latest', or a release name from https://github.com/ko-build/ko/releases"
default: latest
- name: package-directory
description: "The directory inside the context directory containing the main package."
default: "."
- name: target-platform
description: "Target platform to be built. For example: 'linux/arm64'. Multiple platforms can be provided separated by comma, for example: 'linux/arm64,linux/amd64'. The value 'all' will build all platforms supported by the base image. The value 'current' will build the platform on which the build runs."
default: current
volumes:
- name: gocache
description: "Volume to contain the GOCACHE. Can be set to a persistent volume to optimize compilation performance for rebuilds."
overridable: true
emptyDir: {}
steps:
- name: build
image: golang:$(params.go-version)
imagePullPolicy: Always
workingDir: $(params.shp-source-root)
volumeMounts:
- mountPath: /gocache
name: gocache
readOnly: false
env:
- name: DOCKER_CONFIG
value: /tekton/home/.docker
- name: HOME
value: /tekton/home
- name: GOFLAGS
value: $(params.go-flags)
- name: GOCACHE
value: /gocache
- name: PARAM_OUTPUT_IMAGE
value: $(params.shp-output-image)
- name: PARAM_OUTPUT_DIRECTORY
value: $(params.shp-output-directory)
- name: PARAM_SOURCE_CONTEXT
value: $(params.shp-source-context)
- name: PARAM_SOURCE_ROOT
value: $(params.shp-source-root)
- name: PARAM_TARGET_PLATFORM
value: $(params.target-platform)
- name: PARAM_PACKAGE_DIRECTORY
value: $(params.package-directory)
- name: PARAM_KO_VERSION
value: $(params.ko-version)
command:
- /bin/bash
args:
- -c
- |
set -euo pipefail
# Determine the ko version
KO_VERSION="${PARAM_KO_VERSION}"
if [ "${KO_VERSION}" == "latest" ]; then
KO_VERSION=$(curl --silent "https://api.github.com/repos/ko-build/ko/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
fi
# Create one variable with v-suffix and one without as we need both for the download URL
if [[ ${KO_VERSION} = v* ]]; then
KO_VERSION_WITH_V=${KO_VERSION}
KO_VERSION_WITHOUT_V=${KO_VERSION:1}
else
KO_VERSION_WITH_V=v${KO_VERSION}
KO_VERSION_WITHOUT_V=${KO_VERSION}
fi
# Download ko to the temp directory
curl -f -s -L "https://github.com/ko-build/ko/releases/download/${KO_VERSION_WITH_V}/ko_${KO_VERSION_WITHOUT_V}_$(uname)_$(uname -m | sed 's/aarch64/arm64/').tar.gz" | tar xzf - -C /tmp ko
# Determine the platform
PLATFORM="${PARAM_TARGET_PLATFORM}"
if [ "${PLATFORM}" == "current" ]; then
PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')/$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')"
fi
# Print version information
go version
echo "ko version $(/tmp/ko version)"
# Allow directory to be owned by other user which is normal for a volume-mounted directory.
# This allows Go to run git commands to access repository metadata.
# Documentation: https://git-scm.com/docs/git-config/2.39.0#Documentation/git-config.txt-safedirectory
git config --global --add safe.directory "${PARAM_SOURCE_ROOT}"
# Run ko
export GOROOT="$(go env GOROOT)"
pushd "${PARAM_SOURCE_CONTEXT}" > /dev/null
/tmp/ko build "${PARAM_PACKAGE_DIRECTORY}" --oci-layout-path="${PARAM_OUTPUT_DIRECTORY}" --platform="${PLATFORM}" --push=false
popd > /dev/null
resources:
limits:
cpu: 500m
memory: 1Gi
requests:
cpu: 250m
memory: 65Mi
securityContext:
runAsUser: 1000
runAsGroup: 1000