Minimise docker layers

This commit is contained in:
Simon Bruder 2019-11-01 16:28:18 +00:00 committed by Jakob Lechner
parent 3e89556ae6
commit aedcc9d9bc
6 changed files with 61 additions and 90 deletions

View file

@ -15,7 +15,6 @@ stages:
- check
- build
dockerimage_builder:
stage: prepare
before_script:
@ -34,7 +33,6 @@ dockerimage_builder:
refs:
- schedules
dockerimage_security_scanner:
stage: prepare
before_script:
@ -71,13 +69,13 @@ security_scanner:
- dedicated
.squashfs_template: &squashfs_template
image: $DOCKER_IMAGE_BUILDER
stage: build
before_script:
- apk add --no-cache make
services:
- docker:dind
script:
- make images/debian-buster.squashfs
- scripts/packer.sh debian-buster
- scripts/torrent.sh debian-buster.squashfs
- find images -type f > images.txt
artifacts:
paths:

View file

@ -58,29 +58,28 @@ images/debian-buster.squashfs: images
docker run \
--rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "${PWD}/packer:/workdir" \
-v "${PWD}/aria2c:/workdir/aria2c" \
-v "${PWD}/images:/images" \
-e "user=`id -u`" \
-e "group=`id -g`" \
-v "${PWD}:${PWD}" \
-w "${PWD}" \
-u `id -u`:`id -g` \
-e "IMAGES=${PWD}/images" \
-e "ANNOUNCE=$(ANNOUNCE)" \
-e "WEBSEED=$(WEBSEED)" \
-e "COMPRESSION_LEVEL=$(COMPRESSION_LEVEL)" \
$(ci_environment) \
"$(DOCKER_IMAGE_BUILDER)" \
scripts/packer.sh \
debian-buster
images/debian-buster.torrent: images
docker run \
--rm \
-v "${PWD}/images:/images" \
-e "user=`id -u`" \
-e "group=`id -g`" \
-v "${PWD}:${PWD}" \
-w "${PWD}" \
-u `id -u`:`id -g` \
-e "ANNOUNCE=$(ANNOUNCE)" \
-e "WEBSEED=$(WEBSEED)" \
-e "TASK=torrent" \
"$(DOCKER_IMAGE_BUILDER)" \
scripts/torrent.sh \
debian-buster
.PHONY: ansible
@ -88,14 +87,14 @@ ansible:
docker run \
--rm \
-v "${PWD}/packer/ansible:/ansible" \
-e "user=`id -u`" \
-e "group=`id -g`" \
-u `id -u`:`id -g` \
-e "ANNOUNCE=$(ANNOUNCE)" \
-e "WEBSEED=$(WEBSEED)" \
-e "TASK=ansible" \
-v "${SSH_AUTH_SOCK}:/var/run/ssh_auth_sock" \
-e "SSH_AUTH_SOCK=/var/run/ssh_auth_sock" \
-w /ansible \
"$(DOCKER_IMAGE_BUILDER)" \
/usr/bin/ansible-playbook \
-i inventories \
$(if $(ANSIBLE_TAGS),-t $(ANSIBLE_TAGS),) \
-l $(ANSIBLE_LIMIT) \

View file

@ -46,7 +46,4 @@ RUN gpg --import /usr/local/share/hashicorp.asc \
WORKDIR /workdir
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
# vim: ts=4 sw=4 sts=4 noet:

View file

@ -1,66 +0,0 @@
#!/bin/sh
set -e
make_torrent() {
(cd /images
if [ "$NAME" = "" ]; then
# remove file extension
NAME="$(echo "$1" | sed 's/\.[^.]*//')"
fi
if [ "$WEBSEED" = "" ]; then
echo '$WEBSEED not provided' >&2
exit 1
fi
if [ "$ANNOUNCE" = "" ]; then
echo '$ANNOUNCE not provided' >&2
exit 1
fi
TORRENT_FILE="$NAME.torrent"
WEBSEED_URL="$WEBSEED/$1"
if [ -e "$TORRENT_FILE" ]; then rm "$TORRENT_FILE"; fi
mktorrent \
-n "$NAME" \
-a "$ANNOUNCE" \
-o "$TORRENT_FILE" \
-l 22 \
-w "$WEBSEED_URL" \
"$1"
if [ "$user" != "" ] && [ "$group" != "" ]; then
chown "$user:$group" "$TORRENT_FILE"
fi
)
}
run_packer() {
packer build "$NAME.json"
if [ "$user" != "" ] && [ "$group" != "" ]; then
chown $user:$group "/images/${NAME}."*
fi
}
NAME="$1"
if [ "$NAME" = "" ]; then
echo 'no name supplied, stopping.' >&2
exit 1
fi
export NAME
if [ -z "$TASK" ] || [ "$TASK" == "packer" ]; then
run_packer
fi
if [ -z "$TASK" ] || [ "$TASK" == "torrent" ]; then
make_torrent "$NAME.squashfs"
fi
if [ "$TASK" == "ansible" ]; then
cd /ansible
/usr/bin/ansible-playbook "$@"
fi

10
scripts/packer.sh Executable file
View file

@ -0,0 +1,10 @@
#!/bin/sh
set -o nounset
export NAME="$1"
mkdir -p images
export IMAGES="$(realpath images)"
cd packer
packer build "$NAME.json"

33
scripts/torrent.sh Executable file
View file

@ -0,0 +1,33 @@
#!/bin/sh
set -o nounset
cd images
NAME="$1"
if [ "$NAME" = "" ]; then
# remove file extension
NAME="$(echo "$1" | sed 's/\.[^.]*//')"
fi
if [ "$WEBSEED" = "" ]; then
echo '$WEBSEED not provided' >&2
exit 1
fi
if [ "$ANNOUNCE" = "" ]; then
echo '$ANNOUNCE not provided' >&2
exit 1
fi
TORRENT_FILE="$NAME.torrent"
WEBSEED_URL="$WEBSEED/$1"
if [ -e "$TORRENT_FILE" ]; then rm "$TORRENT_FILE"; fi
mktorrent \
-n "$NAME" \
-a "$ANNOUNCE" \
-o "$TORRENT_FILE" \
-l 22 \
-w "$WEBSEED_URL" \
"$1"