diff --git a/.travis.yml b/.travis.yml index bdbc97b9..350327c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,7 +41,7 @@ script: fi after_success: - - # make deploy-images + - make deploy-images notifications: email: diff --git a/Makefile b/Makefile index a09aa268..792afe1d 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,57 @@ +# 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. +# 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. + + +# 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 date of build +DBUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') + +# Specify the docker arg for repository url +ifeq (${DBUILD_REPO_URL}, ) + DBUILD_REPO_URL="https://github.com/openebs/upgrade" + 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 + +# 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} # deps ensures fresh go.mod and go.sum. .PHONY: deps @@ -48,7 +102,7 @@ upgrade-image.amd64: upgrade @echo "-----------------------------------------------" @cp bin/${UPGRADE}/${UPGRADE} build/${UPGRADE} @cd build/${UPGRADE} && \ - sudo docker build -t "${HUB_USER}/${UPGRADE_REPO_NAME_AMD64}:${IMAGE_TAG}" --build-arg BUILD_DATE=${BUILD_DATE} . + sudo docker build -t "${HUB_USER}/${UPGRADE_REPO_NAME_AMD64}:${IMAGE_TAG}" ${DBUILD_ARGS} . @rm build/${UPGRADE}/${UPGRADE} .PHONY: upgrade-image.arm64 @@ -59,7 +113,7 @@ upgrade-image.arm64: upgrade @echo "-----------------------------------------------" @cp bin/${UPGRADE}/${UPGRADE} build/${UPGRADE} @cd build/${UPGRADE} && \ - sudo docker build -t "${HUB_USER}/${UPGRADE_REPO_NAME_ARM64}:${IMAGE_TAG}" --build-arg BUILD_DATE=${BUILD_DATE} . + sudo docker build -t "${HUB_USER}/${UPGRADE_REPO_NAME_ARM64}:${IMAGE_TAG}" ${DBUILD_ARGS} . @rm build/${UPGRADE}/${UPGRADE} @@ -69,3 +123,9 @@ upgrade-image.arm64: upgrade .PHONY: cleanup-upgrade cleanup-upgrade: rm -rf ${GOPATH}/bin/${UPGRADE} + + +# Push images +.PHONY: deploy-images +deploy-images: + @./build/deploy.sh diff --git a/build/deploy.sh b/build/deploy.sh new file mode 100755 index 00000000..20fef701 --- /dev/null +++ b/build/deploy.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# 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. +# 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 + +# Determine the arch/os we're building for +ARCH=$(uname -m) + +if [ "${ARCH}" = "x86_64" ]; then + UPGRADE_IMG="${IMAGE_ORG}/upgrade-amd64" +elif [ "${ARCH}" = "aarch64" ]; then + UPGRADE_IMG="${IMAGE_ORG}/upgrade-arm64" +fi + +# tag and push all the images +DIMAGE="${UPGRADE_IMG}" ./build/push diff --git a/build/push b/build/push new file mode 100755 index 00000000..6f2df84b --- /dev/null +++ b/build/push @@ -0,0 +1,126 @@ +#!/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} ]; +then + echo "Error: DIMAGE is not specified"; + exit 1 +fi + +IMAGEID=$( sudo docker images -q ${DIMAGE}:ci ) +echo "${DIMAGE}:ci -> $IMAGEID" +if [ -z ${IMAGEID} ]; +then + echo "Error: unable to get IMAGEID for ${DIMAGE}:ci"; + exit 1 +fi + +# Generate a unique tag based on the commit and tag +BUILD_ID=$(git describe --tags --always) + +# Determine the current branch +CURRENT_BRANCH="" +if [ -z ${TRAVIS_BRANCH} ]; +then + CURRENT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2) +else + CURRENT_BRANCH=${TRAVIS_BRANCH} +fi + +# Depending on the branch where builds are generated, +# set the tag CI (fixed) and build tags. +BUILD_TAG="${CURRENT_BRANCH}-${BUILD_ID}" +CI_TAG="${CURRENT_BRANCH}-ci" +if [ ${CURRENT_BRANCH} = "master" ]; then + CI_TAG="ci" +fi + +echo "Set the fixed ci image tag as: ${CI_TAG}" +echo "Set the build/unique image tag as: ${BUILD_TAG}" + +function TagAndPushImage() { + REPO="$1" + + # 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}"; + + sudo docker tag ${IMAGEID} ${IMAGE_URI}; + echo " push ${IMAGE_URI}"; + sudo docker push ${IMAGE_URI}; +} + + +if [ ! -z "${DNAME}" ] && [ ! -z "${DPASS}" ]; +then + sudo docker login -u "${DNAME}" -p "${DPASS}"; + + # Push CI tagged image - :ci or :branch-ci + TagAndPushImage "${DIMAGE}" "${CI_TAG}" + + # Push unique tagged image - :master- or :branch- + # This unique/build image will be pushed to corresponding ci repo. + TagAndPushImage "${DIMAGE}-ci" "${BUILD_TAG}" + + if [ ! -z "${TRAVIS_TAG}" ] ; + 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}" + TagAndPushImage "${DIMAGE}" "latest" + fi; +else + echo "No docker credentials provided. Skip uploading ${DIMAGE} to docker hub"; +fi; + +# Push ci image to quay.io for security scanning +if [ ! -z "${QNAME}" ] && [ ! -z "${QPASS}" ]; +then + sudo docker login -u "${QNAME}" -p "${QPASS}" quay.io; + + # Push CI tagged image - :ci or :branch-ci + TagAndPushImage "quay.io/${DIMAGE}" "${CI_TAG}" + + if [ ! -z "${TRAVIS_TAG}" ] ; + 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}" + TagAndPushImage "quay.io/${DIMAGE}" "latest" + fi; +else + echo "No docker credentials provided. Skip uploading ${DIMAGE} to quay"; +fi; + +#Push image to run openebs-e2e based on git commit +if [ ! -z "${COMMIT}" ]; +then + sudo docker login -u "${GITLAB_DNAME}" -p "${GITLAB_DPASS}"; + + # Push COMMIT tagged image - :COMMIT + TagAndPushImage "${DIMAGE}" "${COMMIT}" +fi; \ No newline at end of file diff --git a/build/upgrade/Dockerfile b/build/upgrade/Dockerfile index 1695d14a..8bbee4f5 100644 --- a/build/upgrade/Dockerfile +++ b/build/upgrade/Dockerfile @@ -8,13 +8,15 @@ FROM alpine:3.11.5 # copy the latest binary COPY upgrade /usr/local/bin/upgrade -ARG BUILD_DATE - +ARG ARCH +ARG DBUILD_DATE +ARG DBUILD_REPO_URL +ARG DBUILD_SITE_URL LABEL org.label-schema.name="upgrade" LABEL org.label-schema.description="upgrades openebs components" -LABEL org.label-schema.url="https://openebs.io/" -LABEL org.label-schema.vcs-url="https://github.com/openebs/maya" LABEL org.label-schema.schema-version="1.0" -LABEL org.label-schema.build-date=$BUILD_DATE +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 ["upgrade"]