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

Commit

Permalink
refact(build): make the docker images configurable (#23)
Browse files Browse the repository at this point in the history
* refact(build): make the docker images configurable
* chore(makefile): change REGISTRY to IMAGE_ORG

Signed-off-by: Utkarsh Mani Tripathi <[email protected]>
  • Loading branch information
Utkarsh Mani Tripathi authored May 7, 2020
1 parent 1ddf5c9 commit b16967e
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 21 deletions.
94 changes: 77 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,75 @@
# Copyright 2018-2020 The OpenEBS Authors. All rights reserved.
#
# 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.


# The images can be pushed to any docker/image registeries
# like docker hub, quay. The registries are specified in
# the `build/push` script.
#
# The images of a project or company can then be grouped
# or hosted under a unique organization key like `openebs`
#
# Each component (container) will be pushed to a unique
# repository under an organization.
# Putting all this together, an unique uri for a given
# image comprises of:
# <registry url>/<image org>/<image repo>:<image-tag>
#
# IMAGE_ORG can be used to customize the organization
# under which images should be pushed.
# By default the organization name is `openebs`.

# Output registry and image names for operator image
# Set env to override this value
ifeq (${REGISTRY}, )
REGISTRY:=openebs
ifeq (${IMAGE_ORG}, )
IMAGE_ORG:=openebs
endif
export IMAGE_ORG

# Determine the arch/os
ifeq (${XC_OS}, )
XC_OS:=$(shell go env GOOS)
endif
export REGISTRY
export XC_OS

ifeq (${XC_ARCH}, )
XC_ARCH:=$(shell go env GOARCH)
endif
export XC_ARCH

ARCH:=${XC_OS}_${XC_ARCH}
export ARCH

# Specify the docker arg for repository url
ifeq (${DBUILD_REPO_URL}, )
DBUILD_REPO_URL="https://github.com/openebs/jiva-csi"
export DBUILD_REPO_URL
endif

# Specify the docker arg for website url
ifeq (${DBUILD_SITE_URL}, )
DBUILD_SITE_URL="https://openebs.io"
export DBUILD_SITE_URL
endif

DBUILD_DATE ?= $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
# Output plugin name and its image name and tag
PLUGIN_NAME=jiva-csi
PLUGIN_TAG=ci

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}

# Tools required for different make targets or for development purposes
EXTERNAL_TOOLS=\
golang.org/x/tools/cmd/cover \
Expand Down Expand Up @@ -40,20 +101,19 @@ endif

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

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


.PHONY: help
help:
@echo "Available commands:"
@echo " build - build csi source code"
@echo " image - build csi container image"
@echo " push - push csi to dockerhub registry (${REGISTRY})"
@echo " push - push csi to dockerhub registry (${IMAGE_ORG})"
@echo ""
@make print-variables --no-print-directory

Expand All @@ -66,7 +126,7 @@ print-variables:
@echo " COMMIT: ${COMMIT}"
@echo "Testing variables:"
@echo " Produced Image: ${PLUGIN_NAME}:${PLUGIN_TAG}"
@echo " REGISTRY: ${REGISTRY}"
@echo " IMAGE_ORG: ${IMAGE_ORG}"

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

image: build
@echo "--> Build image $(REGISTRY)/$(PLUGIN_NAME):$(PLUGIN_TAG) ..."
docker build -f ./build/Dockerfile -t $(REGISTRY)/$(PLUGIN_NAME):$(PLUGIN_TAG) .
@echo "--> Build image $(IMAGE_ORG)/$(PLUGIN_NAME):$(PLUGIN_TAG) ..."
docker build -f ./build/Dockerfile -t $(IMAGE_ORG)/$(PLUGIN_NAME):$(PLUGIN_TAG) $(DBUILD_ARGS) .

push-image: image
@echo "--> Push image $(REGISTRY)/$(PLUGIN_NAME):$(PLUGIN_TAG) ..."
docker push $(REGISTRY)/$(PLUGIN_NAME):$(PLUGIN_TAG)
@echo "--> Push image $(IMAGE_ORG)/$(PLUGIN_NAME):$(PLUGIN_TAG) ..."
docker push $(IMAGE_ORG)/$(PLUGIN_NAME):$(PLUGIN_TAG)

