-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-docker.sh
executable file
·85 lines (70 loc) · 2.76 KB
/
build-docker.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
#!/usr/bin/env bash
# This script is intended to be run by the CI/CD pipeline to build a specific version of this application.
set -Eeo pipefail
LOCAL_BUILD=false
LAMBDA_IMAGE=false
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-n|--service-name)
service_name="$2"
shift # past argument
shift # past value
;;
-v|--service-version)
service_version="$2"
shift # past argument
shift # past value
;;
--local)
LOCAL_BUILD=true
shift # past argument
;;
--lambda_image)
LAMBDA_IMAGE=true
shift # past argument
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
USAGE="USAGE: build-docker.sh -n|--service-name service_name -v|--service-version service_version [--local, --lambda_image]"
# shellcheck disable=SC2154
if [[ -z "${service_name}" ]]; then
echo "service_name required. Name of the service as found in pyproject.toml (e.g. podaac-staging)" >&2
echo "$USAGE" >&2
exit 1
fi
# shellcheck disable=SC2154
if [[ -z "${service_version}" ]]; then
echo "service_version required. Version of software to install (e.g. 0.1.0-a1+12353)." >&2
echo "$USAGE" >&2
exit 1
fi
set -u
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
PROJECT_DIR="$(dirname "${SCRIPTPATH}")"
DIST_PATH="dist/"
repositoryName=podaac/${service_name}
# Docker tags can't include '+' https://github.com/docker/distribution/issues/1201
dockerTagVersion=$(echo "${service_version}" | tr "+" _)
# Build the image
if [ "$LAMBDA_IMAGE" = true ] && [ "$LOCAL_BUILD" = true ]; then
repositoryName=podaac/${service_name}-lambda
wheel_filename="$(echo "${service_name}" | tr "-" _)-${service_version}-py3-none-any.whl"
docker build -t "${repositoryName}":"${dockerTagVersion}" --build-arg DIST_PATH="${DIST_PATH}" --build-arg SOURCE="${DIST_PATH}${wheel_filename}" -f "$SCRIPTPATH"/lambdaDockerfile "$PROJECT_DIR" 1>&2
elif [ "$LAMBDA_IMAGE" = true ] ; then
repositoryName=podaac/${service_name}-lambda
docker build -t "${repositoryName}":"${dockerTagVersion}" --build-arg SOURCE="${service_name}==${service_version}" -f "$SCRIPTPATH"/lambdaDockerfile "$PROJECT_DIR" 1>&2
elif [ "$LOCAL_BUILD" = true ] ; then
wheel_filename="$(echo "${service_name}" | tr "-" _)-${service_version}-py3-none-any.whl"
docker build -t "${repositoryName}":"${dockerTagVersion}" --build-arg DIST_PATH="${DIST_PATH}" --build-arg SOURCE="${DIST_PATH}${wheel_filename}" -f "$SCRIPTPATH"/Dockerfile "$PROJECT_DIR" 1>&2
else
docker build -t "${repositoryName}":"${dockerTagVersion}" --build-arg SOURCE="${service_name}==${service_version}" -f "$SCRIPTPATH"/Dockerfile "$SCRIPTPATH" 1>&2
fi
echo "${repositoryName}":"${dockerTagVersion}"