Skip to content

Commit 4390b59

Browse files
committed
Add dockerfile
1 parent 581649c commit 4390b59

File tree

5 files changed

+273
-1
lines changed

5 files changed

+273
-1
lines changed

docker/Dockerfile

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
####################################################################################################
2+
## Builder image
3+
####################################################################################################
4+
FROM python:3.11-slim-bookworm AS builder
5+
6+
ENV DEBIAN_FRONTEND=noninteractive
7+
8+
RUN apt-get update \
9+
&& apt-get install -y --no-install-recommends \
10+
curl \
11+
git
12+
13+
ENV PYTHONDONTWRITEBYTECODE=1
14+
ENV PYTHONUNBUFFERED=1
15+
RUN curl -sSL https://install.python-poetry.org | python -
16+
ENV PATH="${PATH}:/root/.local/bin"
17+
18+
WORKDIR /rodhaj
19+
COPY /pyproject.toml /rodhaj/
20+
COPY /poetry.lock /rodhaj/
21+
22+
RUN poetry export --output requirements.txt --without-hashes --only main
23+
24+
####################################################################################################
25+
## Final image
26+
####################################################################################################
27+
FROM python:3.11-slim-bookworm
28+
29+
RUN apt update \
30+
&& apt install -y --no-install-recommends \
31+
tini \
32+
bash \
33+
netcat-traditional \
34+
libopus-dev \
35+
libffi-dev \
36+
libsodium-dev \
37+
git
38+
39+
WORKDIR /rodhaj
40+
COPY /bot /rodhaj/bot/
41+
COPY /bot/cogs /rodhaj/bot/cogs/
42+
COPY /bot/migrations /rodhaj/bot/migrations/
43+
COPY /docker/start.sh /rodhaj/start.sh
44+
COPY /docker/wait-for /rodhaj/wait-for
45+
46+
COPY --from=builder /rodhaj/requirements.txt /rodhaj/requirements.txt
47+
48+
RUN adduser --disabled-password --gecos "" rodhaj \
49+
&& chown -R rodhaj:rodhaj /rodhaj \
50+
&& chmod +x /rodhaj/start.sh \
51+
&& chmod +x /rodhaj/wait-for
52+
53+
USER rodhaj
54+
55+
ENV PATH="${PATH}:/home/rodhaj/.local/bin"
56+
57+
RUN pip install --user -r requirements.txt
58+
59+
ENTRYPOINT ["/usr/bin/tini", "--"]
60+
61+
CMD ["/rodhaj/start.sh"]
62+
63+
STOPSIGNAL SIGTERM
64+
65+
LABEL org.opencontainers.image.title="Rodhaj"
66+
LABEL org.opencontainers.image.description="A discord modmail bot"
67+
LABEL org.opencontainers.image.licenses="Apache-2.0"
68+
LABEL org.opencontainers.image.source="https://github.com/transprogrammer/rodhaj"

docker/start.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
RODHAJ_FIRST_START_CHECK="RODHAJ_FIRST_START"
4+
5+
if [ ! -f $RODHAJ_FIRST_START_CHECK ]; then
6+
touch $RODHAJ_FIRST_START_CHECK
7+
echo "DO NOT EDIT THIS FILE! THIS IS USED WHEN YOU FIRST RUN RODHAJ USING DOCKER!" >> $RODHAJ_FIRST_START_CHECK
8+
python3 /rodhaj/bot/migrations.py init
9+
fi
10+
11+
exec python3 /rodhaj/bot/launcher.py

