-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Admiral-Piett/dockerize
Dockerize for deployment
- Loading branch information
Showing
5 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |