forked from berkeley-dsep-infra/jupyterhub-k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.bash
executable file
·55 lines (46 loc) · 1.62 KB
/
build.bash
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
#!/bin/bash
# Builds and pushes a given image to gcr.io + all nodes in current kubectl context
set -e
IMAGE_TYPES=$(jq -r '.buildSettings.imageTypes' 'docker-settings.json')
if [ -z "$1" ]; then
echo "Usage: $0 {hub,user,proxy {base${IMAGE_TYPES}}}"
exit 1
fi
# Bail if we're on a dirty git tree
if ! git diff-index --quiet HEAD; then
echo "You have uncommited changes. Please commit them before building and populating"
echo "This helps ensure that all docker images are traceable back to a git commit"
echo "If you push anyway Yuvi will be sad :("
exit 1
fi
kubectl cluster-info | grep -q azure | true
if [ ${PIPESTATUS[1]} -eq 0 ]; then
DOCKER_REPO=$(jq -r '.buildSettings.dockerRepo.azure' 'docker-settings.json')
DOCKER_PUSH="docker push"
else
DOCKER_REPO=$(jq -r '.buildSettings.dockerRepo.gcloud' 'docker-settings.json')
DOCKER_PUSH="gcloud docker -- push"
fi
IMAGE="$1"
GIT_REV=$(git log -n 1 --pretty=format:%h -- ${IMAGE})
TAG="${GIT_REV}"
if [ "${IMAGE}" == "user" ]; then
USER_IMAGE_TYPE="${2}"
DOCKERFILE="Dockerfile.${USER_IMAGE_TYPE}"
IMAGE_SPEC="${DOCKER_REPO}/jupyterhub-k8s-${IMAGE}-${USER_IMAGE_TYPE}:${TAG}"
else
DOCKERFILE="Dockerfile"
IMAGE_SPEC="${DOCKER_REPO}/jupyterhub-k8s-${IMAGE}:${TAG}"
fi
cd ${IMAGE}
if [ ! -f ${DOCKERFILE} ]; then
echo "No such file: ${IMAGE}/${DOCKERFILE}"
exit 1
fi
docker build -t ${IMAGE_SPEC} -f ${DOCKERFILE} .
${DOCKER_PUSH} ${IMAGE_SPEC}
echo "Pushed ${IMAGE_SPEC}"
echo "To populate all nodes in current context with this image, run:"
_cmd=" ./populate.bash %-4s %s\n"
printf "${_cmd}" "dev" "${IMAGE_SPEC}"
printf "${_cmd}" "prod" "${IMAGE_SPEC}"