-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·58 lines (45 loc) · 1.71 KB
/
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
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
#!/usr/bin/env bash
# Build images.
# Arguments are prepended to the `docker-compose build` command argument array
# (before the service name)
#
# Possible values are:
# --force-rm Always remove intermediate containers.
# --no-cache Do not use cache when building the image.
# --pull Always attempt to pull a newer version of the image.
# --build-arg key=val Set build-time variables for one service.
HUB_ID="oxyure"
SERVICES="base base-sh mariadb mini busybox"
function prune_docker {
echo -e "\n ### Do some cleaning…\n"
docker container prune --force
docker image prune --force
}
function flatten {
# Service is given as argument. ***The image `$HUB_ID/$1:latest-full` is supposed to exist.***
# Then `$HUB_ID/$1:latest` will be created and the original image deleted.
echo -e "\n ### Flattening $HUB_ID/$1:latest-full\n"
RANDNAME="$(echo $RANDOM |sha512sum |cut -d' ' -f1)"
docker run -d --name "$RANDNAME" "$HUB_ID/$1:latest-full"
docker stop "$RANDNAME"
docker export -o "/tmp/$RANDNAME.tar" "$RANDNAME"
docker import \
--change 'WORKDIR /' \
--change 'USER root' \
--change 'ENTRYPOINT ["/sbin/tini","/bin/su","-l","-c","/bin/sh","operator"]' \
--message "/tmp/$RANDNAME.tar" \
"/tmp/$RANDNAME.tar" "$HUB_ID/$1:latest"
rm "/tmp/$RANDNAME.tar"
docker rm "$RANDNAME"
docker rmi "$HUB_ID/$1:latest-full"
}
for service in ${SERVICES}; do
echo -e "\n ### Building image \"${service}\"\n"
echo -e "docker-compose build $@ ${service}\n"
docker-compose build $@ ${service}
done
echo -e "\n ### All builds finished\n"
flatten 'mini'
prune_docker
docker image ls
exit 0