2022-02-09 15:21:50 +00:00
|
|
|
ARG OTP_VERSION
|
|
|
|
|
|
|
|
# Build the release
|
|
|
|
FROM docker.io/library/erlang:${OTP_VERSION} AS builder
|
2022-04-14 10:08:17 +00:00
|
|
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
2022-02-09 15:21:50 +00:00
|
|
|
|
|
|
|
# Install thrift compiler
|
|
|
|
ARG THRIFT_VERSION
|
2022-04-15 11:07:54 +00:00
|
|
|
ARG TARGETARCH
|
|
|
|
RUN wget -q -O- "https://github.com/valitydev/thrift/releases/download/${THRIFT_VERSION}/thrift-${THRIFT_VERSION}-linux-${TARGETARCH}.tar.gz" \
|
2022-01-26 16:06:49 +00:00
|
|
|
| tar -xvz -C /usr/local/bin/
|
2022-02-09 15:21:50 +00:00
|
|
|
|
|
|
|
# Copy sources
|
2022-01-26 16:06:49 +00:00
|
|
|
RUN mkdir /build
|
|
|
|
COPY . /build/
|
2022-02-09 15:21:50 +00:00
|
|
|
|
|
|
|
# Build the release
|
2022-01-26 16:06:49 +00:00
|
|
|
WORKDIR /build
|
2022-04-14 10:08:17 +00:00
|
|
|
RUN rebar3 compile && \
|
|
|
|
rebar3 as prod release
|
2022-01-26 16:06:49 +00:00
|
|
|
|
2022-02-09 15:21:50 +00:00
|
|
|
# Make a runner image
|
|
|
|
FROM docker.io/library/erlang:${OTP_VERSION}-slim
|
|
|
|
|
|
|
|
ARG SERVICE_NAME
|
2023-07-06 09:33:37 +00:00
|
|
|
ARG USER_UID=1001
|
|
|
|
ARG USER_GID=$USER_UID
|
2022-02-09 15:21:50 +00:00
|
|
|
|
|
|
|
# Set env
|
2022-01-26 16:06:49 +00:00
|
|
|
ENV CHARSET=UTF-8
|
|
|
|
ENV LANG=C.UTF-8
|
2022-02-09 15:21:50 +00:00
|
|
|
|
|
|
|
# Set runtime
|
|
|
|
WORKDIR /opt/${SERVICE_NAME}
|
|
|
|
|
|
|
|
COPY --from=builder /build/_build/prod/rel/${SERVICE_NAME} /opt/${SERVICE_NAME}
|
|
|
|
|
2022-04-14 19:22:13 +00:00
|
|
|
RUN echo "#!/bin/sh" >> /entrypoint.sh && \
|
|
|
|
echo "exec /opt/${SERVICE_NAME}/bin/${SERVICE_NAME} foreground" >> /entrypoint.sh && \
|
|
|
|
chmod +x /entrypoint.sh
|
2023-07-06 09:33:37 +00:00
|
|
|
|
|
|
|
# Setup user
|
|
|
|
RUN groupadd --gid ${USER_GID} ${SERVICE_NAME} && \
|
2023-07-13 12:29:49 +00:00
|
|
|
mkdir /var/log/${SERVICE_NAME} && \
|
|
|
|
chown ${USER_UID}:${USER_GID} /var/log/${SERVICE_NAME} && \
|
2023-07-06 09:33:37 +00:00
|
|
|
useradd --uid ${USER_UID} --gid ${USER_GID} -M ${SERVICE_NAME}
|
|
|
|
USER ${SERVICE_NAME}
|
|
|
|
|
2022-01-26 16:06:49 +00:00
|
|
|
ENTRYPOINT []
|
2022-04-14 19:22:13 +00:00
|
|
|
CMD ["/entrypoint.sh"]
|
2022-02-09 15:21:50 +00:00
|
|
|
|
2022-01-26 16:06:49 +00:00
|
|
|
EXPOSE 8022
|