djmil
2e11715194
This commit closes #5 ./docker/build.sh # build local sources ./docker/build.sh -r 0.1.0 -p # build known release
99 lines
3.0 KiB
Bash
Executable File
99 lines
3.0 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
usage="$(basename "$0") [--release=<version>] [--publish] [-h]
|
|
|
|
Compile Caddy server with gitea-pages plugin inside docker container. Buy
|
|
default local sources will be used for build.
|
|
|
|
You can also compile known release. The given release tag will be fetched from
|
|
the project git repo at https://gitea.djmil.dev/djmil/gitea-pages.
|
|
|
|
Optionally, the script can be used to publish resulting docker image to the
|
|
https://hub.docker.com/repository/docker/djmil/gitea-pages.
|
|
|
|
Params for the short options version shall be separated by space. For the long
|
|
options - equal sign shall be used. Example:
|
|
--release=0.1.0
|
|
-r 0.0.1
|
|
|
|
Where:
|
|
-l | --local
|
|
Build local sources. Default behaviour.
|
|
|
|
-r | --release <version>
|
|
A major.minor.patch tag of the known release to build.
|
|
|
|
-p | --publish
|
|
Publish resulting image to the docker hub. Typically shall be used
|
|
together with --release option.
|
|
|
|
-h | --help
|
|
Show this message and exit.
|
|
"
|
|
|
|
R="\033[0;31m" # RED
|
|
G="\033[0;32m" # GREEN
|
|
Y="\033[0;33m" # YELLOW
|
|
B="\033[1;34m" # BLUE
|
|
NC="\033[0;0m" # NO COLOR
|
|
|
|
###############################################################################
|
|
# Parse long and short options, source: https://stackoverflow.com/a/28466267
|
|
|
|
# Defaults
|
|
tag='local'
|
|
publish=false
|
|
|
|
die() { echo "$*" >&2; exit 2; } # complain to STDERR and exit with error
|
|
needs_arg() { if [ -z "$OPTARG" ]; then die "No arg for --$OPT option"; fi; }
|
|
|
|
while getopts r:lph-: OPT; do # allow -a, -b with arg, -c, and -- "with arg"
|
|
# support long options: https://stackoverflow.com/a/28466267/519360
|
|
if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG
|
|
OPT="${OPTARG%%=*}" # extract long option name
|
|
OPTARG="${OPTARG#"$OPT"}" # extract long option argument (may be empty)
|
|
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
|
|
fi
|
|
case "$OPT" in
|
|
l | local ) tag='local' ;;
|
|
r | release ) needs_arg; tag="$OPTARG" ;;
|
|
p | publish ) publish=true ;;
|
|
h | help ) echo "$usage" >&2; exit 0 ;;
|
|
\? ) exit 2 ;; # bad short option (error reported via getopts)
|
|
* ) die "Illegal option --$OPT" ;; # bad long option
|
|
esac
|
|
done
|
|
shift $((OPTIND-1)) # remove parsed options and args from $@ list
|
|
###############################################################################
|
|
|
|
|
|
if [ $tag = 'local' ]; then
|
|
echo -e "${Y} -->> Local dev-mode build: compile local sources${NC}";
|
|
|
|
docker build \
|
|
--file docker/local.dockerfile \
|
|
--tag djmil/gitea-pages:local \
|
|
.
|
|
|
|
exit 0
|
|
fi
|
|
|
|
|
|
echo -e "${Y} -->> Building release ${B}'$tag'${NC}";
|
|
|
|
docker build \
|
|
--file docker/release.dockerfile \
|
|
--build-arg RELEASE=$tag \
|
|
--tag djmil/gitea-pages:$tag \
|
|
.
|
|
|
|
|
|
if $publish; then
|
|
echo -e "${Y} -->> Publishing to the dockerhub";
|
|
|
|
docker login --username djmil #--password-stdin
|
|
|
|
docker push djmil/gitea-pages:$tag
|
|
fi
|