This repository was archived by the owner on Oct 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_or_deploy.sh
executable file
·102 lines (93 loc) · 3.54 KB
/
build_or_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
#!/bin/bash -x
# jiveapi Docker build and push script
################################################################################
# The latest version of this package is available at:
#<http://github.com/jantman/jiveapi>
#
################################################################################
#Copyright 2017 Jason Antman <[email protected]> <http://www.jasonantman.com>
#
# This file is part of jiveapi, also known as jiveapi.
#
# jiveapi is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# jiveapi is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with jiveapi. If not, see <http://www.gnu.org/licenses/>.
#
#The Copyright and Authors attributions contained herein may not be removed or
#otherwise altered, except to add the Author attribution of a contributor to
#this work. (Additional Terms pursuant to Section 7b of the AGPL v3)
################################################################################
#While not legally required, I sincerely request that anyone who finds
#bugs please submit them at <https://github.com/jantman/jiveapi> or
#to me via email, and that you send any contributions or improvements
#either as a pull request on GitHub, or to me via email.
################################################################################
#
#AUTHORS:
#Jason Antman <[email protected]> <http://www.jasonantman.com>
################################################################################
set -x
set -e
if [ -z "$1" ]; then
>&2 echo "USAGE: do_docker.sh [build|dockerbuild|push]"
exit 1
fi
function gettag {
# if it's a build of a tag, return that right away
[ ! -z "$TRAVIS_TAG" ] && { echo $TRAVIS_TAG; return 0; }
# otherwise, prefix with PR number if available
prefix=''
[ ! -z "$TRAVIS_PULL_REQUEST" ] && [[ "$TRAVIS_PULL_REQUEST" != "false" ]] && prefix="PR${TRAVIS_PULL_REQUEST}_"
ref="test_${prefix}$(git rev-parse --short HEAD)_$(date +%s)"
echo "${ref}"
}
function getversion {
python -c 'from jiveapi.version import VERSION; print(VERSION)'
}
function dockertoxbuild {
tag=$(gettag)
version=$(getversion)
echo "Building Docker image..."
cp "${TOXDISTDIR}/jiveapi-${version}.zip" jiveapi.zip
docker build --build-arg version="$tag" --build-arg jiveapi_version="$version" --no-cache -t "jantman/jiveapi:${tag}" .
echo "Built image and tagged as: jantman/jiveapi:${tag}"
}
function pythonbuild {
rm -Rf dist
python setup.py sdist bdist_wheel
ls -l dist
}
function dockerpush {
tag=$(gettag)
if [[ "$TRAVIS" == "true" ]]; then
echo "$DOCKER_HUB_PASS" | docker login -u "$DOCKER_HUB_USER" --password-stdin
fi
docker images
echo "Pushing Docker image: jantman/jiveapi:${tag}"
docker push "jantman/jiveapi:${tag}"
}
function pythonpush {
pip install twine
twine upload dist/*
}
if [[ "$1" == "build" ]]; then
tox -r -e docker
pythonbuild
elif [[ "$1" == "dockerbuild" ]]; then
dockertoxbuild
elif [[ "$1" == "push" ]]; then
dockerpush
pythonpush
else
>&2 echo "USAGE: do_docker.sh [build|dockerbuild|push]"
exit 1
fi