Build release -vs- local sources
This commit closes #5 ./docker/build.sh # build local sources ./docker/build.sh -r 0.1.0 -p # build known release
This commit is contained in:
parent
7d96d7a52a
commit
0337ca1723
16
Dockerfile
16
Dockerfile
@ -1,16 +0,0 @@
|
||||
FROM caddy:2.8.4-builder-alpine AS builder
|
||||
|
||||
COPY pkg/gitea/* /module/gitea-pages/pkg/gitea/
|
||||
COPY gitea-pages.go go.mod go.sum /module/gitea-pages/
|
||||
|
||||
RUN xcaddy build \
|
||||
--with gitea.djmil.dev/djmil/gitea-pages \
|
||||
--replace gitea.djmil.dev/djmil/gitea-pages=/module/gitea-pages \
|
||||
--replace gitea.djmil.dev/djmil/gitea-pages/pkg/gitea=/module/gitea-pages/pkg/gitea
|
||||
|
||||
FROM caddy:2.8.4
|
||||
|
||||
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
|
||||
COPY Caddyfile /etc/caddy/Caddyfile
|
||||
|
||||
EXPOSE 3003/tcp
|
98
docker/build.sh
Executable file
98
docker/build.sh
Executable file
@ -0,0 +1,98 @@
|
||||
#!/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
|
24
docker/local.dockerfile
Normal file
24
docker/local.dockerfile
Normal file
@ -0,0 +1,24 @@
|
||||
FROM caddy:2.8.4-builder-alpine AS builder
|
||||
|
||||
#
|
||||
# mount root of the build context as /module/gitea-pages
|
||||
# inside the container and run `xcaddy build` command
|
||||
# also use cache to speed up subsequent builds
|
||||
#
|
||||
# $> go env GOCACHE <<-- Golang build cache
|
||||
# $> go env GOMODCACHE <<-- Goland module download cache
|
||||
#
|
||||
RUN --mount=type=bind,target=/module/gitea-pages \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
--mount=type=cache,target=/go/pkg/mod \
|
||||
xcaddy build \
|
||||
--with gitea.djmil.dev/djmil/gitea-pages \
|
||||
--replace gitea.djmil.dev/djmil/gitea-pages=/module/gitea-pages \
|
||||
--replace gitea.djmil.dev/djmil/gitea-pages/pkg/gitea=/module/gitea-pages/pkg/gitea
|
||||
|
||||
FROM caddy:2.8.4
|
||||
|
||||
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
|
||||
COPY Caddyfile /etc/caddy/Caddyfile
|
||||
|
||||
EXPOSE 3003/tcp
|
19
docker/release.dockerfile
Normal file
19
docker/release.dockerfile
Normal file
@ -0,0 +1,19 @@
|
||||
FROM caddy:2.8.4-builder-alpine AS builder
|
||||
|
||||
ARG RELEASE
|
||||
|
||||
#
|
||||
# $> go env GOCACHE <<-- Golang build cache
|
||||
# $> go env GOMODCACHE <<-- Goland module download cache
|
||||
#
|
||||
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||
--mount=type=cache,target=/go/pkg/mod \
|
||||
xcaddy build \
|
||||
--with gitea.djmil.dev/djmil/gitea-pages@$RELEASE
|
||||
|
||||
FROM caddy:2.8.4
|
||||
|
||||
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
|
||||
COPY Caddyfile /etc/caddy/Caddyfile
|
||||
|
||||
EXPOSE 3003/tcp
|
@ -1,39 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
usage="$(basename "$0") [-h] [-t RELEASE_VERSION ]
|
||||
|
||||
The script compiles Caddy server with GiteaPages plugin, and publishes the resulting image
|
||||
to the https://hub.docker.com/u/djmil
|
||||
|
||||
Where:
|
||||
-t RELEASE_VERSION
|
||||
A major.minor.patch tag for the image being publisdhed.
|
||||
"
|
||||
|
||||
tag=''
|
||||
|
||||
while getopts ht: flag
|
||||
do
|
||||
case "${flag}" in
|
||||
t) tag=${OPTARG};;
|
||||
h) echo "$usage"; exit 0;;
|
||||
*) echo "$usage" >&2; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ ! "$tag" ]; then
|
||||
echo 'Missing: -t RELEASE_VERSION' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Tag: $tag";
|
||||
|
||||
docker build --tag djmil/gitea-pages:$tag .
|
||||
|
||||
#git tag
|
||||
#git push tag
|
||||
|
||||
docker login --username djmil #--password-stdin
|
||||
|
||||
docker push djmil/gitea-pages:$tag
|
Loading…
Reference in New Issue
Block a user