Skip to content

Commit

Permalink
Add/use hack/release.sh script for images
Browse files Browse the repository at this point in the history
This patch adds a hack/release.sh script and dependencies, and follows
the same release practice as CAPV. This changes the location of the
container images, mainly splitting the latest builds from master versus
a release channel just for releases. A separate doc update needs to be
made for this as well.
  • Loading branch information
codenrhoden committed Jul 24, 2019
1 parent b4e067e commit 65aa0a5
Show file tree
Hide file tree
Showing 4 changed files with 336 additions and 62 deletions.
56 changes: 8 additions & 48 deletions Makefile
Expand Up @@ -52,16 +52,9 @@ deps:
# Ensure the version is injected into the binaries via a linker flag.
export VERSION ?= $(shell git describe --always --dirty)

# Load the image registry include.
include hack/make/login-to-image-registry.mk

# Define the images.
IMAGE_CSI := $(REGISTRY)/vsphere-csi
.PHONY: print-image

# Printing the image version is defined early so Go modules aren't forced.
print-image:
@echo $(IMAGE_CSI):$(VERSION)
.PHONY: version
version:
@echo $(VERSION)

################################################################################
## BUILD DIRS ##
Expand Down Expand Up @@ -127,7 +120,6 @@ dist: dist-csi-tgz dist-csi-zip
deploy: | $(DOCKER_SOCK)
$(MAKE) build-bins
$(MAKE) unit-test
$(MAKE) build-images
$(MAKE) push-images

################################################################################
Expand Down Expand Up @@ -243,33 +235,16 @@ check: fmt vet lint
################################################################################
## BUILD IMAGES ##
################################################################################
IMAGE_CSI_D := image-csi-$(VERSION).d
build-csi-image csi-image: $(IMAGE_CSI_D)
$(IMAGE_CSI): $(IMAGE_CSI_D)
ifneq ($(GOOS),linux)
$(IMAGE_CSI_D):
$(error Please set GOOS=linux for building $@)
else
$(IMAGE_CSI_D): $(CSI_BIN) | $(DOCKER_SOCK)
cp -f $< cluster/images/csi/vsphere-csi
docker build -t $(IMAGE_CSI):$(VERSION) cluster/images/csi
docker tag $(IMAGE_CSI):$(VERSION) $(IMAGE_CSI):latest
@rm -f cluster/images/csi/vsphere-csi && touch $@
endif

build-images images: build-csi-image
.PHONY: images
images: | $(DOCKER_SOCK)
hack/release.sh

################################################################################
## PUSH IMAGES ##
################################################################################
.PHONY: push-$(IMAGE_CSI) upload-$(IMAGE_CSI)
push-csi-image upload-csi-image: upload-$(IMAGE_CSI)
push-$(IMAGE_CSI) upload-$(IMAGE_CSI): $(IMAGE_CSI_D) login-to-image-registry | $(DOCKER_SOCK)
docker push $(IMAGE_CSI):$(VERSION)
docker push $(IMAGE_CSI):latest

.PHONY: push-images upload-images
push-images upload-images: upload-csi-image
push-images: | $(DOCKER_SOCK)
hack/release.sh -p

################################################################################
## CI IMAGE ##
Expand All @@ -282,18 +257,3 @@ push-ci-image:

print-ci-image:
@$(MAKE) --no-print-directory -C hack/images/ci print

################################################################################
## PRINT VERISON ##
################################################################################
.PHONY: version
version:
@echo $(VERSION)

################################################################################
## TODO(akutz) ##
################################################################################
TODO := docs godoc releasenotes translation
.PHONY: $(TODO)
$(TODO):
@echo "$@ not yet implemented"
42 changes: 28 additions & 14 deletions cluster/images/csi/Dockerfile
@@ -1,16 +1,30 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM photon:2.0
################################################################################
## BUILD ARGS ##
################################################################################
# This build arg allows the specification of a custom Golang image.
ARG GOLANG_IMAGE=golang:1.12.6

