-
Notifications
You must be signed in to change notification settings - Fork 10
/
Dockerfile
68 lines (54 loc) · 1.64 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Defaults
ARG project_name="op-bot"
ARG project_title="OsProgramadores Telegram bot (op-bot)"
ARG project_author="[email protected]"
ARG project_source="https://github.com/osprogramadores/op-bot"
ARG project_user="op"
ARG project_uid=501
ARG home="/home/${project_user}"
ARG gopath="${home}/go"
ARG src_dir="${home}/${project_name}"
# Primary build stage.
FROM alpine:3.20 as builder
# Pull from defaults.
ARG project_name
ARG project_user
ARG project_uid
ARG home
ARG gopath
ARG src_dir
# Fully static (as long we we don't need to link to C)
ENV CGO_ENABLED 0
# Directories & PATH
ENV HOME="${home}"
ENV GOPATH="${gopath}"
workdir ${src_dir}
COPY . .
RUN apk add --no-cache ca-certificates git git-crypt go make && \
mkdir -p "${gopath}" && \
mkdir -p "${src_dir}" && \
cd "${src_dir}" && \
go mod download && \
make
# Build the second stage (small) image
FROM alpine:3.20
LABEL org.opencontainers.image.title="${project_title}"
LABEL org.opencontainers.image.authors="${project_author}"
LABEL org.opencontainers.image.source="${project_source}"
# Pull ARGs from previous stage.
ARG project_uid
ARG src_dir
# These variables are directly used by the bot.
ENV XDG_CONFIG_HOME "/config"
ENV XDG_DATA_HOME "/data"
ENV TRANSLATIONS_DIR "/app/translations"
ENV CONFIG_DIR "${XDG_CONFIG_HOME}/op-bot"
RUN adduser --uid "${project_uid}" --home /tmp --no-create-home --disabled-password op
WORKDIR /app
COPY --from=builder ${src_dir}/op-bot .
COPY --from=builder ${src_dir}/translations ${TRANSLATIONS_DIR}
COPY --from=builder ${src_dir}/site-configs ${CONFIG_DIR}
# Geo requests API port.
EXPOSE 54321
USER ${project_uid}
ENTRYPOINT [ "./op-bot" ]