From 59aaec48fc3d2e1029eaf3c78b6c4810eb10f2e0 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 2 May 2019 19:35:48 +0000 Subject: [PATCH] [next] Release (#2296) * feat: added release process * fix: removed debug echo's * fix: fixed typo and bug - replaced // with /# to remove "v" prefix only, not all "v" in string * fix: updated docs --- .circleci/config.yml | 47 ++++++++++++--------- package.json | 2 +- scripts/docker.sh | 98 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 20 deletions(-) create mode 100755 scripts/docker.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index ffc60adb7..5b7c44fae 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -29,7 +29,7 @@ jobs: - run: name: Update NPM command: sudo npm update -g npm - # Disabled until there's capabilityies to ignore a specific vun. Related: + # Disabled until there's capabilities to ignore a specific vun. Related: # https://npm.community/t/please-provide-option-to-ignore-packages-in-npm-audit/403/4 # https://github.com/npm/cli/pull/10 # https://github.com/npm/rfcs/pull/18 @@ -107,7 +107,7 @@ jobs: - run: name: Build command: npm run build - no_output_timeout: 20m + no_output_timeout: 30m - run: name: Verify Bundle Size command: npx bundlesize @@ -128,10 +128,10 @@ jobs: steps: - checkout - run: - name: Update Image Dependancies + name: Update Image Dependencies command: apk --no-cache add git python - run: - name: Install NodeJS Dependancies + name: Install NodeJS Dependencies command: npm install # release_docker will build and push the Docker image. @@ -140,16 +140,29 @@ jobs: steps: - checkout - setup_remote_docker - - run: - name: Login - command: docker login -u $DOCKER_USER -p $DOCKER_PASS - - run: - name: Build - command: docker build -t coralproject/talk:next --build-arg REVISION_HASH=$CIRCLE_SHA1 . + - deploy: + name: Deploy the code + command: bash ./scripts/docker.sh deploy no_output_timeout: 30m - - run: - name: Push - command: docker push coralproject/talk:next + +# filter_release will add the filters for a deploy job in a workflow to make it +# only execute on a deploy related job. +filter_release: &filter_release + filters: + branches: + only: + - master + - next + tags: + only: /^v.*/ + +# filter_develop will add the filters for a development related commit. +filter_develop: &filter_develop + filters: + branches: + ignore: + - master + - next workflows: version: 2 @@ -158,9 +171,7 @@ workflows: # Run the docker build test on all branches except for next as we'll # already be releasing via docker with that route. - docker_tests: - filters: - branches: - ignore: next + <<: *filter_develop - npm_dependencies - lint: requires: @@ -176,6 +187,4 @@ workflows: - lint - unit_tests - build - filters: - branches: - only: next + <<: *filter_release diff --git a/package.json b/package.json index e895bbae6..5936f053d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@coralproject/talk", - "version": "5.0.0", + "version": "5.0.0-beta.1", "author": "The Coral Project", "homepage": "https://coralproject.net/", "sideEffects": [ diff --git a/scripts/docker.sh b/scripts/docker.sh new file mode 100755 index 000000000..af96a47c3 --- /dev/null +++ b/scripts/docker.sh @@ -0,0 +1,98 @@ +#!/bin/bash + +set -e + +# Inspired by https://segment.com/blog/ci-at-segment/ + +deploy_tag() { + # Find our individual versions from the tags. If the tag contains prerelease + # tag, it will fall back to the next step which will just tag it as is. For + # Example: + # + # v5.0.0-beta.1 will be tagged with 5.0.0-beta.1 + # v5.0.0 will be tagged with 5, 5.0, 5.0.0 + # + if [ -n "$(echo $CIRCLE_TAG | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$')" ] + then + major=$(echo ${CIRCLE_TAG/#v} | cut -d. -f1) + minor=$(echo ${CIRCLE_TAG/#v} | cut -d. -f2) + patch=$(echo ${CIRCLE_TAG/#v} | cut -d. -f3) + + major_version_tag=$major + minor_version_tag=$major.$minor + patch_version_tag=$major.$minor.$patch + + tag_list="$major_version_tag $minor_version_tag $patch_version_tag" + else + tag_list=${CIRCLE_TAG/#v} + fi + + # Tag the new image with major, minor and patch version tags. + for version in $tag_list + do + echo "==> tagging $version" + docker tag coralproject/talk:latest coralproject/talk:$version + done + + # Push each of the tags to dockerhub, including latest + for version in $tag_list + do + echo "==> pushing $version" + docker push coralproject/talk:$version + done + + # Deploy latest if we're at master, or deploy this branch if we aren't. + if [ "$CIRCLE_BRANCH" = "master" ] + then + deploy_latest + else + deploy_branch + fi +} + +deploy_latest() { + echo "==> pushing latest" + docker push coralproject/talk:latest +} + +deploy_branch() { + echo "==> tagging branch $CIRCLE_BRANCH" + docker tag coralproject/talk:latest coralproject/talk:$CIRCLE_BRANCH + + echo "==> pushing branch $CIRCLE_BRANCH" + docker push coralproject/talk:$CIRCLE_BRANCH +} + +ARGS="" + +if [[ -n "$CIRCLE_SHA1" ]] +then + ARGS="--build-arg REVISION_HASH=${CIRCLE_SHA1}" +fi + +# build the repo, including the onbuild tagged versions. +docker build -t coralproject/talk:latest ${ARGS} -f Dockerfile . + +if [ "$1" = "deploy" ] +then + + if [[ -n "$DOCKER_USER" && -n "$DOCKER_PASS" ]] + then + + # Log the Docker Daemon in + docker login -u $DOCKER_USER -p $DOCKER_PASS + fi + + # deploy based on the env + if [ -n "$CIRCLE_TAG" ] + then + deploy_tag + else + if [ "$CIRCLE_BRANCH" = "master" ] + then + deploy_latest + else + deploy_branch + fi + fi +fi