From 8743f714bb727b102540f9df6337d3b8da54e130 Mon Sep 17 00:00:00 2001 From: Prateek Pandey Date: Thu, 7 May 2020 22:14:32 +0530 Subject: [PATCH] refact(build): make the docker images configurable (#81) PR makes docker images configurable and removes the leading 'v' from image tags. This is required to make the image name consistent with other openebs images Signed-off-by: prateekpandey14 --- .travis.yml | 3 +- Makefile | 58 +++++++++++++++++++-- buildscripts/build.sh | 14 +++++ buildscripts/cstor-csi-driver/Dockerfile | 30 ++++++++--- buildscripts/cstor-csi-driver/entrypoint.sh | 14 +++++ buildscripts/push | 31 ++++++++++- buildscripts/test-cov.sh | 14 +++++ buildscripts/test.sh | 15 ++++++ buildscripts/tools.go | 2 +- buildscripts/travis-build.sh | 6 ++- 10 files changed, 168 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index e1f3c5334..f744f601d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,4 +48,5 @@ after_success: notifications: email: recipients: - - kiran.mova@openebs.io + - kiran.mova@mayadata.io + - prateek.pandey@mayadata.io diff --git a/Makefile b/Makefile index e8de1d3ed..143f80582 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,6 @@ VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods \ # Tools required for different make # targets or for development purposes EXTERNAL_TOOLS=\ - github.com/golang/dep/cmd/dep \ golang.org/x/tools/cmd/cover \ github.com/axw/gocov/gocov \ gopkg.in/matm/v1/gocov-html \ @@ -16,6 +15,40 @@ EXTERNAL_TOOLS=\ github.com/onsi/ginkgo/ginkgo \ github.com/onsi/gomega/... +# 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: +# //: +# +# IMAGE_ORG can be used to customize the organization +# under which images should be pushed. +# By default the organization name is `openebs`. + +ifeq (${IMAGE_ORG}, ) + IMAGE_ORG="openebs" + export IMAGE_ORG +endif + +# Specify the docker arg for repository url +ifeq (${DBUILD_REPO_URL}, ) + DBUILD_REPO_URL="https://github.com/openebs/cstor-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 + ifeq (${IMAGE_TAG}, ) IMAGE_TAG = ci export IMAGE_TAG @@ -29,11 +62,26 @@ else export BASE_TAG endif +# Determine the arch/os +ifeq (${XC_OS}, ) + XC_OS:=$(shell go env GOOS) +endif +export XC_OS +ifeq (${XC_ARCH}, ) + XC_ARCH:=$(shell go env GOARCH) +endif +export XC_ARCH +ARCH:=${XC_OS}_${XC_ARCH} +export ARCH + +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} + + # Specify the name for the binary CSI_DRIVER=cstor-csi-driver -# Specify the date o build -BUILD_DATE = $(shell date +'%Y%m%d%H%M%S') +# Specify the date of build +DBUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') .PHONY: all all: test csi-driver-image @@ -98,10 +146,10 @@ csi-driver-image: csi-driver @echo "+ Generating ${CSI_DRIVER} image" @echo "--------------------------------" @cp bin/${CSI_DRIVER}/${CSI_DRIVER} buildscripts/${CSI_DRIVER}/ - cd buildscripts/${CSI_DRIVER} && sudo docker build -t openebs/${CSI_DRIVER}:${IMAGE_TAG} --build-arg BUILD_DATE=${BUILD_DATE} . && docker tag openebs/${CSI_DRIVER}:${IMAGE_TAG} quay.io/openebs/${CSI_DRIVER}:${IMAGE_TAG} + cd buildscripts/${CSI_DRIVER} && sudo docker build -t ${IMAGE_ORG}/${CSI_DRIVER}:${IMAGE_TAG} ${DBUILD_ARGS} . && docker tag ${IMAGE_ORG}/${CSI_DRIVER}:${IMAGE_TAG} quay.io/${IMAGE_ORG}/${CSI_DRIVER}:${IMAGE_TAG} @rm buildscripts/${CSI_DRIVER}/${CSI_DRIVER} # Push images deploy-images: - @DIMAGE="openebs/cstor-csi-driver" ./buildscripts/push + @DIMAGE="${IMAGE_ORG}/cstor-csi-driver" ./buildscripts/push diff --git a/buildscripts/build.sh b/buildscripts/build.sh index 3b15eee73..8da489402 100755 --- a/buildscripts/build.sh +++ b/buildscripts/build.sh @@ -1,5 +1,19 @@ #!/usr/bin/env bash + +# Copyright 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. + # This script builds the application from source for multiple platforms. set -e diff --git a/buildscripts/cstor-csi-driver/Dockerfile b/buildscripts/cstor-csi-driver/Dockerfile index 5bcc39e91..4844c2057 100644 --- a/buildscripts/cstor-csi-driver/Dockerfile +++ b/buildscripts/cstor-csi-driver/Dockerfile @@ -1,25 +1,39 @@ +# Copyright 2020 The OpenEBS Authors. All rights reserved. # -# This Dockerfile builds a recent volume-mgmt using the latest binary from -# volume-mgmt releases. +# 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:16.04 RUN apt-get update; exit 0 RUN apt-get -y install rsyslog xfsprogs #RUN apt-get clean && rm -rf /var/lib/apt/lists/* +ARG ARCH +ARG DBUILD_DATE +ARG DBUILD_REPO_URL +ARG DBUILD_SITE_URL + COPY cstor-csi-driver /usr/local/bin/ COPY entrypoint.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/entrypoint.sh -ARG BUILD_DATE -LABEL org.label-schema.name="csi-driver" -LABEL org.label-schema.description="OpenEBS" -LABEL org.label-schema.url="http://www.openebs.io/" -LABEL org.label-schema.vcs-url="https://github.com/openebs/cstor-csi" LABEL org.label-schema.schema-version="1.0" -LABEL org.label-schema.build-date=$BUILD_DATE +LABEL org.label-schema.name="cstor-csi-driver" +LABEL org.label-schema.description="OpenEBS CStor CSI Driver" +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 ENTRYPOINT ["/usr/local/bin/cstor-csi-driver"] EXPOSE 7676 7777 diff --git a/buildscripts/cstor-csi-driver/entrypoint.sh b/buildscripts/cstor-csi-driver/entrypoint.sh index 82f16c04e..1188f8036 100644 --- a/buildscripts/cstor-csi-driver/entrypoint.sh +++ b/buildscripts/cstor-csi-driver/entrypoint.sh @@ -1,5 +1,19 @@ #!/bin/sh +# Copyright 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. + set -ex /usr/local/bin/csi-driver diff --git a/buildscripts/push b/buildscripts/push index e6f442002..bbc9b43b5 100755 --- a/buildscripts/push +++ b/buildscripts/push @@ -1,4 +1,19 @@ #!/bin/bash + +# Copyright 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. + set -e if [ -z ${DIMAGE} ]; @@ -40,9 +55,17 @@ echo "Set the build/unique image tag as: ${BUILD_TAG}" function TagAndPushImage() { REPO="$1" - TAG="$2" + # Trim the `v` from the TAG if it exists + # Example: v1.10.0 maps to 1.10.0 + # Example: 1.10.0 maps to 1.10.0 + # Example: v1.10.0-custom maps to 1.10.0-custom + TAG="${2#v}" + + # 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}"; - IMAGE_URI="${REPO}:${TAG}"; sudo docker tag ${IMAGEID} ${IMAGE_URI}; echo " push ${IMAGE_URI}"; sudo docker push ${IMAGE_URI}; @@ -65,6 +88,10 @@ 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 + # Trim the `v` from the TRAVIS_TAG if it exists + # Example: v1.10.0 maps to 1.10.0 + # Example: 1.10.0 maps to 1.10.0 + # Example: v1.10.0-custom maps to 1.10.0-custom TagAndPushImage "${DIMAGE}" "${TRAVIS_TAG}" TagAndPushImage "${DIMAGE}" "latest" fi; diff --git a/buildscripts/test-cov.sh b/buildscripts/test-cov.sh index a68f52fd5..7d5aa0a6d 100755 --- a/buildscripts/test-cov.sh +++ b/buildscripts/test-cov.sh @@ -1,5 +1,19 @@ #!/usr/bin/env bash +# Copyright 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. + set -e echo "" > coverage.txt diff --git a/buildscripts/test.sh b/buildscripts/test.sh index 6576d43cb..24e367ef6 100755 --- a/buildscripts/test.sh +++ b/buildscripts/test.sh @@ -1,4 +1,19 @@ #!/usr/bin/env bash + +# Copyright 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. + set -e # Create a temp dir and clean it up on exit diff --git a/buildscripts/tools.go b/buildscripts/tools.go index 049338deb..b1800797b 100644 --- a/buildscripts/tools.go +++ b/buildscripts/tools.go @@ -1,7 +1,7 @@ // +build tools /* -Copyright 2020 The Kubernetes Authors. +Copyright 2020 The OpenEBS Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/buildscripts/travis-build.sh b/buildscripts/travis-build.sh index 526ad607f..9f9a0da92 100755 --- a/buildscripts/travis-build.sh +++ b/buildscripts/travis-build.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e -# Copyright 2017 The OpenEBS Authors. + +# Copyright 2020 The OpenEBS Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,6 +14,8 @@ set -e # See the License for the specific language governing permissions and # limitations under the License. +set -e + SRC_REPO="$TRAVIS_BUILD_DIR" DST_REPO="$GOPATH/src/github.com/openebs/cstor-csi"