-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrelease.sh
executable file
·120 lines (98 loc) · 4 KB
/
release.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
#!/bin/bash
echo "Creating a new release"
set -e # exit on error
while getopts "h?dfs" opt; do
case "$opt" in
h|\?)
echo "create and publish a new release. Pass the option -d (for 'devmode') to run without restarting docker or publishing on docker hub"
exit 0
;;
d) devmode=1
echo "running in devmode, will not publish the images in docker hub"
;;
f) output_file=$OPTARG
;;
s) skip_install=1
echo "skip npm install"
;;
esac
done
migration_version=$(cat node_modules/@daostack/subgraph/package.json | jq -r '.devDependencies."@daostack/migration"')
docker_compose_migration_version=$(cat docker-compose.yml | grep daostack/migration | cut -d ":" -f 3 | sed "s/'//")
package_version=$(cat package.json | jq -r '.version')
image_version=$package_version
# check if config is ok
if [[ $docker_compose_migration_version != $migration_version ]]; then
echo "The migration version in the docker-compose file is not the same as the one in package.json of the subgraph dependency ($docker_compose_migration_version != $migration_version)"
exit
fi
echo "Starting fresh docker containers..."
set -x # echo on
docker-compose down -v
docker-compose up -d
set +x
echo "waiting for ganache to start"
while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' 127.0.0.1:8545)" != "400" ]]; do sleep 5; done
set -x
echo "deploying ethereum contracts and doing transactions...."
# clean up local environment
rm -f migration.json
docker-compose exec ganache cat migration.json > migration.json
npm run deployEthereum
echo "waiting for graph-node to start"
set +x
while [[ ! "$(curl -s -o /dev/null -w ''%{http_code}'' 127.0.0.1:8000)" =~ ^(200|302)$ ]]; do sleep 5; done
set -x
# echo pwd
# # Workaround for the fact that `deploySubgraph.js` does not work with the current package
# this workaround requires that we write all artefacts (like the info of the daos created in deployEthereum) in the node_modules package, which is not so nice :-/
cd node_modules/@daostack/subgraph
# if [[ $skip_install != 1 ]]; then
# rm -rf node_modules # must do this to workaround a bug
# npm i
# fi
npm run deploy
cd ../../../
# npm run deploySubgraph
set +x
echo "waiting for subgraph to finish indexing"
while [[ $(curl --silent -H "Content-Type: application/json" -d '{"query":"{ subgraphs (where: { name:\"daostack\"}) { id name currentVersion { deployment { synced }}}}","variables":null,"operationName":null}' -X POST http://localhost:8000/subgraphs \
| jq -r '.data.subgraphs[0].currentVersion.deployment.synced') \
!= true ]]; \
do sleep 5; done
echo "subgraph is done indexing"
echo "Image version: $image_version"
if [[ $devmode == 1 ]]; then
echo "we are in devmode, so we are not published the new images to docker hub"
fi
if [[ $devmode != 1 ]]; then
echo "publish new docker images"
# commit the ganache image
container_id=$(docker ps -f "name=ganache" -l -q)
image_name=daostack/test-env-ganache
echo "docker commit $container_id $image_name:$image_version"
docker commit $container_id $image_name:$image_version
echo "docker push $image_name:$image_version"
docker push $image_name:$image_version
# commit the postgres image
container_id=$(docker ps -f "name=postgres" -l -q)
image_name=daostack/test-env-postgres
echo "docker commit $container_id $image_name:$image_version"
docker commit $container_id $image_name:$image_version
echo "docker push $image_name:$image_version"
docker push $image_name:$image_version
# commit the ipfs image
container_id=$(docker ps -f "name=ipfs" -l -q)
image_name=daostack/test-env-ipfs
echo "docker commit $container_id $image_name:$image_version"
docker commit $container_id $image_name:$image_version
echo "docker push $image_name:$image_version"
docker push $image_name:$image_version
docker-compose down -v
# tag on github
echo "create tag ${image_version}"
git tag -a $image_version -m "Release of version $image_name:$image_version"
git push --tags
# done
echo "Done!"
fi