Add container build scripts

This commit is contained in:
Simon Marsh 2019-08-31 23:36:17 +01:00
parent 28dc32f69c
commit de8c8ce1f8
No known key found for this signature in database
GPG Key ID: 7B9FE8780CFB6593
4 changed files with 134 additions and 1 deletions

View File

@ -21,14 +21,26 @@ A public instance of the API and explorer web app can be accessed via:
## Building
Requires [git](https://git-scm.com/) and [go](https://golang.org)
#### Using locally installed go
Requires [git](https://git-scm.com/) and [go](https://golang.org)
```
go get -insecure git.dn42.us/burble/dn42regsrv
```
#### Without installing go
Using container runtime to build with the golang container:
```
docker run -v ${PWD}:/go/bin golang go get -insecure git.dn42.us/burble/dn42regsrv
```
Or use the *contrib/build.sh* script after cloning the repo.
## Running
#### As a service
Use --help to view configurable options
```
${GOPATH}/bin/dn42regsrv --help
@ -47,6 +59,14 @@ ${GOPATH}/dn42regsrv
A sample service file is included for running the server under systemd
#### Within a container
A container build script (*contrib/buildah.sh*) is included in the
contrib directory. The script uses [buildah](https://buildah.io/).
See the *contrib/entrypoint.sh* script for environment variables that can
be set when running the container.
## Using
By default the server will be listening on port 8042.

26
contrib/build.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
##########################################################################
# A small script to build a static dn42regsrv 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/dn42regsrv" \
-v "${PWD}:/go/bin" \
-w "/go/src/dn42regsrv" \
docker.io/golang:1.12 \
go get
##########################################################################
# end of code

65
contrib/buildah.sh Executable file
View File

@ -0,0 +1,65 @@
#!/bin/bash
##########################################################################
echo "Building dn42regsrv container"
# find the source directory
SCRIPTPATH="$(cd "$(dirname "$0")" ; pwd -P)"
SOURCEPATH="$(cd "${SCRIPTPATH}/../"; pwd -P)"
echo "Source is in: ${SOURCEPATH}"
##########################################################################
DEPS='git'
B=$(which buildah)
# initialise container
c=$(buildah from --name dn42regsrv-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)
# create directories and copy the web app
mkdir "$m/app" "$m/data" "$m/registry" "$m/data/ssh"
# web app
cp -r "$SOURCEPATH/StaticRoot" "$m/data/webapp"
# add the entrypoint.sh script
cp "$SOURCEPATH/contrib/entrypoint.sh" "$m/app"
chmod +x "$m/app"
# 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='/data/registry' \
--cmd='/app/entrypoint.sh' \
$c
##########################################################################
# finally create the image
echo "Committing image ..."
i=$($B commit --squash $c dn42regsrv)
# clean up
$B rm $c
##########################################################################
# end of file

22
contrib/entrypoint.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
##########################################################################
DN42REGSRV_WEBAPP=${DN42REGSRV_WEBAPP:-/data/webapp}
DN42REGSRV_REGDIR=${DN42REGSRV_REGDIR:-/data/registry}
DN42REGSRV_BRANCH=${DN42REGSRV_BRANCH:-master}
DN42REGSRV_BIND=${DN42REGSRV_BIND:-[::]:8042}
DN42REGSRV_INTERVAL=${DN42REGSRV_INTERVAL:-10m}
DN42REGSRV_LOGLVL=${DN42REGSRV_LOGLVL:-info}
DN42REGSRV_AUTOPULL=${DN42REGSRV_AUTOPULL:-true}
exec /app/dn42regsrv \
-s "$DN42REGSRV_WEBAPP" \
-d "$DN42REGSRV_REGDIR" \
-p "$DN42REGSRV_BRANCH" \
-b "$DN42REGSRV_BIND" \
-i "$DN42REGSRV_INTERVAL" \
-l "$DN42REGSRV_LOGLVL" \
-a "$DN42REGSRV_AUTOPULL"
##########################################################################
# end of file