Skip to content

Commit

Permalink
Update Dockerfile (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
klauspost committed Nov 7, 2019
1 parent 1ee1366 commit c2d221a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
12 changes: 5 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.12-alpine
FROM golang:1.13-alpine

LABEL maintainer="vivino.com"

Expand All @@ -7,15 +7,13 @@ ENV CGO_ENABLED 0
ENV GO111MODULE on
ENV BASEPACKAGE github.com/Vivino/rankdb
ENV PACKAGEPATH /go/src/${BASEPACKAGE}/
ENV GOPROXY https://proxy.golang.org

WORKDIR ${PACKAGEPATH}

# TODO: Remove when github.com/Vivino/rankdb is available.
COPY . ${PACKAGEPATH}

RUN \
apk add --no-cache git && \
go get ${BASEPACKAGE} || true && \
go get ${BASEPACKAGE} && \
go build -v -o=/go/bin/rankdb ${BASEPACKAGE}/cmd/rankdb && \
go build -v -o=/go/bin/rankdb-cli ${BASEPACKAGE}/api/tool/rankdb-cli

Expand All @@ -25,8 +23,8 @@ EXPOSE 8080

COPY --from=0 /go/bin/rankdb /usr/bin/rankdb
COPY --from=0 /go/bin/rankdb-cli /usr/bin/rankdb-cli
COPY api/conf/conf.stub.toml /conf/conf.toml
COPY deploy/docker-entrypoint.sh /usr/bin/
COPY conf/conf.stub.toml /conf/conf.toml
COPY cmd/docker-entrypoint.sh /usr/bin/

VOLUME ["/data"]
VOLUME ["/conf"]
Expand Down
43 changes: 43 additions & 0 deletions cmd/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/sh

export RANKDB_USERNAME=${RANKDB_USERNAME:-"rankdb"}
export RANKDB_GROUPNAME=${RANKDB_GROUPNAME:-"rankdb"}


docker_set_uid_gid() {
addgroup -S "$RANKDB_GROUPNAME" >/dev/null 2>&1 && \
adduser -S -G "$RANKDB_GROUPNAME" "$RANKDB_USERNAME" >/dev/null 2>&1
}

# su-exec to requested user, if user cannot be requested
# existing user is used automatically.
docker_switch_user() {
owner=$(check-user "$@")
if [ "${owner}" != "${RANKDB_USERNAME}:${RANKDB_GROUPNAME}" ]; then
## Print the message only if we are not using non-default username:groupname.
if [ "${RANKDB_USERNAME}:${RANKDB_GROUPNAME}" != "rankdb:rankdb" ]; then
echo "Requested username/group ${RANKDB_USERNAME}:${RANKDB_GROUPNAME} cannot be used"
echo "Found existing data with user ${owner}, we will continue and use ${owner} instead."
return
fi
fi
# check if su-exec is allowed, if yes proceed proceed.
if su-exec "${owner}" "/bin/ls" >/dev/null 2>&1; then
exec su-exec "${owner}" "$@"
fi
# fallback
exec "$@"
}

if [ "${1}" != "rankdb" ] && [ "${1}" != "rankdb-cli" ]; then
if [ -n "${1}" ]; then
set -- rankdb "$@"
fi
fi

## User Input UID and GID
docker_set_uid_gid

## Switch to user if applicable.
docker_switch_user "$@"

0 comments on commit c2d221a

Please sign in to comment.