push:
@echo "--> Push image $(REGISTRY)/$(PLUGIN_NAME):$(PLUGIN_TAG) ..."
@DIMAGE=$(REGISTRY)/$(PLUGIN_NAME) ./build/push
@echo "--> Push image $(IMAGE_ORG)/$(PLUGIN_NAME):$(PLUGIN_TAG) ..."
@DIMAGE=$(IMAGE_ORG)/$(PLUGIN_NAME) ./build/push

tag:
@echo "--> Tag image $(REGISTRY)/$(PLUGIN_NAME):$(PLUGIN_TAG) to $(REGISTRY)/$(PLUGIN_NAME):$(GIT_TAG) ..."
docker tag $(REGISTRY)/$(PLUGIN_NAME):$(PLUGIN_TAG) $(REGISTRY)/$(PLUGIN_NAME):$(GIT_TAG)
@echo "--> Tag image $(IMAGE_ORG)/$(PLUGIN_NAME):$(PLUGIN_TAG) to $(IMAGE_ORG)/$(PLUGIN_NAME):$(GIT_TAG) ..."
docker tag $(IMAGE_ORG)/$(PLUGIN_NAME):$(PLUGIN_TAG) $(IMAGE_ORG)/$(PLUGIN_NAME):$(GIT_TAG)

push-tag: tag push
@echo "--> Push image $(REGISTRY)/$(PLUGIN_NAME):$(GIT_TAG) ..."
docker push $(REGISTRY)/$(PLUGIN_NAME):$(GIT_TAG)
@echo "--> Push image $(IMAGE_ORG)/$(PLUGIN_NAME):$(GIT_TAG) ..."
docker push $(IMAGE_ORG)/$(PLUGIN_NAME):$(GIT_TAG)

clean:
rm -rf ./build/bin/
Expand Down
27 changes: 27 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
# Copyright 2019-2020 The OpenEBS Authors. All rights reserved.
#
# 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 ubuntu:18.04
RUN apt-get update; exit 0
RUN apt-get -y install rsyslog xfsprogs curl
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

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

ARG DBUILD_DATE
ARG DBUILD_REPO_URL
ARG DBUILD_SITE_URL
ARG ARCH

LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.name="jiva-csi"
LABEL org.label-schema.description="OpenEBS Jiva CSI Plugin"
LABEL org.label-schema.build-date=$DBUILD_DATE
LABEL org.label-schema.vcs-url=$DBUILD_REPO_URL
LABEL org.label-schema.url=$DBUILD_SITE_URL
LABEL org.label-schema.arch=$ARCH

ENTRYPOINT ["/usr/local/bin/jiva-csi"]
12 changes: 8 additions & 4 deletions build/push
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ echo "Set the build/unique image tag as: ${BUILD_TAG}"
function TagAndPushImage() {
REPO="$1"
TAG="$2"

IMAGE_URI="${REPO}:${TAG}";
#Add an option to specify a custom TAG_SUFFIX
#via environment variable. Default is no tag.
#Example suffix could be "-debug" of "-dev"
IMAGE_URI="${REPO}:${TAG}${TAG_SUFFIX}";
sudo docker tag ${IMAGEID} ${IMAGE_URI};
echo " push ${IMAGE_URI}";
sudo docker push ${IMAGE_URI};
Expand All @@ -65,7 +67,8 @@ then
# Push with different tags if tagged as a release
# When github is tagged with a release, then Travis will
# set the release tag in env TRAVIS_TAG
TagAndPushImage "${DIMAGE}" "${TRAVIS_TAG}"
# Trim `v` from the TRAVIS_TAG if it exists
TagAndPushImage "${DIMAGE}" "${TRAVIS_TAG#v}"
TagAndPushImage "${DIMAGE}" "latest"
fi;
else
Expand All @@ -85,7 +88,8 @@ then
# Push with different tags if tagged as a release
# When github is tagged with a release, then Travis will
# set the release tag in env TRAVIS_TAG
TagAndPushImage "quay.io/${DIMAGE}" "${TRAVIS_TAG}"
# Trim `v` from the TRAVIS_TAG if it exists
TagAndPushImage "quay.io/${DIMAGE}" "${TRAVIS_TAG#v}"
TagAndPushImage "quay.io/${DIMAGE}" "latest"
fi;
else
Expand Down

0 comments on commit b16967e

Please sign in to comment.