This repository has been archived by the owner on Mar 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 728
/
deploy.sh
executable file
·136 lines (103 loc) · 4.26 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
#
# 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.
#
# Exit on first error, print all commands.
set -ev
set -o pipefail
# Grab the parent (root) directory.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
date
ME=`basename "$0"`
source ${DIR}/build.cfg
if [ "${ABORT_BUILD}" = "true" ]; then
echo exiting early from ${ME}
exit ${ABORT_CODE}
fi
# Check that this is the right node.js version.
if [ "${TRAVIS_NODE_VERSION}" != "" -a "${TRAVIS_NODE_VERSION}" != "8" ]; then
echo Not executing as not running primary node.js version.
exit 0
fi
# Check that this is not the system tests.
if [ "${SYSTEST}" != "" ]; then
echo Not executing as running system tests.
exit 0
fi
# Check that this is the main repository.
if [[ "${TRAVIS_REPO_SLUG}" != hyperledger* ]]; then
echo "Skipping deploy; wrong repository slug."
exit 0
fi
# Set the NPM access token we will use to publish.
npm config set registry https://registry.npmjs.org/
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
# Set the GitHub deploy key we will use to publish.
set-up-ssh --key "$encrypted_c6d9af089ec4_key" \
--iv "$encrypted_c6d9af089ec4_iv" \
--path-encrypted-key ".travis/github_deploy_key.enc"
# Change from HTTPS to SSH.
./.travis/fix_github_https_repo.sh
# Test the GitHub deploy key.
git ls-remote
# Log in to Docker Hub.
docker login -u="${DOCKER_USERNAME}" -p="${DOCKER_PASSWORD}"
# This is the list of Docker images to build.
export DOCKER_IMAGES="vehicle-manufacture-car-builder vehicle-manufacture-manufacturing vehicle-manufacture-vda letters-of-credit"
# Push the code to npm.
if [ -z "${TRAVIS_TAG}" ]; then
# Set the prerelease version.
npm run pkgstamp
export VERSION=$(node -e "console.log(require('${DIR}/package.json').version)")
# Publish with unstable tag. These are development builds.
echo "Pushing with tag unstable"
lerna exec --ignore '@(digitalproperty-app|vehicle-manufacture)' -- npm publish --tag=unstable 2>&1 | tee
# Build, tag, and publish Docker images.
for i in ${DOCKER_IMAGES}; do
# Build the image and tag it with the version and unstable.
docker build --build-arg VERSION=${VERSION} -t hyperledger/${i}:${VERSION} ${DIR}/packages/${i}
docker tag hyperledger/${i}:${VERSION} hyperledger/${i}:unstable
# Push both the version and unstable.
docker push hyperledger/${i}:${VERSION}
docker push hyperledger/${i}:unstable
done
else
# Grab the current version.
export VERSION=$(node -e "console.log(require('${DIR}/package.json').version)")
# Publish with latest tag (default). These are release builds.
echo "Pushing with tag latest"
lerna exec --ignore '@(digitalproperty-app|vehicle-manufacture)' -- npm publish 2>&1 | tee
# Build, tag, and publish Docker images.
for i in ${DOCKER_IMAGES}; do
# Build the image and tag it with the version and latest.
docker build --build-arg VERSION=${VERSION} -t hyperledger/${i}:${VERSION} ${DIR}/packages/${i}
docker tag hyperledger/${i}:${VERSION} hyperledger/${i}:latest
# Push both the version and latest.
docker push hyperledger/${i}:${VERSION}
docker push hyperledger/${i}:latest
done
# Configure the Git repository and clean any untracked and unignored build files.
git config user.name "${GH_USER_NAME}"
git config user.email "${GH_USER_EMAIL}"
git checkout -b master
git reset --hard
git clean -d -f
# Bump the version number.
npm run pkgbump
export NEW_VERSION=$(node -e "console.log(require('${DIR}/package.json').version)")
# Add the version number changes and push them to Git.
git add .
git commit -m "Automatic version bump to ${NEW_VERSION}"
git push origin master
fi
date