docker/wait-for

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#!/bin/sh
2+
3+
# The MIT License (MIT)
4+
#
5+
# Copyright (c) 2017 Eficode Oy
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
25+
VERSION="2.2.3"
26+
27+
set -- "$@" -- "$TIMEOUT" "$QUIET" "$PROTOCOL" "$HOST" "$PORT" "$result"
28+
TIMEOUT=15
29+
QUIET=0
30+
# The protocol to make the request with, either "tcp" or "http"
31+
PROTOCOL="tcp"
32+
33+
echoerr() {
34+
if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
35+
}
36+
37+
usage() {
38+
exitcode="$1"
39+
cat << USAGE >&2
40+
Usage:
41+
$0 host:port|url [-t timeout] [-- command args]
42+
-q | --quiet Do not output any status messages
43+
-t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
44+
-v | --version Show the version of this tool
45+
-- COMMAND ARGS Execute command with args after the test finishes
46+
USAGE
47+
exit "$exitcode"
48+
}
49+
50+
wait_for() {
51+
case "$PROTOCOL" in
52+
tcp)
53+
if ! command -v nc >/dev/null; then
54+
echoerr 'nc command is missing!'
55+
exit 1
56+
fi
57+
;;
58+
http)
59+
if ! command -v wget >/dev/null; then
60+
echoerr 'wget command is missing!'
61+
exit 1
62+
fi
63+
;;
64+
esac
65+
66+
TIMEOUT_END=$(($(date +%s) + TIMEOUT))
67+
68+
while :; do
69+
case "$PROTOCOL" in
70+
tcp)
71+
nc -w 1 -z "$HOST" "$PORT" > /dev/null 2>&1
72+
;;
73+
http)
74+
wget --timeout=1 -q "$HOST" -O /dev/null > /dev/null 2>&1
75+
;;
76+
*)
77+
echoerr "Unknown protocol '$PROTOCOL'"
78+
exit 1
79+
;;
80+
esac
81+
82+
result=$?
83+
84+
if [ $result -eq 0 ] ; then
85+
if [ $# -gt 7 ] ; then
86+
for result in $(seq $(($# - 7))); do
87+
result=$1
88+
shift
89+
set -- "$@" "$result"
90+
done
91+
92+
TIMEOUT=$2 QUIET=$3 PROTOCOL=$4 HOST=$5 PORT=$6 result=$7
93+
shift 7
94+
exec "$@"
95+
fi
96+
exit 0
97+
fi
98+
99+
if [ $TIMEOUT -ne 0 -a $(date +%s) -ge $TIMEOUT_END ]; then
100+
echo "Operation timed out" >&2
101+
exit 1
102+
fi
103+
104+
sleep 1
105+
done
106+
}
107+
108+
while :; do
109+
case "$1" in
110+
http://*|https://*)
111+
HOST="$1"
112+
PROTOCOL="http"
113+
shift 1
114+
;;
115+
*:* )
116+
HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
117+
PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
118+
shift 1
119+
;;
120+
-v | --version)
121+
echo $VERSION
122+
exit
123+
;;
124+
-q | --quiet)
125+
QUIET=1
126+
shift 1
127+
;;
128+
-q-*)
129+
QUIET=0
130+
echoerr "Unknown option: $1"
131+
usage 1
132+
;;
133+
-q*)
134+
QUIET=1
135+
result=$1
136+
shift 1
137+
set -- -"${result#-q}" "$@"
138+
;;
139+
-t | --timeout)
140+
TIMEOUT="$2"
141+
shift 2
142+
;;
143+
-t*)
144+
TIMEOUT="${1#-t}"
145+
shift 1
146+
;;
147+
--timeout=*)
148+
TIMEOUT="${1#*=}"
149+
shift 1
150+
;;
151+
--)
152+
shift
153+
break
154+
;;
155+
--help)
156+
usage 0
157+
;;
158+
-*)
159+
QUIET=0
160+
echoerr "Unknown option: $1"
161+
usage 1
162+
;;
163+
*)
164+
QUIET=0
165+
echoerr "Unknown argument: $1"
166+
usage 1
167+
;;
168+
esac
169+
done
170+
171+
if ! [ "$TIMEOUT" -ge 0 ] 2>/dev/null; then
172+
echoerr "Error: invalid timeout '$TIMEOUT'"
173+
usage 3
174+
fi
175+
176+
case "$PROTOCOL" in
177+
tcp)
178+
if [ "$HOST" = "" ] || [ "$PORT" = "" ]; then
179+
echoerr "Error: you need to provide a host and port to test."
180+
usage 2
181+
fi
182+
;;
183+
http)
184+
if [ "$HOST" = "" ]; then
185+
echoerr "Error: you need to provide a host to test."
186+
usage 2
187+
fi
188+
;;
189+
esac
190+
191+
wait_for "$@"

poetry.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ discord-ext-menus = {git = "https://github.com/Rapptz/discord-ext-menus", rev =
1616
psutil = "^5.9.5"
1717
pygit2 = "^1.13.1"
1818
python-dateutil = "^2.8.2"
19+
click = "^8.1.7"
20+
typing-extensions = "^4.8.0"
1921

2022
[tool.poetry.group.dev.dependencies]
2123
pre-commit = "^3.4.0"

0 commit comments

Comments
 (0)