-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild
More file actions
executable file
·121 lines (111 loc) · 3.73 KB
/
build
File metadata and controls
executable file
·121 lines (111 loc) · 3.73 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env bash
set -eo pipefail
shopt -s expand_aliases
alias podman="podman --cgroup-manager=cgroupfs --events-backend=file"
function clean_before_exit {
# delay before exiting, so stdout/stderr flushes through the logging system
pkill -15 caddy
pkill -15 podman
sleep 3
}
trap clean_before_exit EXIT
function waiting_process {
echo -e "\\033[32m---> Waiting $1 running.\\033[0m"
for i in {0..4}; do
if ps -C "$1" 1>/dev/null ; then
sleep 1
echo -e "\\033[32m---> Process $1 started.\\033[0m"
break
else
if [[ $i == 3 ]]; then
echo -e "\\033[31m---> Process $1 failed.\\033[0m"
exit 1
else
sleep 3
fi
fi
done
}
log_level="error"
if [[ "${DRYCC_DEBUG}" ]]; then
log_level="debug"
unset DRYCC_DEBUG
fi
mkdir -p "${HOME}"/.config/containers
cp -rf /opt/drycc/podman/etc/containers/* "${HOME}"/.config/containers
registries="/etc/imagebuilder/registries.conf"
if [ -f "${registries}" ]; then
cat "${registries}" > "${HOME}"/.config/containers/registries.conf
fi
podman system service --time 0 &
waiting_process podman
if [[ -n "${TAR_PATH}" ]]; then
get_object
tar -xzf /tmp/app.tgz -C /workspace/ && unset TAR_PATH
fi
pack_builder=$(< /etc/imagebuilder/buildpacks tr -d '[:space:]')
if [[ -f .pack-builder ]]; then
pack_builder=$(< .pack-builder tr -d '[:space:]')
fi
# Get registry and login
if [[ "${DRYCC_REGISTRY_LOCATION}" == "off-cluster" ]] ; then
podman login \
--username "${DRYCC_REGISTRY_USERNAME}" \
--password "${DRYCC_REGISTRY_PASSWORD}" \
"${DRYCC_REGISTRY_HOST}" \
--tls-verify=false > /dev/null
else
# Start registry proxy
DRYCC_REGISTRY_PROXY_HOST="${DRYCC_REGISTRY_PROXY_HOST:?DRYCC_REGISTRY_PROXY_HOST env required}"
DRYCC_REGISTRY_PROXY_PORT=$(echo "${DRYCC_REGISTRY_PROXY_HOST}" | awk -F ':' '{print $2}')
caddy_command="caddy reverse-proxy \
--from :${DRYCC_REGISTRY_PROXY_PORT} \
--to ${DRYCC_REGISTRY_HOST}"
if [[ ${log_level} != "debug" ]] ; then
caddy_command="${caddy_command} > /dev/null"
fi
$caddy_command 2>&1 &
waiting_process caddy
podman login \
--username "${DRYCC_REGISTRY_USERNAME}" \
--password "${DRYCC_REGISTRY_PASSWORD}" \
"${DRYCC_REGISTRY_PROXY_HOST}" \
--tls-verify=false > /dev/null
fi
# Get image name and image tag
image_base_name=$(echo "${IMAGE_NAME}" | awk -F ':' '{print $1}')
image_cache_name="${image_base_name}":cache
image_latest_name="${image_base_name}":latest
# Building
if [[ "${DRYCC_STACK}" == "container" ]] ; then
echo "---> Building container"
if [[ $log_level == "debug" ]] ; then
podman build --tag"${IMAGE_NAME}" --network host .
podman push "${IMAGE_NAME}" --tls-verify=false
else
podman build --quiet --tag "${IMAGE_NAME}" --network host .
podman push "${IMAGE_NAME}" --quiet --tls-verify=false
fi
else
echo "---> Building pack"
echo "---> Using builder ${pack_builder}"
# podman connection
readonly DOCKER_HOST="unix://$(podman info -f "{{.Host.RemoteSocket.Path}}")"
export DOCKER_HOST
pack_command="pack build ${IMAGE_NAME} \
--builder ${pack_builder} \
--docker-host ${DOCKER_HOST} \
--previous-image ${image_latest_name} \
--trust-builder \
--publish \
--cache-image ${image_cache_name} \
--tag ${image_latest_name} \
--network host"
if [[ $log_level == "debug" ]] ; then
pack_command="$pack_command --verbose"
fi
if [[ -f .clear-cache ]]; then
pack_command="$pack_command --clear-cache"
fi
$pack_command
fi