diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..350f5f72 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,118 @@ +# 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. +name: build + +on: ['push'] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Shellcheck + uses: reviewdog/action-shellcheck@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-pr-review + path: '.' + pattern: '*.sh' + exclude: './vendor/*' + + upgrade: + runs-on: ubuntu-latest + needs: ['lint'] + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set tag + run: | + BRANCH="${GITHUB_REF##*/}" + CI_TAG=${BRANCH#v}-ci + if [ ${BRANCH} = "master" ]; then + CI_TAG="ci" + fi + echo "::set-env name=TAG::${CI_TAG}" + echo "::set-env name=BRANCH::${BRANCH}" + echo "BRANCH: ${BRANCH}" + echo "TAG: ${CI_TAG}" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + with: + platforms: all + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + with: + version: latest + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build & Push Image + env: + IMAGE_ORG: ${{ secrets.IMAGE_ORG}} + run: | + make docker.buildx.upgrade + make buildx.push.upgrade + + migrate: + runs-on: ubuntu-latest + needs: ['lint'] + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set tag + run: | + BRANCH="${GITHUB_REF##*/}" + CI_TAG=${BRANCH#v}-ci + if [ ${BRANCH} = "master" ]; then + CI_TAG="ci" + fi + echo "::set-env name=TAG::${CI_TAG}" + echo "::set-env name=BRANCH::${BRANCH}" + echo "BRANCH: ${BRANCH}" + echo "TAG: ${CI_TAG}" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + with: + platforms: all + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + with: + version: latest + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build & Push Image + env: + IMAGE_ORG: ${{ secrets.IMAGE_ORG}} + run: | + make docker.buildx.migrate + make buildx.push.migrate diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 00000000..f0b07de9 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,84 @@ +# 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. + +name: ci + +on: + pull_request: + branches: + # on pull requests to master and release branches + - master + - 'v*' + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Shellcheck + uses: reviewdog/action-shellcheck@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-pr-review + path: '.' + pattern: '*.sh' + exclude: './vendor/*' + + upgrade: + runs-on: ubuntu-latest + needs: ['lint'] + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + with: + platforms: all + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + with: + version: latest + + - name: Build Image + env: + IMG_RESULT: cache + run: make docker.buildx.upgrade + + migrate: + runs-on: ubuntu-latest + needs: ['lint'] + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + with: + platforms: all + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + with: + version: latest + + - name: Build Image + env: + IMG_RESULT: cache + run: make docker.buildx.migrate diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..621f12b8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,94 @@ +# 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. +name: release + +on: + create: + tags: + - 'v*' + +jobs: + upgrade: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Set Tag + run: | + TAG="${GITHUB_REF#refs/*/v}" + echo "::set-env name=TAG::${TAG}" + echo "::set-env name=RELEASE_TAG::${TAG}" + echo "RELEASE_TAG ${TAG}" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + with: + platforms: all + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + with: + version: latest + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build & Push Image + env: + IMAGE_ORG: ${{ secrets.IMAGE_ORG}} + run: | + make docker.buildx.upgrade + make buildx.push.upgrade + + migrate: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Set Tag + run: | + TAG="${GITHUB_REF#refs/*/v}" + echo "::set-env name=TAG::${TAG}" + echo "::set-env name=RELEASE_TAG::${TAG}" + echo "RELEASE_TAG ${TAG}" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + with: + platforms: all + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + with: + version: latest + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build & Push Image + env: + IMAGE_ORG: ${{ secrets.IMAGE_ORG}} + run: | + make docker.buildx.migrate + make buildx.push.migrate diff --git a/.travis.yml b/.travis.yml index d647e0ad..366ea3b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,20 +39,28 @@ jobs: - stage: "Tests" os: linux arch: amd64 + env: + - INSTALL_MINIKUBE=false script: - make check-license - make test name: "Unit tests" - os: linux arch: amd64 + env: + - INSTALL_MINIKUBE=true script: ./ci/migrate/sanity.sh name: "Migrate Sanity" - os: linux arch: amd64 + env: + - INSTALL_MINIKUBE=true script: ./ci/upgrade/sanity.sh name: "Upgrade Sanity" - stage: "Deploy Images" os: linux + env: + - INSTALL_MINIKUBE=false arch: amd64 script: make all.amd64 deploy-images @@ -71,7 +79,7 @@ install: before_script: # TODO add golangci yaml config - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.25.0 - - if [ "$TRAVIS_CPU_ARCH" == "amd64" ]; then + - if [ "$INSTALL_MINIKUBE" == "true" ]; then curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.18.1/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/; curl -Lo minikube https://storage.googleapis.com/minikube/releases/v1.12.3/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/; mkdir -p $HOME/.kube $HOME/.minikube; @@ -80,6 +88,8 @@ before_script: # TODO add golangci yaml config sudo chown -R travis /home/travis/.minikube/; JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1; done; fi + - export RELEASE_TAG="$TRAVIS_TAG" + - export BRANCH="$TRAVIS_BRANCH" notifications: email: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5526be47..4f924541 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing to OpenEBS Upgrade -NDM uses the standard GitHub pull requests process to review and accept contributions. There are several areas that could use your help. For starters, you could help in improving the sections in this document by either creating a new issue describing the improvement or submitting a pull request to this repository. The issues are maintained at [openebs/openebs](https://github.com/openebs/openebs/issues?q=is%3Aissue+is%3Aopen+label%3Andm) repository. +Upgrade uses the standard GitHub pull requests process to review and accept contributions. There are several areas that could use your help. For starters, you could help in improving the sections in this document by either creating a new issue describing the improvement or submitting a pull request to this repository. The issues are maintained at [openebs/openebs](https://github.com/openebs/openebs/issues?q=is%3Aopen+is%3Aissue+label%3A%22component%3A+Upgrade%22) repository. * If you are a first-time contributor, please see [Steps to Contribute](#steps-to-contribute). * If you want to file an issue for a bug or feature request, please see [Filing a issue](#filing-an-issue) @@ -10,9 +10,9 @@ NDM uses the standard GitHub pull requests process to review and accept contribu ## Steps to Contribute -NDM is an Apache 2.0 Licensed project and all your commits should be signed with Developer Certificate of Origin. See [Sign your work](#sign-your-work). +Upgrade is an Apache 2.0 Licensed project and all your commits should be signed with Developer Certificate of Origin. See [Sign your work](#sign-your-work). -* Find an issue to work on or create a new issue. The issues are maintained at [openebs/openebs](https://github.com/openebs/openebs/issues?q=is%3Aissue+is%3Aopen+label%3Andm). You can pick up from a list of [good-first-issues](https://github.com/openebs/upgrade/labels/good%20first%20issue). +* Find an issue to work on or create a new issue. The issues are maintained at [openebs/openebs](https://github.com/openebs/openebs/issues?q=is%3Aopen+is%3Aissue+label%3A%22component%3A+Upgrade%22). You can pick up from a list of [good-first-issues](https://github.com/openebs/upgrade/labels/good%20first%20issue). * Claim your issue by commenting your intent to work on it to avoid duplication of efforts. * Fork the repository on GitHub. * Create a branch from where you want to base your work (usually master). @@ -69,7 +69,7 @@ When filing an issue, make sure to answer these seven questions: For example: ``` - feat(partition) : add support for partitions + feat(upgrade) : add support for jiva volume upgrades ^--^ ^-----^ ^-----------------------^ | | | | | +-> PR subject, summary of the changes @@ -130,5 +130,5 @@ This project is implemented using Go and uses the standard golang tools for deve For setting up a Development environment on your local host, see the detailed instructions [here](./BUILD.md). -The NDM design document is available [here](./docs/design.md). +The Upgrade design document is available [here](https://github.com/openebs/openebs/tree/master/contribute/design/1.x/upgrade). diff --git a/Makefile b/Makefile index 3af8866c..3ec0fa67 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,36 @@ 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} +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} + +# Specify the name for the binaries +UPGRADE=upgrade +MIGRATE=migrate + +# If there are any external tools need to be used, they can be added by defining a EXTERNAL_TOOLS variable +# Bootstrap the build by downloading additional tools +.PHONY: bootstrap +bootstrap: + @for tool in $(EXTERNAL_TOOLS) ; do \ + echo "Installing $$tool" ; \ + go get -u $$tool; \ + done + +.PHONY: clean-migrate +clean-migrate: + @echo '--> Cleaning migrate directory...' + rm -rf bin/${MIGRATE} + rm -rf ${GOPATH}/bin/${MIGRATE} + @echo '--> Done cleaning.' + @echo + +.PHONY: clean-upgrade +clean-upgrade: + @echo '--> Cleaning upgrade directory...' + rm -rf bin/${UPGRADE} + rm -rf ${GOPATH}/bin/${UPGRADE} + @echo '--> Done cleaning.' + @echo # deps ensures fresh go.mod and go.sum. .PHONY: deps @@ -63,16 +92,14 @@ deps: test: go test ./... -# Specify the name for the binaries -UPGRADE=upgrade - # Specify the name of the docker repo for amd64 UPGRADE_REPO_NAME_AMD64="upgrade-amd64" MIGRATE_REPO_NAME_AMD64="migrate-amd64" -# Specify the name of the docker repo for arm64 -UPGRADE_REPO_NAME_ARM64="upgrade-arm64" -MIGRATE_REPO_NAME_ARM64="migrate-arm64" +ifeq (${IMAGE_TAG}, ) + IMAGE_TAG = ci + export IMAGE_TAG +endif # build upgrade binary .PHONY: upgrade @@ -86,12 +113,6 @@ upgrade: @# A copy of the binary will also be placed under: ./bin/${PNAME}/${CTLNAME} @PNAME=${UPGRADE} CTLNAME=${UPGRADE} CGO_ENABLED=0 sh -c "'$(PWD)/build/build.sh'" -ifeq (${IMAGE_TAG}, ) - IMAGE_TAG = ci - export IMAGE_TAG -endif - - # build upgrade image .PHONY: upgrade-image.amd64 upgrade-image.amd64: upgrade @@ -104,27 +125,39 @@ upgrade-image.amd64: upgrade sudo docker build -t "${IMAGE_ORG}/${UPGRADE_REPO_NAME_AMD64}:${IMAGE_TAG}" ${DBUILD_ARGS} . @rm build/${UPGRADE}/${UPGRADE} -.PHONY: upgrade-image.arm64 -upgrade-image.arm64: upgrade - @echo "-----------------------------------------------" - @echo "--> ${UPGRADE} image " - @echo "${IMAGE_ORG}/${UPGRADE_REPO_NAME_ARM64}:${IMAGE_TAG}" - @echo "-----------------------------------------------" - @cp bin/${UPGRADE}/${UPGRADE} build/${UPGRADE} - @cd build/${UPGRADE} && \ - sudo docker build -t "${IMAGE_ORG}/${UPGRADE_REPO_NAME_ARM64}:${IMAGE_TAG}" ${DBUILD_ARGS} . - @rm build/${UPGRADE}/${UPGRADE} - - - - # cleanup upgrade build .PHONY: cleanup-upgrade cleanup-upgrade: rm -rf ${GOPATH}/bin/${UPGRADE} +# build migrate binary +.PHONY: migrate +migrate: + @echo "----------------------------" + @echo "--> ${MIGRATE} " + @echo "----------------------------" + @# PNAME is the sub-folder in ./bin where binary will be placed. + @# CTLNAME indicates the folder/pkg under cmd that needs to be built. + @# The output binary will be: ./bin/${PNAME}//${CTLNAME} + @# A copy of the binary will also be placed under: ./bin/${PNAME}/${CTLNAME} + @PNAME=${MIGRATE} CTLNAME=${MIGRATE} CGO_ENABLED=0 sh -c "'$(PWD)/build/build.sh'" + +# build migrate image +.PHONY: migrate-image.amd64 +migrate-image.amd64: migrate + @echo "-----------------------------------------------" + @echo "--> ${MIGRATE} image " + @echo "${IMAGE_ORG}/${MIGRATE_REPO_NAME_AMD64}:${IMAGE_TAG}" + @echo "-----------------------------------------------" + @cp bin/${MIGRATE}/${MIGRATE} build/${MIGRATE}/ + @cd build/${MIGRATE} && \ + sudo docker build -t "${IMAGE_ORG}/${MIGRATE_REPO_NAME_AMD64}:${IMAGE_TAG}" ${DBUILD_ARGS} . + @rm build/${MIGRATE}/${MIGRATE} -include ./build/migrate/Makefile.mk +# cleanup migrate build +.PHONY: cleanup-migrate +cleanup-migrate: + rm -rf ${GOPATH}/bin/${MIGRATE} .PHONY: all.amd64 all.amd64: upgrade-image.amd64 migrate-image.amd64 @@ -144,3 +177,6 @@ check-license: echo "license header checking failed:"; echo "$${licRes}"; \ exit 1; \ fi + +# include the buildx recipes +include Makefile.buildx.mk diff --git a/Makefile.buildx.mk b/Makefile.buildx.mk new file mode 100644 index 00000000..c189a99c --- /dev/null +++ b/Makefile.buildx.mk @@ -0,0 +1,77 @@ +# 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. + +# ============================================================================== +# Build Options + +ifeq (${TAG}, ) + export TAG=ci +endif + +# Build upgrade & migrate docker image with buildx +# Experimental docker feature to build cross platform multi-architecture docker images +# https://docs.docker.com/buildx/working-with-buildx/ + +# default list of platforms for which multiarch image is built +ifeq (${PLATFORMS}, ) + export PLATFORMS="linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le" +endif + +# if IMG_RESULT is unspecified, by default the image will be pushed to registry +ifeq (${IMG_RESULT}, load) + export PUSH_ARG="--load" + # if load is specified, image will be built only for the build machine architecture. + export PLATFORMS="local" +else ifeq (${IMG_RESULT}, cache) + # if cache is specified, image will only be available in the build cache, it won't be pushed or loaded + # therefore no PUSH_ARG will be specified +else + export PUSH_ARG="--push" +endif + +# Name of the multiarch image for upgrade job +DOCKERX_IMAGE_UPGRADE:=${IMAGE_ORG}/upgrade:${TAG} + +# Name of the multiarch image for migrate job +DOCKERX_IMAGE_MIGRATE:=${IMAGE_ORG}/migrate:${TAG} + +.PHONY: docker.buildx +docker.buildx: + export DOCKER_CLI_EXPERIMENTAL=enabled + @if ! docker buildx ls | grep -q container-builder; then\ + docker buildx create --platform ${PLATFORMS} --name container-builder --use;\ + fi + @docker buildx build --platform ${PLATFORMS} \ + -t "$(DOCKERX_IMAGE_NAME)" ${DBUILD_ARGS} -f $(PWD)/build/$(COMPONENT)/$(COMPONENT).Dockerfile \ + . ${PUSH_ARG} + @echo "--> Build docker image: $(DOCKERX_IMAGE_NAME)" + @echo + +.PHONY: docker.buildx.upgrade +docker.buildx.upgrade: DOCKERX_IMAGE_NAME=$(DOCKERX_IMAGE_UPGRADE) +docker.buildx.upgrade: COMPONENT=$(UPGRADE) +docker.buildx.upgrade: docker.buildx + +.PHONY: docker.buildx.migrate +docker.buildx.migrate: DOCKERX_IMAGE_NAME=$(DOCKERX_IMAGE_MIGRATE) +docker.buildx.migrate: COMPONENT=$(MIGRATE) +docker.buildx.migrate: docker.buildx + +.PHONY: buildx.push.upgrade +buildx.push.upgrade: + BUILDX=true DIMAGE=${IMAGE_ORG}/upgrade ./build/buildxpush.sh + +.PHONY: buildx.push.migrate +buildx.push.migrate: + BUILDX=true DIMAGE=${IMAGE_ORG}/migrate ./build/buildxpush.sh diff --git a/build/build.sh b/build/build.sh index 07b75e42..4b9eb4a5 100755 --- a/build/build.sh +++ b/build/build.sh @@ -33,30 +33,30 @@ else GIT_COMMIT="$(git rev-parse HEAD)" fi -# Set BUILDMETA based on travis tag -if [[ -n "$TRAVIS_TAG" ]] && [[ $TRAVIS_TAG != *"RC"* ]]; then +# Set BUILDMETA based on release tag +if [[ -n "$RELEASE_TAG" ]] && [[ $RELEASE_TAG != *"RC"* ]]; then echo "released" > BUILDMETA fi # Get the version details # Determine the current branch CURRENT_BRANCH="" -if [ -z "${TRAVIS_BRANCH}" ]; +if [ -z "${BRANCH}" ]; then CURRENT_BRANCH=$(git branch | grep "\*" | cut -d ' ' -f2) else - CURRENT_BRANCH="${TRAVIS_BRANCH}" + CURRENT_BRANCH="${BRANCH}" fi ## Populate the version based on release tag -## If travis tag is set then assign it as VERSION and -## if travis tag is empty then mark version as ci -if [ -n "$TRAVIS_TAG" ]; then - # Trim the `v` from the TRAVIS_TAG if it exists +## If release tag is set then assign it as VERSION and +## if release tag is empty then mark version as ci +if [ -n "$RELEASE_TAG" ]; then + # Trim the `v` from the RELEASE_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 - VERSION="${TRAVIS_TAG#v}" + VERSION="${RELEASE_TAG#v}" else ## Marking VERSION as current_branch-dev ## Example: master branch maps to master-dev @@ -83,18 +83,6 @@ elif [ "$UNAME" = "Linux" ] ; then XC_OS="linux" fi -if [ "${ARCH}" = "i686" ] ; then - XC_ARCH='386' -elif [ "${ARCH}" = "x86_64" ] ; then - XC_ARCH='amd64' -elif [ "${ARCH}" = "aarch64" ] ; then - XC_ARCH='arm64' -else - echo "Unusable architecture: ${ARCH}" - exit 1 -fi - - if [ -z "${PNAME}" ]; then echo "Project name not defined" @@ -159,19 +147,6 @@ for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 2 -type f); do cp ${F} ${MAIN_GOPATH}/bin/ done -if [[ "x${DEV}" == "x" ]]; then - # Zip and copy to the dist dir - echo "==> Packaging..." - for PLATFORM in $(find ./bin/${PNAME} -mindepth 1 -maxdepth 1 -type d); do - OSARCH=$(basename ${PLATFORM}) - echo "--> ${OSARCH}" - - pushd "$PLATFORM" >/dev/null 2>&1 - zip ../${PNAME}-${OSARCH}.zip ./* - popd >/dev/null 2>&1 - done -fi - # Done! echo echo "==> Results:" diff --git a/build/buildxpush.sh b/build/buildxpush.sh new file mode 100755 index 00000000..07601f92 --- /dev/null +++ b/build/buildxpush.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# 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. + +set -e + +if [ -z ${DIMAGE} ]; +then + echo "Error: DIMAGE is not specified"; + exit 1 +fi + +function pushBuildx() { + BUILD_TAG="latest" + TARGET_IMG=${DIMAGE} + +# TODO Currently ci builds with commit tag will not be generated, +# since buildx does not support multiple repo + # if not a release build set the tag and ci image + if [ -z "${RELEASE_TAG}" ]; then + return +# BUILD_ID=$(git describe --tags --always) +# BUILD_TAG="${BRANCH}-${BUILD_ID}" +# TARGET_IMG="${DIMAGE}-ci" + fi + + echo "Tagging and pushing ${DIMAGE}:${TAG} as ${TARGET_IMG}:${BUILD_TAG}" + docker buildx imagetools create "${DIMAGE}:${TAG}" -t "${TARGET_IMG}:${BUILD_TAG}" +} + +# if the push is for a buildx build +if [[ ${BUILDX} ]]; then + pushBuildx + exit 0 +fi diff --git a/build/migrate/Makefile.mk b/build/migrate/Makefile.mk deleted file mode 100644 index 88d5b0aa..00000000 --- a/build/migrate/Makefile.mk +++ /dev/null @@ -1,57 +0,0 @@ -# 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. - -# Specify the name for the binaries -MIGRATE=migrate - -# build migrate binary -.PHONY: migrate -migrate: - @echo "----------------------------" - @echo "--> ${MIGRATE} " - @echo "----------------------------" - @# PNAME is the sub-folder in ./bin where binary will be placed. - @# CTLNAME indicates the folder/pkg under cmd that needs to be built. - @# The output binary will be: ./bin/${PNAME}//${CTLNAME} - @# A copy of the binary will also be placed under: ./bin/${PNAME}/${CTLNAME} - @PNAME=${MIGRATE} CTLNAME=${MIGRATE} CGO_ENABLED=0 sh -c "'$(PWD)/build/build.sh'" - -# build migrate image -.PHONY: migrate-image.amd64 -migrate-image.amd64: migrate - @echo "-----------------------------------------------" - @echo "--> ${MIGRATE} image " - @echo "${IMAGE_ORG}/${MIGRATE_REPO_NAME_AMD64}:${IMAGE_TAG}" - @echo "-----------------------------------------------" - @cp bin/${MIGRATE}/${MIGRATE} build/${MIGRATE}/ - @cd build/${MIGRATE} && \ - sudo docker build -t "${IMAGE_ORG}/${MIGRATE_REPO_NAME_AMD64}:${IMAGE_TAG}" ${DBUILD_ARGS} . - @rm build/${MIGRATE}/${MIGRATE} - -# build migrate image -.PHONY: migrate-image.arm64 -migrate-image.arm64: migrate - @echo "-----------------------------------------------" - @echo "--> ${MIGRATE} image " - @echo "${IMAGE_ORG}/${MIGRATE_REPO_NAME_ARM64}:${IMAGE_TAG}" - @echo "-----------------------------------------------" - @cp bin/${MIGRATE}/${MIGRATE} build/${MIGRATE}/ - @cd build/${MIGRATE} && \ - sudo docker build -t "${IMAGE_ORG}/${MIGRATE_REPO_NAME_ARM64}:${IMAGE_TAG}" ${DBUILD_ARGS} . - @rm build/${MIGRATE}/${MIGRATE} - -# cleanup migrate build -.PHONY: cleanup-migrate -cleanup-migrate: - rm -rf ${GOPATH}/bin/${MIGRATE} diff --git a/build/migrate/migrate.Dockerfile b/build/migrate/migrate.Dockerfile new file mode 100644 index 00000000..d4f94689 --- /dev/null +++ b/build/migrate/migrate.Dockerfile @@ -0,0 +1,57 @@ +# 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. +# +# This Dockerfile builds migrate +# +FROM golang:1.14.7 as build + +ARG TARGETOS +ARG TARGETARCH +ARG TARGETVARIANT="" + +ENV GO111MODULE=on \ + GOOS=${TARGETOS} \ + GOARCH=${TARGETARCH} \ + GOARM=${TARGETVARIANT} \ + DEBIAN_FRONTEND=noninteractive \ + PATH="/root/go/bin:${PATH}" + +WORKDIR /go/src/github.com/openebs/upgrade/ + +RUN apt-get update && apt-get install -y make git + +COPY go.mod go.sum ./ +# Get dependancies - will also be cached if we won't change mod/sum +RUN go mod download + +COPY . . + +RUN make migrate + +FROM alpine:3.11.5 + +ARG DBUILD_DATE +ARG DBUILD_REPO_URL +ARG DBUILD_SITE_URL +LABEL org.label-schema.name="migrate" +LABEL org.label-schema.description="migrate openebs components" +LABEL org.label-schema.schema-version="1.0" +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 + +# copy the latest binary +COPY --from=build /go/src/github.com/openebs/upgrade/bin/migrate/migrate /usr/local/bin/migrate + +ENTRYPOINT ["migrate"] diff --git a/build/upgrade/upgrade.Dockerfile b/build/upgrade/upgrade.Dockerfile new file mode 100644 index 00000000..09e8cb91 --- /dev/null +++ b/build/upgrade/upgrade.Dockerfile @@ -0,0 +1,57 @@ +# 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. +# +# This Dockerfile builds upgrade +# +FROM golang:1.14.7 as build + +ARG TARGETOS +ARG TARGETARCH +ARG TARGETVARIANT="" + +ENV GO111MODULE=on \ + GOOS=${TARGETOS} \ + GOARCH=${TARGETARCH} \ + GOARM=${TARGETVARIANT} \ + DEBIAN_FRONTEND=noninteractive \ + PATH="/root/go/bin:${PATH}" + +WORKDIR /go/src/github.com/openebs/upgrade/ + +RUN apt-get update && apt-get install -y make git + +COPY go.mod go.sum ./ +# Get dependancies - will also be cached if we won't change mod/sum +RUN go mod download + +COPY . . + +RUN make upgrade + +FROM alpine:3.11.5 + +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.schema-version="1.0" +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 + +# copy the latest binary +COPY --from=build /go/src/github.com/openebs/upgrade/bin/upgrade/upgrade /usr/local/bin/upgrade + +ENTRYPOINT ["upgrade"]