You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.5 KiB
42 lines
1.5 KiB
FROM golang:1.18.5
|
|
|
|
# Defining a non privileged user to run the app
|
|
# which has the benefit that one can define the UID/GID of this new user
|
|
# so volume mapping of a local directory to the container with the same
|
|
# ids works with no ownership/permission issues
|
|
ENV PROJECT_NAME=catchy-cat
|
|
ENV PROJECT_USER=${PROJECT_NAME}
|
|
ENV PROJECT_USER_UID=1000
|
|
ENV PROJECT_USER_GID=1000
|
|
ENV PROJECT_USER_HOME=/home/${PROJECT_USER}
|
|
ENV PROJECT_USER_APP_HOME=/go/src/github.com/rodley82/${PROJECT_NAME}
|
|
|
|
RUN groupadd -r --gid ${PROJECT_USER_GID} ${PROJECT_USER}
|
|
RUN useradd --system --no-log-init --uid ${PROJECT_USER_UID} --gid ${PROJECT_USER_GID} --home-dir ${PROJECT_USER_HOME} --create-home --shell /bin/bash ${PROJECT_USER}
|
|
|
|
RUN mkdir -p ${PROJECT_USER_APP_HOME} && chown -R ${PROJECT_USER}:${PROJECT_USER} ${PROJECT_USER_APP_HOME}
|
|
|
|
# TODO Just for dev
|
|
# RUN apt update && apt install -y tmux
|
|
|
|
USER ${PROJECT_USER}
|
|
|
|
ENV GO111MODULE on
|
|
|
|
# TODO Just for dev
|
|
# Only for development so we can later use reflex -r '\.go$' make all
|
|
# RUN go install github.com/cespare/reflex@latest && \
|
|
# go install github.com/go-delve/delve/cmd/dlv@latest && \
|
|
|
|
WORKDIR ${PROJECT_USER_APP_HOME}
|
|
COPY --chown=${PROJECT_USER}:${PROJECT_USER} go.mod ./
|
|
COPY --chown=${PROJECT_USER}:${PROJECT_USER} go.sum ./
|
|
|
|
RUN go mod download
|
|
|
|
COPY --chown=${PROJECT_USER}:${PROJECT_USER} *.go ./
|
|
|
|
RUN go build -o ${PROJECT_USER_APP_HOME}/${PROJECT_NAME}
|
|
|
|
# Now tell Docker what command to run when the container starts
|
|
CMD ["sh", "-c", "${PROJECT_USER_APP_HOME}/${PROJECT_NAME}"]
|
|
|