1#!/bin/bash
2
3# Create a set of CHART framework docker images
4
5# Current directory
6HERE="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
7
8# Read configuration file
9BUILD_ENV="${HERE}/framework.env"
10if [[ ! -f "${BUILD_ENV}" ]]; then
11 echo "Cannot find build configuration ${BUILD_ENV}"
12 exit -1
13fi
14source "${BUILD_ENV}"
15
16# Display configuration information
17echo "From configuration file ${BUILD_ENV}:"
18echo " Creating docker prereq image: ${CHART_PREREQ_IMAGE_NAME}"
19echo " Creating docker framework image: ${CHART_FRAMEWORK_IMAGE_NAME}"
20echo " Creating docker proxy image: ${CHART_PROXY_IMAGE_NAME}"
21echo ""
22
23# Read VCS info
24FRAMEWORK_VCS_BRANCH=$(git rev-parse --abbrev-ref HEAD)
25FRAMEWORK_VCS_TAG=$(git tag --points-at HEAD)
26FRAMEWORK_VCS_COMMIT=$(git rev-parse HEAD)
27echo "From git:"
28echo " Framework git branch: ${FRAMEWORK_VCS_BRANCH}"
29echo " Framework git tag: ${FRAMEWORK_VCS_TAG}"
30echo " Framework git commit: ${FRAMEWORK_VCS_COMMIT}"
31echo ""
32
33# Read system info
34FRAMEWORK_BUILD_USER=$(whoami)
35FRAMEWORK_BUILD_HOST=$(hostname)
36FRAMEWORK_BUILD_DIR=$(pwd)
37echo "From system info:"
38echo " User: ${FRAMEWORK_BUILD_USER}"
39echo " Host: ${FRAMEWORK_BUILD_HOST}"
40echo " Directory: ${FRAMEWORK_BUILD_DIR}"
41# echo " Dirty build: ${FRAMEWORK_BUILD_DIRTY}"
42echo ""
43
44# Test for uncommitted changes
45if [[ -n "$(git status -s)" ]]; then
46 echo -n ""
47 echo -n "WARNING: This directory contains local changes which are not commited to git. "
48 echo -n "The build can continue but the images must not be used for any formal deployments "
49 echo "and will be marked as a dirty build."
50 echo ""
51 FRAMEWORK_BUILD_DIRTY=1
52else
53 FRAMEWORK_BUILD_DIRTY=0
54fi
55
56# Check VCS tags are set
57if [[ "${FRAMEWORK_VCS_TAG}" == "" ]]; then
58 echo -n "WARNING: No git tag set for the framework. Make sure to create one before building "
59 echo "images for formal deployment"
60 echo ""
61 FRAMEWORK_BUILD_DIRTY=1
62fi
63
64# Pause to let the user consider
65if [[ "${CHART_NO_PROMPT_BUILD}" != "1" ]]; then
66 echo "Press ENTER to continue"
67 read
68fi
69
70# Run everything from the repository top directory
71cd ${HERE}/..
72
73# Log to tmp/buildlogs/
74LOGS="$(realpath --canonicalize-missing --relative-to=$PWD ${HERE}/../tmp/buildlogs)"
75mkdir -p "${LOGS}"
76# echo "Logging to ${LOGS}"
77
78# build and tag prerequisites image
79PREREQ_LOG="${LOGS}/build-prereq.log"
80echo "Building prereq image logging to ${PREREQ_LOG}"
81docker buildx build \
82 . \
83 --tag "${CHART_PREREQ_IMAGE_NAME}" \
84 --file docker/prereq/Dockerfile > "${PREREQ_LOG}"
85echo "Tagged ${CHART_PREREQ_IMAGE_NAME}"
86# exit 0
87
88# Build and tag CHART framework image
89FRAMEWORK_LOG="${LOGS}/build-framework.log"
90echo "Building framework image logging to ${FRAMEWORK_LOG}"
91docker buildx build \
92 --build-arg "PREREQ_IMAGE_NAME=${CHART_PREREQ_IMAGE_NAME}" \
93 --build-arg "FRAMEWORK_VCS_BRANCH=${FRAMEWORK_VCS_BRANCH}" \
94 --build-arg "FRAMEWORK_VCS_TAG=${FRAMEWORK_VCS_TAG}" \
95 --build-arg "FRAMEWORK_VCS_COMMIT=${FRAMEWORK_VCS_COMMIT}" \
96 --build-arg "FRAMEWORK_BUILD_USER=${FRAMEWORK_BUILD_USER}" \
97 --build-arg "FRAMEWORK_BUILD_HOST=${FRAMEWORK_BUILD_HOST}" \
98 --build-arg "FRAMEWORK_BUILD_DIR=${FRAMEWORK_BUILD_DIR}" \
99 --build-arg "FRAMEWORK_BUILD_DIRTY=${FRAMEWORK_BUILD_DIRTY}" \
100 --tag "${CHART_FRAMEWORK_IMAGE_NAME}" \
101 . \
102 --file docker/framework/Dockerfile > "${FRAMEWORK_LOG}"
103echo "Tagged ${CHART_FRAMEWORK_IMAGE_NAME}"
104# exit 0
105
106# Build and tag web proxy image
107PROXY_LOG="${LOGS}/build-proxy.log"
108echo "Building proxy image logging to ${PROXY_LOG}"
109docker buildx build \
110 --build-arg "PROXY_VCS_BRANCH=${FRAMEWORK_VCS_BRANCH}" \
111 --build-arg "PROXY_VCS_TAG=${FRAMEWORK_VCS_TAG}" \
112 --build-arg "PROXY_BUILD_DIRTY=${FRAMEWORK_BUILD_DIRTY}" \
113 --build-arg "PROXY_VCS_COMMIT=${FRAMEWORK_VCS_COMMIT}" \
114 --build-arg "PROXY_BUILD_USER=${FRAMEWORK_BUILD_USER}" \
115 --build-arg "PROXY_BUILD_HOST=${FRAMEWORK_BUILD_HOST}" \
116 --build-arg "PROXY_BUILD_DIR=${FRAMEWORK_BUILD_DIR}" \
117 --build-arg "PROXY_BUILD_DIRTY=${FRAMEWORK_BUILD_DIRTY}" \
118 --tag "${CHART_PROXY_IMAGE_NAME}" \
119 . \
120 --file docker/proxy/Dockerfile > "${PROXY_LOG}"
121echo "Tagged ${CHART_PROXY_IMAGE_NAME}"