Merge docker images
This commit is contained in:
parent
73e65f0500
commit
1cb4ca513c
7 changed files with 105 additions and 118 deletions
|
|
@ -1,11 +1,11 @@
|
|||
image: docker:latest
|
||||
|
||||
variables:
|
||||
GIT_STRATEGY: fetch
|
||||
PACKER_VERSION: 1.2.0
|
||||
ANNOUNCE: http://10.105.255.0:6969/announce
|
||||
WEBSEED: http://10.105.255.0/labsync/$CI_COMMIT_REF_NAME/$CI_PIPELINE_ID/images
|
||||
PACKER_DOCKER_IMAGE: ${CI_REGISTRY_IMAGE}/packer
|
||||
MKTORRENT_DOCKER_IMAGE: ${CI_REGISTRY_IMAGE}/mktorrent
|
||||
DOCKER_IMAGE: ${CI_REGISTRY_IMAGE}/labsync-builder
|
||||
|
||||
stages:
|
||||
- prepare
|
||||
|
|
@ -25,8 +25,7 @@ dockerimage:
|
|||
script:
|
||||
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
|
||||
- make dockerimg
|
||||
- docker push $PACKER_DOCKER_IMAGE
|
||||
- docker push $MKTORRENT_DOCKER_IMAGE
|
||||
- docker push $DOCKER_IMAGE
|
||||
tags:
|
||||
- fablab
|
||||
|
||||
|
|
@ -41,14 +40,3 @@ squashfs:
|
|||
tags:
|
||||
- fablab
|
||||
|
||||
mktorrent:
|
||||
stage: torrent
|
||||
script:
|
||||
- make images/debian-stretch.torrent
|
||||
artifacts:
|
||||
paths:
|
||||
- images
|
||||
expire_in: 2 weeks
|
||||
tags:
|
||||
- fablab
|
||||
|
||||
|
|
|
|||
19
Makefile
19
Makefile
|
|
@ -2,8 +2,7 @@ PACKER_VERSION ?= 1.2.0
|
|||
ANNOUNCE ?= http://10.2.2.1:6969/announce
|
||||
WEBSEED ?= http://10.2.2.1
|
||||
|
||||
PACKER_DOCKER_IMAGE ?= labsync-packer
|
||||
MKTORRENT_DOCKER_IMAGE ?= labsync-mktorrent
|
||||
DOCKER_IMAGE ?= labsync-builder
|
||||
|
||||
CWD=$(abspath $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
|
||||
|
||||
|
|
@ -27,7 +26,7 @@ fi \
|
|||
)
|
||||
|
||||
.PHONY: default
|
||||
default: dockerimg images/debian-stretch.squashfs images/debian-stretch.torrent
|
||||
default: dockerimg images/debian-stretch.squashfs
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
|
|
@ -36,8 +35,7 @@ clean:
|
|||
|
||||
.PHONY: dockerimg
|
||||
dockerimg:
|
||||
docker build -t "$(PACKER_DOCKER_IMAGE)" --build-arg "PACKER_VERSION=$(PACKER_VERSION)" packer/docker
|
||||
docker build -t "$(MKTORRENT_DOCKER_IMAGE)" mktorrent
|
||||
docker build -t "$(DOCKER_IMAGE)" --build-arg "PACKER_VERSION=$(PACKER_VERSION)" docker
|
||||
|
||||
images:
|
||||
[ ! -d "$@" ] && mkdir "$@"
|
||||
|
|
@ -51,19 +49,22 @@ images/debian-stretch.squashfs: images
|
|||
-v "${PWD}/images:/images" \
|
||||
-e "user=`id -u`" \
|
||||
-e "group=`id -g`" \
|
||||
"$(PACKER_DOCKER_IMAGE)" \
|
||||
-e "ANNOUNCE=$(ANNOUNCE)" \
|
||||
-e "WEBSEED=$(WEBSEED)" \
|
||||
"$(DOCKER_IMAGE)" \
|
||||
debian-stretch
|
||||
|
||||
images/debian-stretch.torrent: images
|
||||
docker run \
|
||||
--rm \
|
||||
-v "${PWD}/images:/workdir" \
|
||||
-v "${PWD}/images:/images" \
|
||||
-e "user=`id -u`" \
|
||||
-e "group=`id -g`" \
|
||||
-e "ANNOUNCE=$(ANNOUNCE)" \
|
||||
-e "WEBSEED=$(WEBSEED)" \
|
||||
"$(MKTORRENT_DOCKER_IMAGE)" \
|
||||
debian-stretch.squashfs
|
||||
-e "TASK=torrent" \
|
||||
"$(DOCKER_IMAGE)" \
|
||||
debian-stretch
|
||||
|
||||
# updates the initramfs
|
||||
# only used for development
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ FROM docker:dind
|
|||
|
||||
RUN apk add --no-cache \
|
||||
ansible \
|
||||
mktorrent \
|
||||
openssh-client \
|
||||
squashfs-tools
|
||||
|
||||
91
docker/entrypoint.sh
Executable file
91
docker/entrypoint.sh
Executable file
|
|
@ -0,0 +1,91 @@
|
|||
#!/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-borg \
|
||||
-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 "$PACKER_JSON"
|
||||
|
||||
mkdir -p build/rootfs
|
||||
tar xf build/rootfs.tar -C build/rootfs
|
||||
|
||||
mv build/rootfs/artifacts/initramfs "/images/$INITRAMFS_FILE"
|
||||
mv build/rootfs/artifacts/linux "/images/$LINUX_FILE"
|
||||
|
||||
rm -rf build/rootfs/artifacts
|
||||
|
||||
rm -- \
|
||||
build/rootfs/.dockerenv \
|
||||
build/rootfs/initrd.* \
|
||||
build/rootfs/vmlinuz*
|
||||
|
||||
if [ -e "/images/$SQUASHFS_FILE" ]; then
|
||||
rm "/images/$SQUASHFS_FILE"
|
||||
fi
|
||||
|
||||
mksquashfs build/rootfs "/images/$SQUASHFS_FILE" \
|
||||
-comp lzo \
|
||||
-Xcompression-level 9
|
||||
|
||||
rm -rf build
|
||||
|
||||
if [ "$user" != "" ] && [ "$group" != "" ]; then
|
||||
chown $user:$group \
|
||||
"/images/$INITRAMFS_FILE" \
|
||||
"/images/$LINUX_FILE" \
|
||||
"/images/$SQUASHFS_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
NAME="$1"
|
||||
|
||||
if [ "$NAME" = "" ]; then
|
||||
echo 'no name supplied, stopping.' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export PACKER_JSON="$NAME.json"
|
||||
export INITRAMFS_FILE="$NAME.initramfs"
|
||||
export LINUX_FILE="$NAME.linux"
|
||||
export SQUASHFS_FILE="$NAME.squashfs"
|
||||
|
||||
if [ -z "$TASK" ] || [ "$TASK" == "packer" ]; then
|
||||
run_packer
|
||||
fi
|
||||
if [ -z "$TASK" ] || [ "$TASK" == "torrent" ]; then
|
||||
make_torrent "$NAME.squashfs"
|
||||
fi
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
FROM alpine
|
||||
|
||||
RUN apk add --no-cache mktorrent \
|
||||
&& mkdir /workdir
|
||||
|
||||
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||
|
||||
WORKDIR /workdir
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
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-borg \
|
||||
-n "$NAME" \
|
||||
-a "$ANNOUNCE" \
|
||||
-o "$TORRENT_FILE" \
|
||||
-l 22 \
|
||||
-w "$WEBSEED_URL" \
|
||||
"$1"
|
||||
|
||||
if [ "$user" != "" ] && [ "$group" != "" ]; then
|
||||
chown "$user:$group" "$TORRENT_FILE"
|
||||
fi
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
NAME="$1"
|
||||
|
||||
if [ "$NAME" = "" ]; then
|
||||
echo 'no name supplied, stopping.' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PACKER_JSON="$NAME.json"
|
||||
INITRAMFS_FILE="$NAME.initramfs"
|
||||
LINUX_FILE="$NAME.linux"
|
||||
SQUASHFS_FILE="$NAME.squashfs"
|
||||
|
||||
packer build "$PACKER_JSON"
|
||||
|
||||
mkdir -p build/rootfs
|
||||
tar xf build/rootfs.tar -C build/rootfs
|
||||
|
||||
mv build/rootfs/artifacts/initramfs "/images/$INITRAMFS_FILE"
|
||||
mv build/rootfs/artifacts/linux "/images/$LINUX_FILE"
|
||||
|
||||
rm -rf build/rootfs/artifacts
|
||||
|
||||
rm -- \
|
||||
build/rootfs/.dockerenv \
|
||||
build/rootfs/initrd.* \
|
||||
build/rootfs/vmlinuz*
|
||||
|
||||
if [ -e "/images/$SQUASHFS_FILE" ]; then
|
||||
rm "/images/$SQUASHFS_FILE"
|
||||
fi
|
||||
|
||||
mksquashfs build/rootfs "/images/$SQUASHFS_FILE" \
|
||||
-comp lzo \
|
||||
-Xcompression-level 9
|
||||
|
||||
rm -rf build
|
||||
|
||||
if [ "$user" != "" ] && [ "$group" != "" ]; then
|
||||
chown $user:$group \
|
||||
"/images/$INITRAMFS_FILE" \
|
||||
"/images/$LINUX_FILE" \
|
||||
"/images/$SQUASHFS_FILE"
|
||||
fi
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue