diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ecf7875 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM golang:1.18.1 as base + +WORKDIR "/opt/svc" + +COPY app/ ./app +COPY main.go ./ +COPY go.mod ./ +COPY go.sum ./ + +RUN go build -o musizticle + +# TODO - Figure out how to run off a smaller image +#FROM scratch +#COPY --from=base /opt/svc/musizticle ./ + +ARG git_sha="local" +ENV GIT_SHA=${git_sha} + +EXPOSE 9000 + +CMD ./musizticle > /var/log/musizticle.log 2>&1 diff --git a/README.md b/README.md index 2ea4348..b757338 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,38 @@ Part 1 of a 2-piece music streaming app, designed to be self-hosted locally with media streamed through a related client app found here - https://github.com/Admiral-Piett/musizticle-gui. -## Installation Instructions -TBD - ## Environment Variables Set these in the environment before start up or be prepared to deal with the defaults. - MUSIZTICLE_PORT - MUSIZTICLE_SQLITE_DB - MUSIZTICLE_TOKEN_EXPIRATION - MUSIZTICLE_TOKEN_KEY_LENGTH + +#### Optional ENV Vars +- LOG_LEVEL - eg. `DEBUG`|`INFO`|`ERROR` + +## Installation Instructions +These steps will pull and run the latest version of the docker image for this app. The `runner.sh` script +(included in here) is an example of where to start and has some niceties built in, such as container death and +clean up on exit. Feel free to change at your own peril. + +#### Pre-Req +- Install docker on the machine you intend to be your "server" + - I used a RaspberryPi 4 with Centos on it to start, but you could do whatever. Even cloud if you wanted. Benefits +of containers. + +#### Deployment +- Copy `.env` to server and set all your environment variables (listed above) into it +- Copy `./runner.sh` to server + - Update to a different bash shell if you need to +- OPTIONAL: copy `./update.sh` +- Mount the directory of your music files to `./music` in the same directory as `runner.sh` +- Run `./update.sh` and then `./runner.sh` + +```shell +mkdir musizticle +cd musizticle +cp /path/to/runner.sh /destination/musizticle/runner.sh +cp /path/to/env /destination/musizticle/env +./runner.sh +``` diff --git a/deployer.sh b/deployer.sh new file mode 100755 index 0000000..d4f762a --- /dev/null +++ b/deployer.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# TODO - https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/ +# Build for both linux/amd64 (mac) and linux/arm/v7 (alpine) +docker buildx build --platform linux/amd64,linux/arm/v7 --push -t admiralpiett/musizticle . +#docker push admiralpiett/musizticle diff --git a/runner.sh b/runner.sh new file mode 100755 index 0000000..70c9421 --- /dev/null +++ b/runner.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +function on_death() { + echo "Stopping container" + docker stop musizticle +} +trap on_death INT + +IMAGE_NAME="admiralpiett/musizticle" +CONTAINER_NAME="musizticle" + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +DATA_VOLUME=${DIR}/data/:/opt/svc/data/ +MUSIC_VOLUME=${DIR}/music/:/opt/svc/music/ + +echo docker run -d --rm --name=$CONTAINER_NAME -p=9000:9000 --env-file=.env -v $DATA_VOLUME -v $MUSIC_VOLUME $IMAGE_NAME +docker run -d --rm --name=$CONTAINER_NAME -p=9000:9000 --env-file=.env -v $DATA_VOLUME -v $MUSIC_VOLUME $IMAGE_NAME + +docker exec -it $CONTAINER_NAME sh -c "tail -F /var/log/musizticle.log" + +echo "Stopping container" +docker stop $CONTAINER_NAME diff --git a/update.sh b/update.sh new file mode 100755 index 0000000..4feb92d --- /dev/null +++ b/update.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +CONTAINER="musizticle" +IMAGE_NAME="admiralpiett/${CONTAINER}" + +# Stop any affected running containers and remove the images before pulling latest +docker stop $CONTAINER +docker rmi $(docker images --format "{{ .Repository }}:{{ .Tag }}" $IMAGE_NAME) + +docker pull "${IMAGE_NAME}:latest"