2018-07-10 13:01:02 +03:00
#!/usr/bin/env bash
2018-07-18 15:27:09 +03:00
set -evo pipefail
2018-07-10 13:01:02 +03:00
IFS = $'\n\t'
ROOT = " $( readlink -f ${ BASH_SOURCE [0]%/* } /../) "
2018-07-18 15:27:09 +03:00
2018-07-17 20:00:26 +03:00
LATEST_TAG = $( git describe --tags --abbrev= 0)
PREVIOUS_TAG = $( git describe --tags $( git rev-list --tags --max-count= 2) --abbrev= 0 | sed -n 2p)
2018-09-29 08:49:24 +03:00
CHANGELOG_TEXT = ""
2018-07-10 13:01:02 +03:00
2018-07-18 15:27:09 +03:00
# reviewers for pull requests opened to update installation manifests
REVIEWERS = "shahidhk,coco98,arvi3411301"
2020-01-16 09:05:35 +03:00
IS_STABLE_RELEASE = false
STABLE_SEMVER_REGEX = " ^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*) $"
if [ ! -z " ${ CIRCLE_TAG } " ] ; then
if [ [ " $CIRCLE_TAG " = ~ $STABLE_SEMVER_REGEX ] ] ; then
echo
echo "this is a stable release"
echo
IS_STABLE_RELEASE = true
fi
fi
2018-09-26 17:22:28 +03:00
changelog( ) {
2018-10-03 15:53:23 +03:00
CHANGELOG = $( git log ${ PREVIOUS_TAG } ..${ LATEST_TAG } --pretty= " tformat:- $1 : %s " --reverse -- $ROOT /$1 )
if [ -n " $CHANGELOG " ]
then
if [ -n " $CHANGELOG_TEXT " ]
then
echo ""
fi
echo " ${ CHANGELOG } "
fi
2018-09-26 17:22:28 +03:00
}
2018-07-10 13:01:02 +03:00
## deploy functions
deploy_server( ) {
echo "deploying server"
cd " $ROOT /server "
docker login -u " $DOCKER_USER " -p " $DOCKER_PASSWORD "
make ci-load-image
make push
}
2018-07-17 20:00:26 +03:00
deploy_server_latest( ) {
2020-01-16 09:05:35 +03:00
echo "deloying server latest tag"
cd " $ROOT /server "
echo " $DOCKER_PASSWORD " | docker login -u " $DOCKER_USER " --password-stdin
make push-latest
2018-07-17 20:00:26 +03:00
}
2018-07-10 13:01:02 +03:00
draft_github_release( ) {
cd " $ROOT "
2020-04-02 04:42:18 +03:00
export GITHUB_REPOSITORY = " ${ CIRCLE_PROJECT_USERNAME } / ${ CIRCLE_PROJECT_REPONAME } "
2018-07-10 13:01:02 +03:00
echo "drafting github release"
2020-04-02 04:42:18 +03:00
hub release create \
--draft \
-a /build/_cli_output/binaries/cli-hasura-darwin-amd64 \
-a /build/_cli_output/binaries/cli-hasura-linux-amd64 \
2021-07-16 07:19:02 +03:00
-a /build/_cli_output/binaries/cli-hasura-darwin-arm64 \
-a /build/_cli_output/binaries/cli-hasura-linux-arm64 \
2020-04-02 04:42:18 +03:00
-a /build/_cli_output/binaries/cli-hasura-windows-amd64.exe \
-m " $CIRCLE_TAG " \
-m " ${ RELEASE_BODY } " \
2020-03-25 13:50:59 +03:00
" $CIRCLE_TAG "
2020-04-02 04:42:18 +03:00
unset GITHUB_REPOSITORY
2018-07-10 13:01:02 +03:00
}
2018-07-24 07:05:32 +03:00
configure_git( ) {
git config --global user.email "build@hasura.io"
git config --global user.name "hasura-bot"
}
2018-07-18 15:27:09 +03:00
send_pr_to_repo( ) {
2020-01-16 09:05:35 +03:00
configure_git
2018-07-24 07:05:32 +03:00
git clone https://github.com/hasura/$1 .git ~/$1
2018-07-18 15:27:09 +03:00
cd ~/$1
git checkout -b ${ LATEST_TAG }
2018-08-06 14:33:17 +03:00
find . -type f -exec sed -i -E 's#(hasura/graphql-engine:)v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?( \\)*$#\1' " ${ LATEST_TAG } " '\9#' { } \;
2018-07-18 15:27:09 +03:00
git add .
git commit -m " update image version to ${ LATEST_TAG } "
2018-07-24 07:05:32 +03:00
git push -q https://${ GITHUB_TOKEN } @github.com/hasura/$1 .git ${ LATEST_TAG }
2020-04-22 13:23:47 +03:00
hub pull-request -f -F- <<< " Update image version to ${ LATEST_TAG } " -r ${ REVIEWERS } -a ${ REVIEWERS }
2018-07-18 15:27:09 +03:00
}
2018-07-10 13:01:02 +03:00
deploy_console( ) {
echo "deploying console"
cd " $ROOT /console "
2019-05-16 10:45:29 +03:00
export VERSION = $( ../scripts/get-console-assets-version.sh)
2020-04-01 15:56:54 +03:00
# if version is not set, then skip console
if [ -z " $VERSION " ] ; then
echo "version is not, skipping console deployment"
return
fi
2018-07-10 13:01:02 +03:00
export DIST_PATH = "/build/_console_output"
2019-05-16 10:45:29 +03:00
local GS_BUCKET_ROOT = " gs://graphql-engine-cdn.hasura.io/console/assets/ $VERSION "
# assets are at /build/_console_output/assets/versioned, already gzipped
gsutil cp " $DIST_PATH /assets/versioned/main.js.gz " " $GS_BUCKET_ROOT /main.js.gz "
gsutil cp " $DIST_PATH /assets/versioned/main.css.gz " " $GS_BUCKET_ROOT /main.css.gz "
gsutil cp " $DIST_PATH /assets/versioned/vendor.js.gz " " $GS_BUCKET_ROOT /vendor.js.gz "
gsutil setmeta -h "Content-Encoding: gzip" " $GS_BUCKET_ROOT /* "
2018-07-10 13:01:02 +03:00
unset VERSION
unset DIST_PATH
}
2018-11-02 13:21:44 +03:00
2020-03-19 15:21:53 +03:00
# build and push container for auto-migrations-v2
build_and_push_cli_migrations_image_v2( ) {
IMAGE_TAG = " hasura/graphql-engine: ${ CIRCLE_TAG } .cli-migrations-v2 "
2020-04-15 04:56:00 +03:00
docker load -i /build/_cli_migrations_output/v2.tar
docker tag cli-migrations-v2 " $IMAGE_TAG "
2020-03-19 15:21:53 +03:00
docker push " $IMAGE_TAG "
}
# build and push latest container for auto-migrations-v2
push_latest_cli_migrations_image_v2( ) {
IMAGE_TAG = " hasura/graphql-engine: ${ CIRCLE_TAG } .cli-migrations-v2 "
LATEST_IMAGE_TAG = "hasura/graphql-engine:latest.cli-migrations-v2"
# push latest.cli-migrations-v2 tag
docker tag " $IMAGE_TAG " " $LATEST_IMAGE_TAG "
docker push " $LATEST_IMAGE_TAG "
}
2021-04-06 12:58:24 +03:00
# build and push container for auto-migrations-v3
build_and_push_cli_migrations_image_v3( ) {
IMAGE_TAG = " hasura/graphql-engine: ${ CIRCLE_TAG } .cli-migrations-v3 "
docker load -i /build/_cli_migrations_output/v3.tar
docker tag cli-migrations-v3 " $IMAGE_TAG "
docker push " $IMAGE_TAG "
}
# build and push latest container for auto-migrations-v3
push_latest_cli_migrations_image_v3( ) {
IMAGE_TAG = " hasura/graphql-engine: ${ CIRCLE_TAG } .cli-migrations-v3 "
LATEST_IMAGE_TAG = "hasura/graphql-engine:latest.cli-migrations-v3"
# push latest.cli-migrations-v3 tag
docker tag " $IMAGE_TAG " " $LATEST_IMAGE_TAG "
docker push " $LATEST_IMAGE_TAG "
}
2020-01-16 09:05:35 +03:00
2018-11-02 13:21:44 +03:00
# copy docker-compose-https manifests to gcr for digital ocean one-click app
deploy_do_manifests( ) {
gsutil cp " $ROOT /install-manifests/docker-compose-https/docker-compose.yaml " \
gs://graphql-engine-cdn.hasura.io/install-manifests/do-one-click/docker-compose.yaml
gsutil cp " $ROOT /install-manifests/docker-compose-https/Caddyfile " \
gs://graphql-engine-cdn.hasura.io/install-manifests/do-one-click/Caddyfile
}
# setup gcloud cli tool
setup_gcloud( ) {
echo $GCLOUD_SERVICE_KEY > ${ HOME } /gcloud-service-key.json
gcloud auth activate-service-account --key-file= ${ HOME } /gcloud-service-key.json
gcloud --quiet config set project ${ GOOGLE_PROJECT_ID }
}
2019-02-14 12:37:47 +03:00
# push the server binary to google cloud storage
push_server_binary( ) {
gsutil cp /build/_server_output/graphql-engine \
2019-05-16 10:45:29 +03:00
gs://graphql-engine-cdn.hasura.io/server/latest/linux-amd64
2019-02-14 12:37:47 +03:00
}
2018-07-10 13:01:02 +03:00
# skip deploy for pull requests
if [ [ -n " ${ CIRCLE_PR_NUMBER :- } " ] ] ; then
echo "not deploying for PRs"
exit
fi
# required env vars
# DOCKER_USER
# DOCKER_PASSWORD
# GITHUB_TOKEN
# GCLOUD_SERVICE_KEY
# CIRCLE_PROJECT_USERNAME
# CIRCLE_PROJECT_REPONAME
# CIRCLE_TAG
# CIRCLE_PR_NUMBER
# CIRCLE_BRANCH
2018-11-02 13:21:44 +03:00
setup_gcloud
2020-04-01 15:56:54 +03:00
if [ [ -z " $CIRCLE_TAG " ] ] ; then
# channel branch, only update console
echo "channel branch, only deploying console"
export EXPECTED_CHANNEL = " ${ CIRCLE_BRANCH } "
2018-07-10 13:01:02 +03:00
deploy_console
2020-04-01 15:56:54 +03:00
unset EXPECTED_CHANNEL
2018-07-10 13:01:02 +03:00
exit
fi
deploy_console
deploy_server
if [ [ ! -z " $CIRCLE_TAG " ] ] ; then
2020-03-19 15:21:53 +03:00
build_and_push_cli_migrations_image_v2
2021-04-06 12:58:24 +03:00
build_and_push_cli_migrations_image_v3
2020-01-16 09:05:35 +03:00
# if this is a stable release, update all latest assets
if [ $IS_STABLE_RELEASE = true ] ; then
deploy_server_latest
push_server_binary
2020-03-19 15:21:53 +03:00
push_latest_cli_migrations_image_v2
2021-04-06 12:58:24 +03:00
push_latest_cli_migrations_image_v3
2020-01-16 09:05:35 +03:00
send_pr_to_repo graphql-engine-heroku
deploy_do_manifests
fi
# submit a release draft to github
# build changelog
2018-09-29 08:49:24 +03:00
CHANGELOG_TEXT = $( changelog server)
2018-09-26 17:22:28 +03:00
CHANGELOG_TEXT += $( changelog cli)
CHANGELOG_TEXT += $( changelog console)
RELEASE_BODY = $( eval " cat <<EOF
2018-09-29 08:49:24 +03:00
$( <$ROOT /.circleci/release_notes.template.md)
EOF
" )
2018-07-10 13:01:02 +03:00
draft_github_release
2018-07-11 09:49:03 +03:00
fi