-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·25 lines (19 loc) · 991 Bytes
/
build.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
#!/bin/sh
set -e
export DOCKER_REGISTRY_REPO="${DOCKER_REGISTRY_REPO:-"$(basename "$PWD")"}"
export VERSION=$(cat version.txt)
echo "Image version ${VERSION}."
echo "Attempting to pull existing image for cache..."
docker pull "${DOCKER_REGISTRY_REPO}:${VERSION}" || true
echo "Building image..."
docker build --cache-from "${DOCKER_REGISTRY_REPO}:${VERSION}" --build-arg "VERSION=${VERSION}" -t "${DOCKER_REGISTRY_REPO}:${VERSION}" .
echo "Image ready."
if [ -n "${DOCKER_REGISTRY}" ] && [ -n "${DOCKER_REGISTRY_USER}" ] && [ -n "${DOCKER_REGISTRY_PASSWORD}" ]
then
echo "Logging into ${DOCKER_REGISTRY}..."
docker login -u="${DOCKER_REGISTRY_USER}" -p="${DOCKER_REGISTRY_PASSWORD}" "${DOCKER_REGISTRY}"
echo "Pushing image to ${DOCKER_REGISTRY_REPO}:${VERSION}..."
docker push "${DOCKER_REGISTRY_REPO}:${VERSION}"
else
echo "Lengths: DOCKER_REGISTRY ${#DOCKER_REGISTRY}, DOCKER_REGISTRY_USER ${#DOCKER_REGISTRY_USER}, DOCKER_REGISTRY_PASSWORD ${#DOCKER_REGISTRY_PASSWORD}"
fi