forked from PhantomBot/PhantomBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
148 lines (121 loc) · 5.23 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#
# Copyright (C) 2016-2024 phantombot.github.io/PhantomBot
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Build container
FROM --platform=${BUILDPLATFORM} eclipse-temurin:17-jdk AS builder
ARG PROJECT_NAME=PhantomBot
ARG PROJECT_VERSION
ARG BASEDIR=/opt/${PROJECT_NAME}
ARG BUILDDIR=${BASEDIR}_build
ARG LIBDIR=${BASEDIR}_lib
ARG DATADIR=${BASEDIR}_data
ARG ANT_ARGS=
ENV DEBIAN_FRONTEND=noninteractive
RUN set -eux; \
mkdir -p "${BUILDDIR}" "${DATADIR}"; \
apt-get update; \
cd root; apt-get download ant; \
dpkg --ignore-depends=default-jre-headless --install ant_*.deb; \
apt-get clean; \
rm -rf \
/var/lib/apt/lists/* \
/tmp/* \
/var/tmp/* \
/root/*.deb
COPY build.xml ivysettings.xml ivy.xml "${BUILDDIR}/"
RUN set -eux; \
cd "${BUILDDIR}"; \
ant -noinput -buildfile build.xml -Disdocker=true ${ANT_ARGS} ivy-retrieve
COPY . "${BUILDDIR}"
RUN set -eux; \
cd "${BUILDDIR}"; \
ant -noinput -buildfile build.xml -Disdocker=true ${ANT_ARGS} jar; \
cd "${BUILDDIR}/dist/${PROJECT_NAME}-${PROJECT_VERSION}"; \
mv "./lib" "${LIBDIR}"; ln -s "${LIBDIR}" "./lib"
RUN set -eux; \
cd "${BUILDDIR}/dist/${PROJECT_NAME}-${PROJECT_VERSION}/"; \
ls | grep java-runtime | xargs --no-run-if-empty rm -rf; \
ls | grep launch | grep -v launch-docker.sh | xargs --no-run-if-empty rm -rf; \
ls | grep restartbot | grep -v restartbot-docker.sh | xargs --no-run-if-empty rm -rf; \
cd "${BUILDDIR}/dist/${PROJECT_NAME}-${PROJECT_VERSION}/config/healthcheck/failurehooks"; \
ls | grep restart | grep -v restart-docker-internal.py | xargs --no-run-if-empty rm -rf
RUN set -eux; \
cd "${BUILDDIR}/dist/${PROJECT_NAME}-${PROJECT_VERSION}/"; \
mkdir "${DATADIR}/scripts"; \
mkdir "${DATADIR}/scripts/custom"; \
mkdir "${DATADIR}/scripts/discord"; \
mkdir "${DATADIR}/scripts/lang"; \
mkdir "${DATADIR}/logs"; \
mv "./addons" "${DATADIR}/"; \
mv "./config" "${DATADIR}/"; \
mv "./scripts/custom" "${DATADIR}/scripts/custom/"; \
mv "./scripts/discord/custom" "${DATADIR}/scripts/discord/"; \
mv "./scripts/lang/custom" "${DATADIR}/scripts/lang/"; \
rm "./lib"
# Application container
FROM eclipse-temurin:17-jre AS publish
ARG PROJECT_NAME=PhantomBot
ARG PROJECT_VERSION
ARG BASEDIR=/opt/${PROJECT_NAME}
ARG BUILDDIR=${BASEDIR}_build
ARG LIBDIR=${BASEDIR}_lib
ARG DATADIR=${BASEDIR}_data
USER root
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends util-linux python3 python3-pip python3-venv; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false
RUN set -eux; \
groupadd -r phantombot -g 900; \
useradd -u 901 -r -g phantombot -s /sbin/nologin -c "PhantomBot Daemon User" phantombot
RUN set -eux; \
mkdir -p "${BASEDIR}" "${DATADIR}"; \
chown phantombot:phantombot "${BASEDIR}"; \
chown phantombot:phantombot "${DATADIR}"
ENV PATH="${BASEDIR}:$PATH"
COPY --from=builder --chown=phantombot:phantombot "${LIBDIR}" "${BASEDIR}/lib"
COPY --from=builder "${DATADIR}/config/healthcheck/requirements.txt" "${DATADIR}/config/healthcheck/"
RUN set -eux; \
python3 -m venv /opt/python3/venv; \
/opt/python3/venv/bin/pip install --no-cache-dir -r "${DATADIR}/config/healthcheck/requirements.txt"
COPY --from=builder --chown=phantombot:phantombot "${DATADIR}/." "${DATADIR}/"
COPY --from=builder --chown=phantombot:phantombot "${BUILDDIR}/dist/${PROJECT_NAME}-${PROJECT_VERSION}/." "${BASEDIR}/"
RUN set -eux; \
cd "${BASEDIR}"; \
mkdir "${DATADIR}/dbbackup"; \
mkdir "${DATADIR}/gameslist"; \
ln -s "${DATADIR}/addons"; \
ln -s "${DATADIR}/config"; \
ln -s "${DATADIR}/dbbackup"; \
ln -s "${DATADIR}/logs"; \
ln -s "${DATADIR}/scripts/custom" "${BASEDIR}/scripts/custom"; \
ln -s "${DATADIR}/scripts/discord" "${BASEDIR}/scripts/discord/custom"; \
ln -s "${DATADIR}/scripts/lang" "${BASEDIR}/scripts/lang/custom"; \
touch "${DATADIR}/gameslist/gamesList.txt"; \
ln -s "${DATADIR}/gameslist/gamesList.txt" "${BASEDIR}/web/panel/js/utils/gamesList.txt"; \
touch "${DATADIR}/java.opt.custom"; \
ln -s "${DATADIR}/java.opt.custom" "${BASEDIR}/java.opt.custom"; \
chmod u+x "${BASEDIR}/restartbot-docker.sh"; \
chmod u+x "${BASEDIR}/launch-docker.sh"; \
chmod u+x "${BASEDIR}/docker-entrypoint.sh"
VOLUME "${DATADIR}"
WORKDIR "${BASEDIR}"
HEALTHCHECK --interval=5m --timeout=1m --start-period=2m CMD /opt/python3/venv/bin/python /opt/PhantomBot/config/healthcheck/healthcheck.py --show-success --config-dir /opt/PhantomBot_data/config/
ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 25000
CMD ["launch-docker.sh"]