From d9c1bd143db21aee19140ced514db32952367e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Fri, 9 Jun 2017 10:14:43 +0200 Subject: [PATCH] Add suggestions from PRs in digitalocean/netbox-drocker --- README.md | 2 +- build.sh | 41 +++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 7 +++++-- 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100755 build.sh diff --git a/README.md b/README.md index 6c846a7..5d54171 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ To get NetBox up and running: ``` # git clone -b master https://github.com/digitalocean/netbox-docker.git -# cd netbox +# cd netbox-docker # docker-compose up -d ``` diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..0bdb3ef --- /dev/null +++ b/build.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +set -e + +if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then + echo "Usage: ${0} [--push]" + echo " branch The branch or tag to build" + echo " --push Push built Docker files to docker hub" + echo "" + echo "You can use the following ENV variables to customize the build:" + echo " SRC_REPO The Github repository (i.e. github.com/SRC_REPO/netbox) of netbox." + echo " DOCKER_REPO The Docker repository (i.e. hub.docker.com/r/DOCKER_REPO/netbox) " + echo " Also used for tagging the image." + echo " BRANCH The branch to build." + echo " Also used for tagging the image." + echo " URL Where to fetch the package from." + echo " Must be a tar.gz file of the source code." + + if [ "${1}x" == "x" ]; then + exit 1 + else + exit 0 + fi +fi + +SRC_REPO="${SRC_REPO-digitalocean}" +DOCKER_REPO="${DOCKER_REPO-ninech}" +BRANCH="${1}" +URL="${URL-https://github.com/${SRC_REPO}/netbox/archive/$BRANCH.tar.gz}" + +TAG="${TAG-latest}" + +echo "🐳 Building the Docker images for the branch '${BRANCH}'" +docker build -f Dockerfile -t "${DOCKER_REPO}/netbox:${BRANCH}" -t "${DOCKER_REPO}/netbox:${TAG}" --build-arg "BRANCH=${BRANCH}" --build-arg "URL=${URL}" . +echo "✅ Finished building the Docker images '${DOCKER_REPO}/netbox:${BRANCH}'" + +if [ "${2}" == "--push" ] ; then + echo "⏫ Pushing 'netbox:${BRANCH}' and 'netbox:${BRANCH}-ldap'" + docker push "${DOCKER_REPO}/netbox:${BRANCH}" + echo "✅ Finished pushing the Docker images." +fi diff --git a/docker-compose.yml b/docker-compose.yml index 6bb8a7c..5c119b2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,11 @@ version: '3' services: netbox: - build: . - image: digitalocean/netbox:v2.0-beta3 + build: + context: . + args: + - BRANCH=${BRANCH-master} + image: digitalocean/netbox:${BRANCH-master} depends_on: - postgres env_file: netbox.env