Skip to content
This repository was archived by the owner on Oct 5, 2021. It is now read-only.

Commit b16967e

Browse files
author
Utkarsh Mani Tripathi
authored
refact(build): make the docker images configurable (#23)
* refact(build): make the docker images configurable * chore(makefile): change REGISTRY to IMAGE_ORG Signed-off-by: Utkarsh Mani Tripathi <[email protected]>
1 parent 1ddf5c9 commit b16967e

File tree

3 files changed

+112
-21
lines changed

3 files changed

+112
-21
lines changed

Makefile

Lines changed: 77 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,75 @@
1+
# Copyright 2018-2020 The OpenEBS Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
# The images can be pushed to any docker/image registeries
17+
# like docker hub, quay. The registries are specified in
18+
# the `build/push` script.
19+
#
20+
# The images of a project or company can then be grouped
21+
# or hosted under a unique organization key like `openebs`
22+
#
23+
# Each component (container) will be pushed to a unique
24+
# repository under an organization.
25+
# Putting all this together, an unique uri for a given
26+
# image comprises of:
27+
# <registry url>/<image org>/<image repo>:<image-tag>
28+
#
29+
# IMAGE_ORG can be used to customize the organization
30+
# under which images should be pushed.
31+
# By default the organization name is `openebs`.
32+
133
# Output registry and image names for operator image
234
# Set env to override this value
3-
ifeq (${REGISTRY}, )
4-
REGISTRY:=openebs
35+
ifeq (${IMAGE_ORG}, )
36+
IMAGE_ORG:=openebs
37+
endif
38+
export IMAGE_ORG
39+
40+
# Determine the arch/os
41+
ifeq (${XC_OS}, )
42+
XC_OS:=$(shell go env GOOS)
543
endif
6-
export REGISTRY
44+
export XC_OS
45+
46+
ifeq (${XC_ARCH}, )
47+
XC_ARCH:=$(shell go env GOARCH)
48+
endif
49+
export XC_ARCH
50+
51+
ARCH:=${XC_OS}_${XC_ARCH}
52+
export ARCH
753

54+
# Specify the docker arg for repository url
55+
ifeq (${DBUILD_REPO_URL}, )
56+
DBUILD_REPO_URL="https://github.com/openebs/jiva-csi"
57+
export DBUILD_REPO_URL
58+
endif
59+
60+
# Specify the docker arg for website url
61+
ifeq (${DBUILD_SITE_URL}, )
62+
DBUILD_SITE_URL="https://openebs.io"
63+
export DBUILD_SITE_URL
64+
endif
65+
66+
DBUILD_DATE ?= $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
867
# Output plugin name and its image name and tag
968
PLUGIN_NAME=jiva-csi
1069
PLUGIN_TAG=ci
1170

71+
export DBUILD_ARGS=--build-arg DBUILD_DATE=${DBUILD_DATE} --build-arg DBUILD_REPO_URL=${DBUILD_REPO_URL} --build-arg DBUILD_SITE_URL=${DBUILD_SITE_URL} --build-arg ARCH=${ARCH}
72+
1273
# Tools required for different make targets or for development purposes
1374
EXTERNAL_TOOLS=\
1475
golang.org/x/tools/cmd/cover \
@@ -40,20 +101,19 @@ endif
40101

41102
PACKAGES = $(shell go list ./... | grep -v 'vendor')
42103

43-
DATETIME ?= $(shell date +'%F_%T')
44104
LDFLAGS ?= \
45105
-extldflags "-static" \
46106
-X github.com/openebs/jiva-csi/version/version.Version=${VERSION} \
47107
-X github.com/openebs/jiva-csi/version/version.Commit=${COMMIT} \
48-
-X github.com/openebs/jiva-csi/version/version.DateTime=${DATETIME}
108+
-X github.com/openebs/jiva-csi/version/version.DateTime=${DBUILD_DATE}
49109

50110

51111
.PHONY: help
52112
help:
53113
@echo "Available commands:"
54114
@echo " build - build csi source code"
55115
@echo " image - build csi container image"
56-
@echo " push - push csi to dockerhub registry (${REGISTRY})"
116+
@echo " push - push csi to dockerhub registry (${IMAGE_ORG})"
57117
@echo ""
58118
@make print-variables --no-print-directory
59119

@@ -66,7 +126,7 @@ print-variables:
66126
@echo " COMMIT: ${COMMIT}"
67127
@echo "Testing variables:"
68128
@echo " Produced Image: ${PLUGIN_NAME}:${PLUGIN_TAG}"
69-
@echo " REGISTRY: ${REGISTRY}"
129+
@echo " IMAGE_ORG: ${IMAGE_ORG}"
70130

71131
# Bootstrap the build by downloading additional tools
72132
bootstrap:
@@ -103,24 +163,24 @@ build: deps test
103163
GOOS=linux go build -a -ldflags '$(LDFLAGS)' -o ./build/bin/$(PLUGIN_NAME) ./cmd/csi/main.go
104164

105165
image: build
106-
@echo "--> Build image $(REGISTRY)/$(PLUGIN_NAME):$(PLUGIN_TAG) ..."
107-
docker build -f ./build/Dockerfile -t $(REGISTRY)/$(PLUGIN_NAME):$(PLUGIN_TAG) .
166+
@echo "--> Build image $(IMAGE_ORG)/$(PLUGIN_NAME):$(PLUGIN_TAG) ..."
167+
docker build -f ./build/Dockerfile -t $(IMAGE_ORG)/$(PLUGIN_NAME):$(PLUGIN_TAG) $(DBUILD_ARGS) .
108168

109169
push-image: image
110-
@echo "--> Push image $(REGISTRY)/$(PLUGIN_NAME):$(PLUGIN_TAG) ..."
111-
docker push $(REGISTRY)/$(PLUGIN_NAME):$(PLUGIN_TAG)
170+
@echo "--> Push image $(IMAGE_ORG)/$(PLUGIN_NAME):$(PLUGIN_TAG) ..."
171+
docker push $(IMAGE_ORG)/$(PLUGIN_NAME):$(PLUGIN_TAG)
112172

113173
push:
114-
@echo "--> Push image $(REGISTRY)/$(PLUGIN_NAME):$(PLUGIN_TAG) ..."
115-
@DIMAGE=$(REGISTRY)/$(PLUGIN_NAME) ./build/push
174+
@echo "--> Push image $(IMAGE_ORG)/$(PLUGIN_NAME):$(PLUGIN_TAG) ..."
175+
@DIMAGE=$(IMAGE_ORG)/$(PLUGIN_NAME) ./build/push
116176

117177
tag:
118-
@echo "--> Tag image $(REGISTRY)/$(PLUGIN_NAME):$(PLUGIN_TAG) to $(REGISTRY)/$(PLUGIN_NAME):$(GIT_TAG) ..."
119-
docker tag $(REGISTRY)/$(PLUGIN_NAME):$(PLUGIN_TAG) $(REGISTRY)/$(PLUGIN_NAME):$(GIT_TAG)
178+
@echo "--> Tag image $(IMAGE_ORG)/$(PLUGIN_NAME):$(PLUGIN_TAG) to $(IMAGE_ORG)/$(PLUGIN_NAME):$(GIT_TAG) ..."
179+
docker tag $(IMAGE_ORG)/$(PLUGIN_NAME):$(PLUGIN_TAG) $(IMAGE_ORG)/$(PLUGIN_NAME):$(GIT_TAG)
120180

121181
push-tag: tag push
122-
@echo "--> Push image $(REGISTRY)/$(PLUGIN_NAME):$(GIT_TAG) ..."
123-
docker push $(REGISTRY)/$(PLUGIN_NAME):$(GIT_TAG)
182+
@echo "--> Push image $(IMAGE_ORG)/$(PLUGIN_NAME):$(GIT_TAG) ..."
183+
docker push $(IMAGE_ORG)/$(PLUGIN_NAME):$(GIT_TAG)
124184

125185
clean:
126186
rm -rf ./build/bin/

build/Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
1+
# Copyright 2019-2020 The OpenEBS Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
FROM ubuntu:18.04
216
RUN apt-get update; exit 0
317
RUN apt-get -y install rsyslog xfsprogs curl
418
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
519

620
COPY build/bin/jiva-csi /usr/local/bin/
721

22+
ARG DBUILD_DATE
23+
ARG DBUILD_REPO_URL
24+
ARG DBUILD_SITE_URL
25+
ARG ARCH
26+
27+
LABEL org.label-schema.schema-version="1.0"
28+
LABEL org.label-schema.name="jiva-csi"
29+
LABEL org.label-schema.description="OpenEBS Jiva CSI Plugin"
30+
LABEL org.label-schema.build-date=$DBUILD_DATE
31+
LABEL org.label-schema.vcs-url=$DBUILD_REPO_URL
32+
LABEL org.label-schema.url=$DBUILD_SITE_URL
33+
LABEL org.label-schema.arch=$ARCH
34+
835
ENTRYPOINT ["/usr/local/bin/jiva-csi"]

build/push

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ echo "Set the build/unique image tag as: ${BUILD_TAG}"
4141
function TagAndPushImage() {
4242
REPO="$1"
4343
TAG="$2"
44-
45-
IMAGE_URI="${REPO}:${TAG}";
44+
#Add an option to specify a custom TAG_SUFFIX
45+
#via environment variable. Default is no tag.
46+
#Example suffix could be "-debug" of "-dev"
47+
IMAGE_URI="${REPO}:${TAG}${TAG_SUFFIX}";
4648
sudo docker tag ${IMAGEID} ${IMAGE_URI};
4749
echo " push ${IMAGE_URI}";
4850
sudo docker push ${IMAGE_URI};
@@ -65,7 +67,8 @@ then
6567
# Push with different tags if tagged as a release
6668
# When github is tagged with a release, then Travis will
6769
# set the release tag in env TRAVIS_TAG
68-
TagAndPushImage "${DIMAGE}" "${TRAVIS_TAG}"
70+
# Trim `v` from the TRAVIS_TAG if it exists
71+
TagAndPushImage "${DIMAGE}" "${TRAVIS_TAG#v}"
6972
TagAndPushImage "${DIMAGE}" "latest"
7073
fi;
7174
else
@@ -85,7 +88,8 @@ then
8588
# Push with different tags if tagged as a release
8689
# When github is tagged with a release, then Travis will
8790
# set the release tag in env TRAVIS_TAG
88-
TagAndPushImage "quay.io/${DIMAGE}" "${TRAVIS_TAG}"
91+
# Trim `v` from the TRAVIS_TAG if it exists
92+
TagAndPushImage "quay.io/${DIMAGE}" "${TRAVIS_TAG#v}"
8993
TagAndPushImage "quay.io/${DIMAGE}" "latest"
9094
fi;
9195
else

0 commit comments

Comments
 (0)