diff options
author | Robin H. Johnson <robbat2@gentoo.org> | 2020-06-20 16:07:42 -0700 |
---|---|---|
committer | Robin H. Johnson <robbat2@gentoo.org> | 2020-06-20 16:07:42 -0700 |
commit | 479d3b8bcb7921affe2ad089213489a3af4956c6 (patch) | |
tree | 61e06713dc6d76a6bf7a2f8b543fa4dca8ae33f8 /bin | |
parent | bin/build: support TRACE=1 (diff) | |
download | www-479d3b8bcb7921affe2ad089213489a3af4956c6.tar.gz www-479d3b8bcb7921affe2ad089213489a3af4956c6.tar.bz2 www-479d3b8bcb7921affe2ad089213489a3af4956c6.zip |
bin: refactor docker stuff
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/build.sh | 23 | ||||
-rw-r--r-- | bin/docker-helper.inc | 40 | ||||
-rwxr-xr-x | bin/docker-setup.sh | 6 |
3 files changed, 48 insertions, 21 deletions
diff --git a/bin/build.sh b/bin/build.sh index f9cd530..6cf9a84 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -1,24 +1,5 @@ #!/bin/bash set -e -TRACE=${TRACE:=0} -[[ $TRACE -eq 1 ]] && set -x -IMAGE_NAME=docker.gentoo.org/sites/www -IMAGE_TAG=latest -IMAGE=${IMAGE_NAME}:${IMAGE_TAG} -IMAGE_SRC=docker/ -# Always refresh the image -# Docker caches it anyway -docker build \ - --quiet \ - -t "${IMAGE}" \ - "${IMAGE_SRC}" +source "$(dirname "$0")"/docker-helper.inc # Run the actual build process, with no networking permitted -docker run \ - --rm \ - --net=none \ - -e JEKYLL_UID=$(id -u) \ - -e JEKYLL_GID=$(id -g) \ - --volume="${PWD}:/srv/jekyll" \ - --volume="${PWD}/.bundle:/usr/local/bundle/" \ - "${IMAGE}" \ - jekyll build +docker_run_net_none jekyll build diff --git a/bin/docker-helper.inc b/bin/docker-helper.inc new file mode 100644 index 0000000..d084d2e --- /dev/null +++ b/bin/docker-helper.inc @@ -0,0 +1,40 @@ +#!/bin/bash +set -e +TRACE=${TRACE:=0} +[[ $TRACE -eq 1 ]] && set -x +IMAGE_NAME=docker.gentoo.org/sites/www +IMAGE_TAG=latest +IMAGE=${IMAGE_NAME}:${IMAGE_TAG} +IMAGE_SRC=docker/ + +docker_build() { + # Always refresh the image + # Docker caches it anyway + docker build \ + --quiet \ + -t "${IMAGE}" \ + "${IMAGE_SRC}" +} + +_docker_run_common() { + docker run \ + --rm \ + -e JEKYLL_UID="$(id -u)" \ + -e JEKYLL_GID="$(id -g)" \ + --volume="${PWD}:/srv/jekyll" \ + "$@" +} + +docker_run_net_host() { + _docker_run_common \ + --net=host \ + "${IMAGE}" \ + "$@" +} + +docker_run_net_none() { + _docker_run_common \ + --net=none \ + "${IMAGE}" \ + "$@" +} diff --git a/bin/docker-setup.sh b/bin/docker-setup.sh new file mode 100755 index 0000000..1e821a3 --- /dev/null +++ b/bin/docker-setup.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -e +source "$(dirname "$0")"/docker-helper.inc +docker_build +docker_run_net_none bundle install + |