diff options
-rw-r--r-- | Makefile | 15 | ||||
-rw-r--r-- | README.md | 28 | ||||
-rw-r--r-- | VERSION | 1 | ||||
-rwxr-xr-x | create_container | 59 | ||||
-rw-r--r-- | setup.d/10_base | 3 |
5 files changed, 97 insertions, 9 deletions
@@ -4,7 +4,7 @@ REGISTRY=docker.automotivelinux.org REPO=agl NAME=worker -VERSION=2.1 +VERSION=$(shell tail -1 VERSION) # --------------------------------------------------- # --- computed - don't touch ! @@ -24,6 +24,7 @@ help: @echo "- push-latest: push the image to registry $(REGISTRY) and also tag as 'latest'" @echo "- export: export the image to a compressed archive" @echo "- export-latest: export the latest image to a compressed archive" + @echo "- show-image: dumps the current image name" @echo "" @echo "Variables:" @echo "- Docker registry: REGISTRY=$(REGISTRY)" @@ -58,13 +59,7 @@ clean: # remove spurious containers and images left by broken builds .PHONY:distclean distclean: clean - @for imgid in $$(docker images | grep "^<none>" | awk '{print $$3}'); do \ - for cntid in $$(docker ps -a -f ancestor=$$imgid --format "{{.ID}}"); do \ - echo "Stop container $$cntid"; \ - docker stop $$cntid; \ - echo "Remove container $$cntid"; \ - docker rm $$cntid; \ - done; \ + for imgid in $$(docker images | grep "^<none>" | awk '{print $$3}'); do \ echo "Remove image $$imgid"; \ docker rmi $$imgid; \ done @@ -103,3 +98,7 @@ export: @echo "Export image to docker_$(REPO)_$(NAME)-$(VERSION).tar.xz" docker save $(IMAGE_NAME) | xz -T0 -c >docker_$(REPO)_$(NAME)-$(VERSION).tar.xz +.PHONY:show-image +show-image: + @echo $(IMAGE_NAME) + @@ -45,4 +45,30 @@ In turn, this setup script will: When the setup script finishes, Docker commits the temporary container in a new image. -This image can then be exported to a tarball and/or pushed to a Docker registry.
\ No newline at end of file +This image can then be exported to a tarball and/or pushed to a Docker registry. + +## Using the generated image + +### Grab the image + +To publish the image, there are 2 ways: using a docker registry OR exporting to a tarball. + +In the first case, using the image is very easy as it can be pulled directly from the registry host using a 'docker pull' command. The main issue with this method is the efficiency: images are not compressed and it takes ages to transfer overlays to the client host. + +In the second case, the efficiency is better but requires to transfer the image archive manually. On the client host, loading the image is as simple as: + +``` +# wget -O - <archive_url> | docker load +``` + +### Instantiate a container + +The following command can be used as an example to instantiate a container: + + +``` +# ./create_container 0 +``` + +To instantiate more containers on the same host, the instance ID passed as argument must be different from the previous ones. + @@ -0,0 +1 @@ +2.1 diff --git a/create_container b/create_container new file mode 100755 index 0000000..74c7dc7 --- /dev/null +++ b/create_container @@ -0,0 +1,59 @@ +#!/bin/bash + +CURDIR=$(cd $(dirname $0) && pwd -P) +DEFIMAGE=$(make -s -C $CURDIR show-image) + +function usage() { + echo "Usage: $(basename $0) <instance ID> [image name]" >&2 + echo "Instance ID must be 0 or a positive integer (1,2,...)" >&2 + echo "Image name is optional: 'make show-image' is used by default to get image" >&2 + echo "Default image: $DEFIMAGE" >&2 + exit 1 +} + +case $1 in + -h|--help|"") + usage + ;; +esac + +CURDIR=$(cd $(dirname $0) && pwd -P) + +ID=$1 +IMAGE=${2:-$DEFIMAGE} + +USER=$(id -un) +echo "Using instance ID #$ID (user $(id -un))" + +NAME=agl-worker-$(hostname|cut -f1 -d'.')-$ID-$USER + +MIRRORDIR=$HOME/ssd/localmirror_$ID +XDTDIR=$HOME/ssd/xdt_$ID +SHAREDDIR=$HOME/devel/docker/share + +SSH_PORT=$((2222 + ID)) +WWW_PORT=$((8000 + ID)) +BOOT_PORT=$((69 + ID)) +NBD_PORT=$((10809 + ID)) + +mkdir -p $MIRRORDIR $XDTDIR $SHAREDDIR +docker run \ + --publish=${SSH_PORT}:22 \ + --publish=${WWW_PORT}:8000 \ + --publish=${BOOT_PORT}:69/udp \ + --publish=${NBD_PORT}:10809 \ + --detach=true \ + --hostname=$NAME --name=$NAME \ + --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro \ + -v $MIRRORDIR:/home/devel/mirror \ + -v $SHAREDDIR:/home/devel/share \ + -v $XDTDIR:/xdt \ + -it docker.automotivelinux.org/agl/worker:2.1 + +echo "Copying your identity to container $NAME:" +sleep 5 +ssh-copy-id -p $SSH_PORT devel@$(hostname) + +echo "You can now login using:" +echo " ssh -p $SSH_PORT devel@$(hostname)" + diff --git a/setup.d/10_base b/setup.d/10_base index 07633ea..59dab07 100644 --- a/setup.d/10_base +++ b/setup.d/10_base @@ -4,6 +4,9 @@ echo "deb http://http.debian.net/debian jessie-backports main contrib" >>/etc/apt/sources.list echo "deb http://http.debian.net/debian testing main contrib" >>/etc/apt/sources.list +# setup network retries for apt +echo "Acquire::Retries 5;" >/etc/apt/apt.conf.d/99NetRetries + # upgrade distro apt-get update -y apt-get dist-upgrade -y |