# This build arg allows the specification of a custom Photon image.
ARG PHOTON_IMAGE=photon:2.0

################################################################################
## BUILD STAGE ##
################################################################################
# Build the manager as a statically compiled binary so it has no dependencies
# libc, muscl, etc.
FROM ${GOLANG_IMAGE} as builder
WORKDIR /build
COPY go.mod go.sum ./
COPY pkg/ pkg/
COPY cmd/ cmd/
ENV CGO_ENABLED=0
RUN go build -a -ldflags='-w -s -extldflags="static"' -o vsphere-csi ./cmd/vsphere-csi

################################################################################
## MAIN STAGE ##
################################################################################
FROM ${PHOTON_IMAGE}
LABEL "maintainer" "Travis Rhoden <trhoden@vmware.com>"

RUN tdnf -y remove toybox

Expand All @@ -22,6 +36,6 @@ RUN tdnf -y install \

RUN tdnf clean all

ADD vsphere-csi /bin/
COPY --from=builder /build/vsphere-csi /bin/vsphere-csi

CMD ["/bin/vsphere-csi"]
108 changes: 108 additions & 0 deletions hack/match-release-tag.sh
@@ -0,0 +1,108 @@
#!/bin/bash

# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

# Change directories to the parent directory of the one in which this
# script is located.
cd "$(dirname "${BASH_SOURCE[0]}")/.."

usage() {
cat <<EOF
usage: ${0} [TAG]
Verifies the provided tag is a release tag.
TAG
If no tag is provided then "git describe --dirty" is used to obtain the tag.
FLAGS
-h prints this help screen
-x run the examples
EOF
}

while getopts ':hx' opt; do
case "${opt}" in
h)
usage 1>&2; exit 1
;;
x)
EXAMPLES=1
;;
\?)
{ echo "invalid option: -${OPTARG}"; usage; } 1>&2; exit 1
;;
:)
echo "option -${OPTARG} requires an argument" 1>&2; exit 1
;;
esac
done
shift $((OPTIND-1))

# The regular expression matches the following strings:
# * v1.0.0-alpha.0
# * v1.0.0-beta.0
# * v1.0.0-rc.0
# * v1.0.0
# Any occurence of a digit in the above examples may be multiple digits.
REGEX='^[[:space:]]{0,}v[[:digit:]]{1,}\.[[:digit:]]{1,}\.[[:digit:]]{1,}(-(alpha|beta|rc)\.[[:digit:]]{1,}){0,1}[[:space:]]{0,}$'

# Match the tag against the regular expression for a release tag.
match() {
if [[ ${1} =~ ${REGEX} ]]; then
echo "yay: ${1}"
else
exit_code="${?}"
echo "nay: ${1}"
return "${exit_code}"
fi
}

# Run examples to illustrate valid and invalid values.
examples() {
local semvers=" \
v1.0.0-alpha.0 \
v1.0.0-beta.0 \
v1.0.0-rc.0 \
v1.0.0 \
v10.0.0 \
v1.10.0 \
v1.0.10 \
v10.0.0-alpha.10 \
v1.10.0-beta.10 \
v1.0.10-rc.10 \
1.0.0 \
v1.0.0+rc.0 \
v10a.0.0 \
1.1.0-alpha.1 \
v1.0.0-alpha.0a"
set +o errexit
for v in ${semvers}; do match "${v}"; done
return 0
}

main() {
# Get the tag from the remaining arguments or from "git describe --dirty"
[ "${#}" -eq "0" ] || tag="${1}"
[ -n "${tag-}" ] || tag="$(git describe --dirty)"

# Match the tag against the regular expression for a release tag.
match "${tag}" 1>&2
}

{ [ "${EXAMPLES-}" ] && examples; } || main "${@-}"

0 comments on commit 65aa0a5

Please sign in to comment.