Skip to content

Commit

Permalink
Merge pull request #27 from Admiral-Piett/dockerize
Browse files Browse the repository at this point in the history
Dockerize for deployment
  • Loading branch information
Admiral-Piett authored Jul 26, 2022
2 parents 883e11e + cdf19a2 commit 8a88623
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 3 deletions.
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
6 changes: 6 additions & 0 deletions deployer.sh
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions runner.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 8a88623

Please sign in to comment.