From c87abb506d9770f59fbc42a786983e6f030b90aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phillip=20K=C3=BChne?= Date: Tue, 3 Oct 2023 23:47:57 +0000 Subject: [PATCH] Add docker build and push script --- Dockerfile | 3 +++ build_container.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 build_container.sh diff --git a/Dockerfile b/Dockerfile index ef63b2d..d3e4014 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,4 +17,7 @@ RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt RUN pip install --no-cache-dir -U meinheld +ARG SOURCE_VERSION +ENV SOURCE_VERSION ${SOURCE_VERSION:-unknown} + COPY ./backend /app \ No newline at end of file diff --git a/build_container.sh b/build_container.sh new file mode 100755 index 0000000..9f92e74 --- /dev/null +++ b/build_container.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Get username from command line +if [ $# -eq 0 ]; then + echo "No username supplied. Please supply a github username as the first argument." + exit 1 +fi + +# Store username in variable +USERNAME=$1 + +# Check for uncommitted changes +if ! git diff-index --quiet HEAD --; then + echo "You have uncommitted changes. Please commit or stash them and try again." + exit 1 +fi + +# Check if the user is logged into ghcr.io +if ! docker info | grep -q "Username: $USERNAME"; then + echo "You are not logged into ghcr.io. Please run 'docker login ghcr.io' and try again." + exit 1 +fi + +# Get the appropriate version of the container using git +VERSION=$(git rev-parse --abbrev-ref HEAD)-$(git describe) + +# Build the container. Add the version as a tag and as ENV variable SOURCE_VERSION +docker build -t ghcr.io/$USERNAME/:$VERSION --build-arg SOURCE_VERSION=$VERSION . + +# Ask the user if they want to push the container. Confirm Version. +read -p "Push container to ghcr.io/$USERNAME/karaoqueue:$VERSION? [y/n] " -n 1 -r +echo +if [[ $REPLY =~ ^[Yy]$ ]] +then + docker push ghcr.io/$USERNAME/karaoqueue:$VERSION +fi + +# Ask the user if they want to push the container as latest +read -p "Push container to ghcr.io/$USERNAME/karaoqueue:latest? [y/n] " -n 1 -r +echo +if [[ $REPLY =~ ^[Yy]$ ]] +then + docker tag ghcr.io/$USERNAME/karaoqueue:$VERSION ghcr.io/$USERNAME/karaoqueue:latest + docker push ghcr.io/$USERNAME/karaoqueue:latest +fi