Improve Help for build.sh

This commit is contained in:
Christian Mäder 2022-10-08 17:08:39 +02:00
parent c21a29b383
commit d96e8f1dfd
1 changed files with 123 additions and 90 deletions

213
build.sh
View File

@ -6,96 +6,129 @@ echo "▶️ $0 $*"
set -e set -e
if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then
echo "Usage: ${0} <branch> [--push]" _BOLD=$(tput bold)
echo " branch The branch or tag to build. Required." _GREEN=$(tput setaf 2)
echo " --push Pushes the built Docker image to the registry." _CYAN=$(tput setaf 6)
echo "" _CLEAR=$(tput sgr0)
echo "You can use the following ENV variables to customize the build:"
echo " SRC_ORG Which fork of netbox to use (i.e. github.com/\${SRC_ORG}/\${SRC_REPO})." cat <<END_OF_HELP
echo " Default: netbox-community" ${_BOLD}Usage:${_CLEAR} ${0} <branch> [--push]
echo " SRC_REPO The name of the repository to use (i.e. github.com/\${SRC_ORG}/\${SRC_REPO})."
echo " Default: netbox" branch The branch or tag to build. Required.
echo " URL Where to fetch the code from." --push Pushes the built container image to the registry.
echo " Must be a git repository. Can be private."
echo " Default: https://github.com/\${SRC_ORG}/\${SRC_REPO}.git" ${_BOLD}You can use the following ENV variables to customize the build:${_CLEAR}
echo " NETBOX_PATH The path where netbox will be checkout out."
echo " Must not be outside of the netbox-docker repository (because of Docker)!" SRC_ORG Which fork of netbox to use (i.e. github.com/\${SRC_ORG}/\${SRC_REPO}).
echo " Default: .netbox" ${_GREEN}Default:${_CLEAR} netbox-community
echo " SKIP_GIT If defined, git is not invoked and \${NETBOX_PATH} will not be altered."
echo " This may be useful, if you are manually managing the NETBOX_PATH." SRC_REPO The name of the repository to use (i.e. github.com/\${SRC_ORG}/\${SRC_REPO}).
echo " Default: undefined" ${_GREEN}Default:${_CLEAR} netbox
echo " TAG The version part of the docker tag."
echo " Default:" URL Where to fetch the code from.
echo " When <branch>=master: latest" Must be a git repository. Can be private.
echo " When <branch>=develop: snapshot" ${_GREEN}Default:${_CLEAR} https://github.com/\${SRC_ORG}/\${SRC_REPO}.git
echo " Else: same as <branch>"
echo " IMAGE_NAMES The names used for the image including the registry" NETBOX_PATH The path where netbox will be checkout out.
echo " Used for tagging the image." Must not be outside of the netbox-docker repository (because of Docker)!
echo " Default: docker.io/netboxcommunity/netbox" ${_GREEN}Default:${_CLEAR} .netbox
echo " Example: 'docker.io/netboxcommunity/netbox quay.io/netboxcommunity/netbox'"
echo " DOCKER_TAG The name of the tag which is applied to the image." SKIP_GIT If defined, git is not invoked and \${NETBOX_PATH} will not be altered.
echo " Useful for pushing into another registry than hub.docker.com." This may be useful, if you are manually managing the NETBOX_PATH.
echo " Default: \${DOCKER_REGISTRY}/\${DOCKER_ORG}/\${DOCKER_REPO}:\${TAG}" ${_GREEN}Default:${_CLEAR} undefined
echo " DOCKER_SHORT_TAG The name of the short tag which is applied to the"
echo " image. This is used to tag all patch releases to their" TAG The version part of the image tag.
echo " containing version e.g. v2.5.1 -> v2.5" ${_GREEN}Default:${_CLEAR}
echo " Default: \${DOCKER_REGISTRY}/\${DOCKER_ORG}/\${DOCKER_REPO}:<MAJOR>.<MINOR>" When <branch>=master: latest
echo " DOCKERFILE The name of Dockerfile to use." When <branch>=develop: snapshot
echo " Default: Dockerfile" Else: same as <branch>
echo " DOCKER_FROM The base image to use."
echo " Default: 'ubuntu:22.04'" IMAGE_NAMES The names used for the image including the registry
echo " BUILDX_PLATFORMS" Used for tagging the image.
echo " Specifies the platform(s) to build the image for." ${_GREEN}Default:${_CLEAR} docker.io/netboxcommunity/netbox
echo " Example: 'linux/amd64,linux/arm64'" ${_CYAN}Example:${_CLEAR} 'docker.io/netboxcommunity/netbox quay.io/netboxcommunity/netbox'
echo " Default: 'linux/amd64'"
echo " BUILDX_BUILDER_NAME" DOCKER_TAG The name of the tag which is applied to the image.
echo " If defined, the image build will be assigned to the given builder." Useful for pushing into another registry than hub.docker.com.
echo " If you specify this variable, make sure that the builder exists." ${_GREEN}Default:${_CLEAR} \${DOCKER_REGISTRY}/\${DOCKER_ORG}/\${DOCKER_REPO}:\${TAG}
echo " If this value is not defined, a new builx builder with the directory name of the"
echo " current directory (i.e. '$(basename "${PWD}")') is created." DOCKER_SHORT_TAG The name of the short tag which is applied to the
echo " Example: 'clever_lovelace'" image. This is used to tag all patch releases to their
echo " Default: undefined" containing version e.g. v2.5.1 -> v2.5
echo " BUILDX_REMOVE_BUILDER" ${_GREEN}Default:${_CLEAR} \${DOCKER_REGISTRY}/\${DOCKER_ORG}/\${DOCKER_REPO}:<MAJOR>.<MINOR>
echo " If defined (and only if BUILDX_BUILDER_NAME is undefined),"
echo " then the buildx builder created by this script will be removed after use." DOCKERFILE The name of Dockerfile to use.
echo " This is useful if you build NetBox Docker on an automated system that does" ${_GREEN}Default:${_CLEAR} Dockerfile
echo " not manage the builders for you."
echo " Example: 'on'" DOCKER_FROM The base image to use.
echo " Default: undefined" ${_GREEN}Default:${_CLEAR} 'ubuntu:22.04'
echo " HTTP_PROXY The proxy to use for http requests."
echo " Example: http://proxy.domain.tld:3128" BUILDX_PLATFORMS
echo " Default: undefined" Specifies the platform(s) to build the image for.
echo " NO_PROXY Comma-separated list of domain extensions proxy should not be used for." ${_CYAN}Example:${_CLEAR} 'linux/amd64,linux/arm64'
echo " Example: .domain1.tld,.domain2.tld" ${_GREEN}Default:${_CLEAR} 'linux/amd64'
echo " Default: undefined"
echo " DEBUG If defined, the script does not stop when certain checks are unsatisfied." BUILDX_BUILDER_NAME
echo " Default: undefined" If defined, the image build will be assigned to the given builder.
echo " DRY_RUN Prints all build statements instead of running them." If you specify this variable, make sure that the builder exists.
echo " Default: undefined" If this value is not defined, a new builx builder with the directory name of the
echo " GH_ACTION If defined, special 'echo' statements are enabled that set the" current directory (i.e. '$(basename "${PWD}")') is created."
echo " following environment variables in Github Actions:" ${_CYAN}Example:${_CLEAR} 'clever_lovelace'
echo " - FINAL_DOCKER_TAG: The final value of the DOCKER_TAG env variable" ${_GREEN}Default:${_CLEAR} undefined
echo " Default: undefined"
echo "" BUILDX_REMOVE_BUILDER
echo "Examples:" If defined (and only if BUILDX_BUILDER_NAME is undefined),
echo " ${0} master" then the buildx builder created by this script will be removed after use.
echo " This will fetch the latest 'master' branch, build a Docker Image and tag it" This is useful if you build NetBox Docker on an automated system that does
echo " 'netboxcommunity/netbox:latest'." not manage the builders for you.
echo " ${0} develop" ${_CYAN}Example:${_CLEAR} 'on'
echo " This will fetch the latest 'develop' branch, build a Docker Image and tag it" ${_GREEN}Default:${_CLEAR} undefined
echo " 'netboxcommunity/netbox:snapshot'."
echo " ${0} v2.6.6" HTTP_PROXY The proxy to use for http requests.
echo " This will fetch the 'v2.6.6' tag, build a Docker Image and tag it" ${_CYAN}Example:${_CLEAR} http://proxy.domain.tld:3128
echo " 'netboxcommunity/netbox:v2.6.6' and 'netboxcommunity/netbox:v2.6'." ${_GREEN}Default:${_CLEAR} undefined
echo " ${0} develop-2.7"
echo " This will fetch the 'develop-2.7' branch, build a Docker Image and tag it" NO_PROXY Comma-separated list of domain extensions proxy should not be used for.
echo " 'netboxcommunity/netbox:develop-2.7'." ${_CYAN}Example:${_CLEAR} .domain1.tld,.domain2.tld
echo " SRC_ORG=cimnine ${0} feature-x" ${_GREEN}Default:${_CLEAR} undefined
echo " This will fetch the 'feature-x' branch from https://github.com/cimnine/netbox.git,"
echo " build a Docker Image and tag it 'netboxcommunity/netbox:feature-x'." DEBUG If defined, the script does not stop when certain checks are unsatisfied.
echo " SRC_ORG=cimnine DOCKER_ORG=cimnine ${0} feature-x" ${_GREEN}Default:${_CLEAR} undefined
echo " This will fetch the 'feature-x' branch from https://github.com/cimnine/netbox.git,"
echo " build a Docker Image and tag it 'cimnine/netbox:feature-x'." DRY_RUN Prints all build statements instead of running them.
${_GREEN}Default:${_CLEAR} undefined
GH_ACTION If defined, special 'echo' statements are enabled that set the
following environment variables in Github Actions:
- FINAL_DOCKER_TAG: The final value of the DOCKER_TAG env variable
${_GREEN}Default:${_CLEAR} undefined
${_BOLD}Examples:${_CLEAR}
${0} master
This will fetch the latest 'master' branch, build a Docker Image and tag it
'netboxcommunity/netbox:latest'.
${0} develop
This will fetch the latest 'develop' branch, build a Docker Image and tag it
'netboxcommunity/netbox:snapshot'.
${0} v2.6.6
This will fetch the 'v2.6.6' tag, build a Docker Image and tag it
'netboxcommunity/netbox:v2.6.6' and 'netboxcommunity/netbox:v2.6'.
${0} develop-2.7
This will fetch the 'develop-2.7' branch, build a Docker Image and tag it
'netboxcommunity/netbox:develop-2.7'.
SRC_ORG=cimnine ${0} feature-x
This will fetch the 'feature-x' branch from https://github.com/cimnine/netbox.git,
build a Docker Image and tag it 'netboxcommunity/netbox:feature-x'.
SRC_ORG=cimnine DOCKER_ORG=cimnine ${0} feature-x
This will fetch the 'feature-x' branch from https://github.com/cimnine/netbox.git,
build a Docker Image and tag it 'cimnine/netbox:feature-x'.
END_OF_HELP
if [ "${1}x" == "x" ]; then if [ "${1}x" == "x" ]; then
exit 1 exit 1