3030 fi
3131 PROJECT_DIR_NAME :
3232 sh : basename "$PWD"
33+
34+ # Container metadata
35+ DOCKER_IMAGE : ' {{.DOCKER_IMAGE | default .PROJECT_DIR_NAME}}'
36+ GITHUB_REPO : ' {{.GITHUB_REPO | default .PROJECT_DIR_NAME}}'
37+ DOCKER_ORG_NAME : ' {{.DOCKER_ORG_NAME | default "devopsinfra"}}'
38+ GITHUB_ORG_NAME : ' {{.GITHUB_ORG_NAME | default "devops-infra"}}'
39+ DOCKER_USERNAME : ' {{.DOCKER_USERNAME | default "christophshyper"}}'
40+ GITHUB_USERNAME : ' {{.GITHUB_USERNAME | default "ChristophShyper"}}'
41+ DOCKER_NAME : ' {{.DOCKER_ORG_NAME}}/{{.DOCKER_IMAGE}}'
42+ GITHUB_NAME : ' {{.GITHUB_ORG_NAME}}/{{.GITHUB_REPO}}'
43+ GHRC_NAME : ghcr.io/{{.GITHUB_ORG_NAME}}/{{.GITHUB_REPO}}
44+ DEFAULT_BRANCH : master
45+ VERSION_FROM_ACTION_YML :
46+ sh : ' grep "image: docker://{{.DOCKER_NAME}}:" action.yml 2>/dev/null | cut -d ":" -f 4'
47+ AUTHOR_FROM_ACTION_YML :
48+ sh : |
49+ grep -e "^author:" action.yml 2>/dev/null | head -1 | awk -F": " '{print $2}'
50+ NAME_FROM_ACTION_YML :
51+ sh : |
52+ grep -e "^name:" action.yml 2>/dev/null | head -1 | awk -F": " '{print $2}'
53+ DESCRIPTION_FROM_ACTION_YML :
54+ sh : |
55+ grep -e "^description:" action.yml 2>/dev/null | head -1 | awk -F": " '{print $2}'
56+ LABEL_AUTHOR : ' {{.LABEL_AUTHOR | default .AUTHOR_FROM_ACTION_YML}}'
57+ LABEL_NAME : ' {{.LABEL_NAME | default .NAME_FROM_ACTION_YML}}'
58+ LABEL_DESCRIPTION : ' {{.LABEL_DESCRIPTION | default .DESCRIPTION_FROM_ACTION_YML}}'
59+ LABEL_REPO_URL : ' {{ default (printf "https://github.com/%s/%s" .GITHUB_ORG_NAME .DOCKER_IMAGE) .LABEL_REPO_URL }}'
60+ LABEL_DOCS_URL : >-
61+ {{ default (printf "https://github.com/%s/%s/blob/%s/README.md" .GITHUB_ORG_NAME .DOCKER_IMAGE
62+ .DEFAULT_BRANCH) .LABEL_DOCS_URL }}
63+ LABEL_HOMEPAGE : ' {{.LABEL_HOMEPAGE | default "https://shyper.pro"}}'
64+ LABEL_VENDOR : ' {{.LABEL_VENDOR | default "DevOps-Infra"}}'
65+ LABEL_LICENSE : ' {{.LABEL_LICENSE | default "MIT"}}'
66+
67+ # Build context
68+ CONTEXT : ' {{.CONTEXT | default "."}}'
69+ DOCKERFILE : ' {{.DOCKERFILE | default "Dockerfile"}}'
70+ PLATFORMS : ' {{.PLATFORMS | default "linux/amd64,linux/arm64"}}'
71+ BUILD_DATE :
72+ sh : date -u +"%Y-%m-%dT%H:%M:%SZ"
73+ LAST_RELEASE :
74+ sh : |
75+ curl --silent "https://api.github.com/repos/{{.GITHUB_ORG_NAME}}/{{.GITHUB_REPO}}/releases/latest" | \
76+ grep '"tag_name":' | \
77+ {{.SED}} -E 's/.*"([^"]+)".*/\1/'
78+ VERSION_SUFFIX :
79+ sh : |
80+ if [ "${VERSION_SUFFIX+x}" = "x" ]; then
81+ printf "%s" "${VERSION_SUFFIX}"
82+ else
83+ printf "%s" "-test"
84+ fi
3385 VERSION_OVERRIDE :
3486 sh : echo "${VERSION_OVERRIDE:-}"
3587 VERSION :
@@ -38,11 +90,13 @@ vars:
3890 if [ -n "$override" ]; then
3991 echo "$override"
4092 else
41- latest_tag="$(git tag --sort=-v:refname 2>/dev/null | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1)"
42- if [ -n "$latest_tag" ]; then
43- echo "$latest_tag"
93+ tag="$(git tag --sort=-v:refname 2>/dev/null | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1)"
94+ if [ -n "$tag" ]; then
95+ echo "$tag"
96+ elif [ -n "{{.VERSION_FROM_ACTION_YML}}" ]; then
97+ echo "{{.VERSION_FROM_ACTION_YML}}"
4498 else
45- echo "v0.0.0 "
99+ echo "{{.LAST_RELEASE}} "
46100 fi
47101 fi
48102 VERSION_NO_V :
@@ -62,3 +116,105 @@ vars:
62116 sh : echo $(( {{.MINOR}} + 1 ))
63117 NEXT_MAJOR :
64118 sh : echo $(( {{.MAJOR}} + 1 ))
119+ MAJOR_FROM_ACTION_YML :
120+ sh : echo "{{.VERSION_FROM_ACTION_YML}}" | awk -F\. '{print $1}'
121+ MINOR_FROM_ACTION_YML :
122+ sh : echo "{{.VERSION_FROM_ACTION_YML}}" | awk -F\. '{print $1"."$2}'
123+
124+ # Git metadata
125+ GIT_SHA :
126+ sh : git rev-parse HEAD 2>/dev/null || echo 0000000000000000000000000000000000000000
127+ GIT_SHORT_SHA :
128+ sh : git rev-parse --short HEAD 2>/dev/null || echo 0000000
129+ GIT_BRANCH :
130+ sh : |
131+ if [ -n "${GITHUB_REF:-}" ]; then
132+ echo "${GITHUB_REF#refs/heads/}"
133+ else
134+ git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown"
135+ fi
136+
137+ # Labels for http://label-schema.org/rc1/#build-time-labels
138+ # And for https://github.com/opencontainers/image-spec/blob/master/annotations.md
139+ ANNOTATIONS : >-
140+ --annotation index:org.label-schema.schema-version="1.0"
141+ --annotation index:org.label-schema.build-date="{{.BUILD_DATE}}"
142+ --annotation index:org.label-schema.name="{{.LABEL_NAME}}"
143+ --annotation index:org.label-schema.description="{{.LABEL_DESCRIPTION}}"
144+ --annotation index:org.label-schema.usage="{{.LABEL_DOCS_URL}}"
145+ --annotation index:org.label-schema.url="{{.LABEL_HOMEPAGE}}"
146+ --annotation index:org.label-schema.vcs-url="{{.LABEL_REPO_URL}}"
147+ --annotation index:org.label-schema.vcs-ref="{{.GIT_SHA}}"
148+ --annotation index:org.label-schema.vendor="{{.LABEL_VENDOR}}"
149+ --annotation index:org.label-schema.version="{{.VERSION_FULL}}{{.VERSION_SUFFIX}}"
150+ --annotation index:org.opencontainers.image.created="{{.BUILD_DATE}}"
151+ --annotation index:org.opencontainers.image.authors="{{.LABEL_AUTHOR}}"
152+ --annotation index:org.opencontainers.image.url="{{.LABEL_HOMEPAGE}}"
153+ --annotation index:org.opencontainers.image.documentation="{{.LABEL_DOCS_URL}}"
154+ --annotation index:org.opencontainers.image.source="{{.LABEL_REPO_URL}}"
155+ --annotation index:org.opencontainers.image.version="{{.VERSION_FULL}}{{.VERSION_SUFFIX}}"
156+ --annotation index:org.opencontainers.image.revision="{{.GIT_SHA}}"
157+ --annotation index:org.opencontainers.image.vendor="{{.LABEL_VENDOR}}"
158+ --annotation index:org.opencontainers.image.licenses="{{.LABEL_LICENSE}}"
159+ --annotation index:org.opencontainers.image.title="{{.LABEL_NAME}}"
160+ --annotation index:org.opencontainers.image.description="{{.LABEL_DESCRIPTION}}"
161+ --annotation manifest:org.label-schema.schema-version="1.0"
162+ --annotation manifest:org.label-schema.build-date="{{.BUILD_DATE}}"
163+ --annotation manifest:org.label-schema.name="{{.LABEL_NAME}}"
164+ --annotation manifest:org.label-schema.description="{{.LABEL_DESCRIPTION}}"
165+ --annotation manifest:org.label-schema.usage="{{.LABEL_DOCS_URL}}"
166+ --annotation manifest:org.label-schema.url="{{.LABEL_HOMEPAGE}}"
167+ --annotation manifest:org.label-schema.vcs-url="{{.LABEL_REPO_URL}}"
168+ --annotation manifest:org.label-schema.vcs-ref="{{.GIT_SHA}}"
169+ --annotation manifest:org.label-schema.vendor="{{.LABEL_VENDOR}}"
170+ --annotation manifest:org.label-schema.version="{{.VERSION_FULL}}{{.VERSION_SUFFIX}}"
171+ --annotation manifest:org.opencontainers.image.created="{{.BUILD_DATE}}"
172+ --annotation manifest:org.opencontainers.image.authors="{{.LABEL_AUTHOR}}"
173+ --annotation manifest:org.opencontainers.image.url="{{.LABEL_HOMEPAGE}}"
174+ --annotation manifest:org.opencontainers.image.documentation="{{.LABEL_DOCS_URL}}"
175+ --annotation manifest:org.opencontainers.image.source="{{.LABEL_REPO_URL}}"
176+ --annotation manifest:org.opencontainers.image.version="{{.VERSION_FULL}}{{.VERSION_SUFFIX}}"
177+ --annotation manifest:org.opencontainers.image.revision="{{.GIT_SHA}}"
178+ --annotation manifest:org.opencontainers.image.vendor="{{.LABEL_VENDOR}}"
179+ --annotation manifest:org.opencontainers.image.licenses="{{.LABEL_LICENSE}}"
180+ --annotation manifest:org.opencontainers.image.title="{{.LABEL_NAME}}"
181+ --annotation manifest:org.opencontainers.image.description="{{.LABEL_DESCRIPTION}}"
182+ LABELS : >-
183+ --label org.label-schema.schema-version="1.0"
184+ --label org.label-schema.build-date="{{.BUILD_DATE}}"
185+ --label org.label-schema.name="{{.LABEL_NAME}}"
186+ --label org.label-schema.description="{{.LABEL_DESCRIPTION}}"
187+ --label org.label-schema.usage="{{.LABEL_DOCS_URL}}"
188+ --label org.label-schema.url="{{.LABEL_HOMEPAGE}}"
189+ --label org.label-schema.vcs-url="{{.LABEL_REPO_URL}}"
190+ --label org.label-schema.vcs-ref="{{.GIT_SHA}}"
191+ --label org.label-schema.vendor="{{.LABEL_VENDOR}}"
192+ --label org.label-schema.version="{{.VERSION_FULL}}{{.VERSION_SUFFIX}}"
193+ --label org.opencontainers.image.created="{{.BUILD_DATE}}"
194+ --label org.opencontainers.image.authors="{{.LABEL_AUTHOR}}"
195+ --label org.opencontainers.image.url="{{.LABEL_HOMEPAGE}}"
196+ --label org.opencontainers.image.documentation="{{.LABEL_DOCS_URL}}"
197+ --label org.opencontainers.image.source="{{.LABEL_REPO_URL}}"
198+ --label org.opencontainers.image.version="{{.VERSION_FULL}}{{.VERSION_SUFFIX}}"
199+ --label org.opencontainers.image.revision="{{.GIT_SHA}}"
200+ --label org.opencontainers.image.vendor="{{.LABEL_VENDOR}}"
201+ --label org.opencontainers.image.licenses="{{.LABEL_LICENSE}}"
202+ --label org.opencontainers.image.title="{{.LABEL_NAME}}"
203+ --label org.opencontainers.image.description="{{.LABEL_DESCRIPTION}}"
204+ TAGS : >-
205+ --tag {{.DOCKER_NAME}}:{{.VERSION_FULL}}{{.VERSION_SUFFIX}}
206+ --tag {{.DOCKER_NAME}}:{{.VERSION_MINOR}}{{.VERSION_SUFFIX}}
207+ --tag {{.DOCKER_NAME}}:{{.VERSION_MAJOR}}{{.VERSION_SUFFIX}}
208+ --tag {{.DOCKER_NAME}}:latest{{.VERSION_SUFFIX}}
209+ --tag {{.GHRC_NAME}}:{{.VERSION_FULL}}{{.VERSION_SUFFIX}}
210+ --tag {{.GHRC_NAME}}:{{.VERSION_MINOR}}{{.VERSION_SUFFIX}}
211+ --tag {{.GHRC_NAME}}:{{.VERSION_MAJOR}}{{.VERSION_SUFFIX}}
212+ --tag {{.GHRC_NAME}}:latest{{.VERSION_SUFFIX}}
213+ DOCKER_BUILD_START :
214+ sh : |
215+ if docker buildx version >/dev/null 2>&1; then
216+ echo "docker buildx build --platform {{.PLATFORMS}}"
217+ else
218+ echo "docker build"
219+ fi
220+ DOCKER_BUILD_FINISH : ' {{.ANNOTATIONS}} {{.LABELS}} {{.TAGS}} --file={{.DOCKERFILE}} .'
0 commit comments