Add container build files

This commit is contained in:
Simon Marsh 2019-09-13 22:29:04 +01:00
parent 46e83bcb68
commit 56fd6dc687
Signed by: burble
GPG Key ID: 7B9FE8780CFB6593
4 changed files with 112 additions and 2 deletions

26
contrib/build.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
##########################################################################
# A small script to build a static lgregmapper image
# using the golang container image
#
# the binary will be built in to the current directory
##########################################################################
RUNTIME=$(which podman || which docker)
echo "Using container runtime: ${RUNTIME}"
# find the source directory
SCRIPTPATH="$(cd "$(dirname "$0")" ; pwd -P)"
SOURCEPATH="$(cd "${SCRIPTPATH}/../"; pwd -P)"
echo "Source is in: ${SOURCEPATH}"
# do the thing
${RUNTIME} run --rm \
-e CGO_ENABLED=0 \
-v "${SOURCEPATH}:/go/src/lgregmapper" \
-v "${PWD}:/go/bin" \
-w "/go/src/lgregmapper" \
docker.io/golang:1.12 \
go get
##########################################################################
# end of code

68
contrib/buildah.sh Executable file
View File

@ -0,0 +1,68 @@
#!/bin/bash
##########################################################################
IMAGE='lgregmapper'
echo "Building ${IMAGE} container"
# find the source directory
SCRIPTPATH="$(cd "$(dirname "$0")" ; pwd -P)"
SOURCEPATH="$(cd "${SCRIPTPATH}/../"; pwd -P)"
echo "Source is in: ${SOURCEPATH}"
##########################################################################
DEPS=(
'ca-certificates'
)
B=$(which buildah)
# initialise container
c=$(buildah from --name ${IMAGE}-working docker.io/debian:buster)
##########################################################################
# install dependencies and initialise directories
$B run $c -- bash <<EOF
apt-get -y update
apt-get -y install --no-install-recommends ${DEPS[@]}
rm -r /var/lib/apt/lists
EOF
# mount the container
m=$($B mount $c)
cpath="${m}/usr/local/share/ca-certificates/burble.dn42"
mkdir "$m/app" "${cpath}"
curl -o "${cpath}/ca-burble-dn42.crt" \
'https://dn42.burble.com/home/certificate-authority/certs/ca-burble-dn42.pem'
$B run $c -- /usr/sbin/update-ca-certificates
cp ${SOURCEPATH}/contrib/entrypoint.sh ${m}/app/
chmod +x ${m}/app/entrypoint.sh
# build the binary directly in to the container
pushd "$m/app"
"$SOURCEPATH/contrib/build.sh"
popd
# unmount the container
$B unmount $c
# configure
buildah config \
--author="Simon Marsh" \
--workingdir='/app' \
--cmd='/app/entrypoint.sh' \
$c
##########################################################################
# finally create the image
echo "Committing image ..."
i=$($B commit --squash $c ${IMAGE})
# clean up
$B rm $c
##########################################################################
# end of file

16
contrib/entrypoint.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
##########################################################################
LGREGMAPPER_API=${LGREGMAPPER_WEBAPP:-https://explorer.burble.dn42/}
LGREGMAPPER_BIND=${LGREGMAPPER_BIND:-localhost:11211}
LGREGMAPPER_INTERVAL=${LGREGMAPPER_INTERVAL:-10m}
LGREGMAPPER_LOGLVL=${LGREGMAPPER_LOGLVL:-info}
exec /app/lgregmapper \
-a "$LGREGMAPPER_API" \
-b "$LGREGMAPPER_BIND" \
-i "$LGREGMAPPER_INTERVAL" \
-l "$LGREGMAPPER_LOGLVL" \
##########################################################################
# end of file

View File

@ -53,10 +53,10 @@ func main() {
// declare cmd line options
var (
logLevel = flag.StringP("LogLevel", "l", "Info", "Log level")
refreshInterval = flag.StringP("Refresh", "i", "60m", "Refresh interval")
refreshInterval = flag.StringP("Refresh", "i", "10m", "Refresh interval")
bindAddress = flag.StringP("BindAddress", "b", "localhost:11211",
"Server bind address")
apiAddress = flag.StringP("APIAddress", "a", "http://collector.dn42:8042",
apiAddress = flag.StringP("APIAddress", "a", "https://explorer.burble.dn42/",
"DN42 API server address")
)
flag.Parse()