Skip to content

Commit f0e1e64

Browse files
stackit-skexoxys
andauthored
[release-v1.31] Add make variable IS_DEV to control oci image suffix (#45)
* Add make variable IS_DEV to control oci image suffix * fix shellcheck --------- Co-authored-by: Robert Kaussow <[email protected]>
1 parent a5f3ecf commit f0e1e64

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ SHELL = /usr/bin/env bash -o pipefail
44
.SHELLFLAGS = -ec
55
BUILD_IMAGES ?= stackit-csi-plugin cloud-controller-manager
66
SOURCES := Makefile go.mod go.sum $(shell find $(DEST) -name '*.go' 2>/dev/null)
7-
VERSION ?= $(shell git describe --dirty --tags --match='v*')
7+
VERSION ?= $(shell git describe --dirty --tags --match='v*' 2>/dev/null || git rev-parse --short HEAD)
88
REGISTRY ?= ghcr.io
9-
REPO ?= stackitcloud/cloud-provider-stackit-dev
9+
REPO ?= stackitcloud/cloud-provider-stackit
1010
PLATFORMS ?= amd64 arm64
11+
IS_DEV ?= true
1112

1213
.PHONY: all
1314
all: verify
@@ -42,6 +43,7 @@ image-%: $(APKO) $(KO)
4243
PLATFORMS="$(PLATFORMS)" \
4344
REGISTRY=$(REGISTRY) \
4445
REPO=$(REPO)/$* \
46+
IS_DEV=$(IS_DEV) \
4547
./hack/build.sh $*
4648

4749
.PHONY: clean-tools-bin

hack/build.sh

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if [[ -z ${LOCAL} ]]; then
1919
LOCAL="false"
2020
fi
2121

22-
function comma_seperated() {
22+
function comma_separated() {
2323
local arr=("$@")
2424
local IFS=,
2525
echo "${arr[*]}"
@@ -35,9 +35,9 @@ fi
3535
# generate a tag that renovate can easily compare (similar to prow's image tags)
3636
# format: v<commit-timestamp>-<short-commit-sha>
3737
tags=(
38-
"v$(date -d @$(git show -s --format=%ct @) -u +%Y%m%d%H%M%S)-$(git rev-parse HEAD | head -c7)"
39-
${VERSION}
40-
$(echo ${PULL_BASE_REF} | sed 's/\//_/g' | sed 's/#//g')
38+
"v$(date -d @"$(git show -s --format=%ct @)" -u +%Y%m%d%H%M%S)-$(git rev-parse HEAD | head -c7)"
39+
"${VERSION}"
40+
"$(echo "${PULL_BASE_REF}" | sed 's/\//_/g' | sed 's/#//g')"
4141
)
4242

4343
if [[ -n "${PULL_NUMBER:=""}" ]]; then
@@ -49,21 +49,24 @@ if git_tag="$(git describe --tags --exact-match 2>/dev/null)"; then
4949
tags+=("$git_tag")
5050
fi
5151

52+
if [[ ${IS_DEV} == "true" ]]; then
53+
REPO=${REPO}-dev
54+
fi
5255
BASE_IMAGE=${REGISTRY}/${REPO}-base
53-
platforms=(${PLATFORMS})
56+
IFS=' ' read -r -a platforms <<< "${PLATFORMS}"
5457
if [[ -f cmd/$IMAGE/apko-base-image.yaml ]]; then
5558
if [[ ${LOCAL} == "true" ]]; then
5659
BASE_IMAGE=ko.local/${IMAGE}-base
57-
platforms=($(uname -m))
60+
mapfile -t platforms < <(uname -m)
5861
fi
5962

60-
APKO_IMAGE=$(apko publish --local=${LOCAL} cmd/${IMAGE}/apko-base-image.yaml ${BASE_IMAGE} --sbom=false -p "${APKO_EXTRA_PACKAGES}" --arch $(comma_seperated "${platforms[@]}"))
63+
APKO_IMAGE=$(apko publish --local="${LOCAL}" "cmd/${IMAGE}/apko-base-image.yaml" "${BASE_IMAGE}" --sbom=false -p "${APKO_EXTRA_PACKAGES}" --arch "$(comma_separated "${platforms[@]}")")
6164
export KO_DEFAULTBASEIMAGE=${APKO_IMAGE}
6265
if [[ ${LOCAL} == "true" ]]; then
6366
# apko only published images to registry apko.local with repo cache when running in local mode.
6467
# Need to tag to registry ko.local for ko to see that the image needs to be resolved locally
6568
# will be fixed in https://github.com/chainguard-dev/apko/pull/1781
66-
docker tag ${APKO_IMAGE} ${BASE_IMAGE}
69+
docker tag "${APKO_IMAGE}" "${BASE_IMAGE}"
6770
export KO_DEFAULTBASEIMAGE=${BASE_IMAGE}
6871
fi
6972
fi
@@ -76,16 +79,16 @@ done
7679

7780
labels=(
7881
org.opencontainers.image.created="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
79-
org.opencontainers.image.revision=${VERSION}
82+
org.opencontainers.image.revision="${VERSION}"
8083
org.opencontainers.image.source=https://github.com/stackitcloud/cloud-provider-stackit
8184
org.opencontainers.image.url=https://github.com/stackitcloud/cloud-provider-stackit
8285
)
8386

8487
KO_DOCKER_REPO=${REGISTRY}/${REPO} \
85-
ko build --local=${LOCAL} \
86-
-t $(comma_seperated "${tags[@]}") \
88+
ko build --local="${LOCAL}" \
89+
-t "$(comma_separated "${tags[@]}")" \
8790
--sbom=none \
88-
--platform $(comma_seperated "${ko_platforms[@]}") \
91+
--platform "$(comma_separated "${ko_platforms[@]}")" \
8992
--bare \
90-
--image-label=$(comma_seperated "${labels[@]}") \
91-
./cmd/$IMAGE
93+
--image-label="$(comma_separated "${labels[@]}")" \
94+
"./cmd/$IMAGE"

0 commit comments

Comments
 (0)