This repository was archived by the owner on Aug 30, 2024. It is now read-only.
forked from polkadot-js/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker.sh
More file actions
executable file
·75 lines (61 loc) · 1.57 KB
/
docker.sh
File metadata and controls
executable file
·75 lines (61 loc) · 1.57 KB
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
#!/bin/bash
# Copyright 2019 @polkadot/tools authors & contributors
# This software may be modified and distributed under the terms
# of the Apache-2.0 license. See the LICENSE file for details.
# fail fast on any non-zero exits
set -e
# the option as passed on the commandline
CMD="$1"
# the docker image name and dockerhub repo
NAME="polkadot-js-tools"
REPO="jacogr"
# extract the current npm version from package.json
VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| sed 's/ //g')
# helper function for the build logic
function build () {
echo "*** Creating Dockerfile from latest npm version"
sed "s/VERSION/$VERSION/g" Dockerfile.tmpl > Dockerfile
echo "*** Building $NAME"
docker build -t $NAME .
exit 0
}
# helper function for the publishing logic
function publish () {
if [ -n "$DOCKER_PASS" ]; then
docker login -u $REPO -p $DOCKER_PASS
fi
echo "*** Tagging $REPO/$NAME"
docker tag $NAME $REPO/$NAME
echo "*** Publishing $NAME"
docker push $REPO/$NAME
exit 0
}
# helper function for the usage logic
function usage () {
echo "This builds a docker image for the latest npm published version."
echo "For maintainers publishing functionality is also provided."
echo ""
echo "Usage: docker.sh <build|publish>"
echo "Commands:"
echo " build: builds a $NAME docker image"
echo " publish: publishes a built image to dockerhub"
echo ""
exit 1
}
# execute the command specified
case $CMD in
build)
build
;;
publish)
publish
;;
*)
usage
;;
esac