Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:1.17.2-bullseye as builder

# Create app directory
WORKDIR /app

# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY . /app

ENV GO111MODULE=on

WORKDIR /app
RUN go build

FROM debian:bullseye-slim

COPY --from=builder /app/go-space-chat /app/go-space-chat
COPY --from=builder /app/web_resource /app/web_resource
COPY --from=builder /app/config /app/config
41 changes: 41 additions & 0 deletions docker-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

BASEDIR=$(dirname "$0")
PROJECT_DIR="$(realpath "${BASEDIR}")"

IMAGE_NAME="go-space-chat"

GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
GIT_COMMIT=$(git rev-parse --short HEAD)
IMAGE_TAG="${GIT_BRANCH}-${GIT_COMMIT}"

function run_docker() {
echo "Running docker image: $IMAGE_NAME:$IMAGE_TAG"
docker run -it --rm \
-w /app \
-p 8081:80 \
-p 9000:9000 \
$IMAGE_NAME:$IMAGE_TAG \
/app/go-space-chat
}

# rm docker containers and images if exists
CONTAINERS=$(docker ps -a -q -f name=$IMAGE_NAME)
if [ -n "$CONTAINERS" ]; then
docker rm -f $CONTAINERS
fi

IMAGES=$(docker images -q $IMAGE_NAME)
if [ -n "$IMAGES" ]; then
run_docker

exit 0
fi

echo "Will build image: $IMAGE_NAME:$IMAGE_TAG"
# build image
docker build --progress=plain --no-cache -t $IMAGE_NAME:$IMAGE_TAG -f ./Dockerfile ./

echo "Image $IMAGE_NAME:$IMAGE_TAG is Built!"

run_docker