diff --git a/Dockerfile b/Dockerfile index 9f86b9d..8b11cb4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,21 @@ -FROM docker.io/golang:alpine as builder +FROM golang:1-alpine3.16 AS builder -RUN apk add --no-cache olm-dev gcc musl-dev libstdc++-dev +RUN apk add --no-cache git ca-certificates build-base su-exec olm-dev -COPY . /app -WORKDIR /app +COPY . /build +WORKDIR /build +RUN go build -o /usr/bin/standupbot -RUN go build +FROM alpine:3.16 -FROM docker.io/alpine +ENV UID=1337 \ + GID=1337 -RUN apk add --no-cache olm libstdc++ tzdata +RUN apk add --no-cache su-exec ca-certificates olm bash -COPY --from=builder /app/standupbot /usr/local/bin/standupbot +COPY --from=builder /usr/bin/standupbot /usr/bin/standupbot +COPY --from=builder /build/config.sample.json /opt/standupbot/config.sample.json +COPY --from=builder /build/docker-run.sh /docker-run.sh +VOLUME /data + +CMD ["/docker-run.sh"] diff --git a/docker-run.sh b/docker-run.sh new file mode 100755 index 0000000..67a8d6b --- /dev/null +++ b/docker-run.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +if [[ -z "$GID" ]]; then + GID="$UID" +fi + +# Define functions. +function fixperms { + chown -R $UID:$GID /data /opt/standupbot +} + +if [[ ! -f /data/config.json ]]; then + cp /opt/standupbot/config.sample.json /data/config.json + echo "Didn't find a config file." + echo "Copied default config file to /data/config.json" + echo "Modify that config file to your liking." + exit +fi + +cd /data +fixperms +exec su-exec $UID:$GID /usr/bin/standupbot