Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker #355

Open
wants to merge 105 commits into
base: self-host
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
f9519a3
Update requirements
jackyaz Sep 9, 2023
bcd3007
Update requirements.txt
jackyaz Sep 9, 2023
0f7af1f
Update requirements.txt
jackyaz Sep 9, 2023
2f16eec
Update requirements.txt
jackyaz Sep 9, 2023
d66ab50
Update setup.py
jackyaz Sep 9, 2023
24ff301
Revert "Update setup.py"
jackyaz Sep 9, 2023
bd7d030
Update requirements.txt
jackyaz Sep 9, 2023
22ae526
Update requirements.txt
jackyaz Sep 9, 2023
aef5b8d
Update map_cog.py
jackyaz Sep 9, 2023
9d3f408
Revert "Update map_cog.py"
jackyaz Sep 9, 2023
ad34c09
Update .gitignore
jackyaz Sep 9, 2023
0ecde05
Create build_s2.sh
jackyaz Sep 9, 2023
0a889e7
Remove azure stuff
jackyaz Sep 10, 2023
7ea4c99
Delete setup.py
jackyaz Sep 10, 2023
633c4a0
Remove broken reference to meowth
jackyaz Sep 10, 2023
27e0f14
Update error_handling.py
jackyaz Sep 10, 2023
687d622
Revert "Remove broken reference to meowth"
jackyaz Sep 10, 2023
3254513
Revert "Delete setup.py"
jackyaz Sep 10, 2023
3f3487e
Update setup.py
jackyaz Sep 10, 2023
f4c5e5c
Update map_info.py
jackyaz Sep 10, 2023
f0f06b1
Make Google Maps API key config parameter
jackyaz Sep 10, 2023
f37fb44
Update map_cog.py
jackyaz Sep 10, 2023
3e6e6ad
Update .gitignore
jackyaz Sep 10, 2023
e9be536
Update config_template.py
jackyaz Sep 10, 2023
da10c0c
Update README.md
jackyaz Sep 10, 2023
5b31e8b
Update build_s2.sh
jackyaz Sep 10, 2023
ac3afad
Update setup.py
jackyaz Sep 10, 2023
a113761
Update .gitignore
jackyaz Sep 10, 2023
43d0fad
Move config files around in preparation for Docker
jackyaz Sep 10, 2023
6a26656
Add Dockerfile
jackyaz Sep 10, 2023
a828fbe
Fix !stats
jackyaz Sep 10, 2023
824c844
Update .gitignore
jackyaz Sep 10, 2023
c5636b5
Update tables.py
jackyaz Sep 10, 2023
fb66b67
Update schema.sql
jackyaz Sep 10, 2023
f80590e
Update config_template.py
jackyaz Sep 10, 2023
57b8207
Update config_template.py
jackyaz Sep 10, 2023
a34473d
Build Docker container with postgresql self-contained
jackyaz Sep 10, 2023
c4b3e00
Remove unused scope from invite url
jackyaz Sep 10, 2023
9c23069
Update config_template.py
jackyaz Sep 11, 2023
5a0fdeb
Add pkbtlr emoji
jackyaz Sep 11, 2023
3afd70b
Fix here and pokebattler emoji reacts to raids
jackyaz Sep 12, 2023
266dd27
Fix custom emoji react removal
jackyaz Sep 12, 2023
8e70205
Update objects.py
jackyaz Sep 12, 2023
06f4f19
Fix Docker build
jackyaz Sep 22, 2023
49b02bc
make before make install
jackyaz Sep 22, 2023
bfe23c3
Update Dockerfile
jackyaz Sep 29, 2023
aacb948
Move definition of type emojis from database to config
jackyaz Sep 29, 2023
895f7ca
More fixes for type emojis
jackyaz Sep 29, 2023
ce52e6b
Fix error with duplicate expired timestamp messages
jackyaz Sep 29, 2023
f1032d3
Fix raid egg reporting
jackyaz Oct 2, 2023
bf15a4e
Revert "Fix raid egg reporting"
jackyaz Oct 2, 2023
c01b31b
Fix raid egg reporting
jackyaz Oct 2, 2023
e8e0b9a
Update repo references
jackyaz Oct 7, 2023
14259df
More repo reference updates
jackyaz Oct 7, 2023
d5e4410
Make sure db table constraints are added correctly
jackyaz Oct 7, 2023
2458db0
Rename constraints to use _pkey suffix consistently
jackyaz Oct 7, 2023
b06a162
Use constraint name on statements instead of columns
jackyaz Oct 7, 2023
be6f569
Remove randint for timestamp as db constraints fixed instead
jackyaz Oct 7, 2023
081c72f
pylint fixes
jackyaz Oct 8, 2023
6f695a3
More pylint fixes
jackyaz Oct 8, 2023
1f1a82e
Filter out inactive raid bosses from autocomplete
jackyaz Oct 8, 2023
a900b56
Remove trailing spaces in some types in config template
jackyaz Oct 8, 2023
76675f2
Filter inactive bosses in other raid_list
jackyaz Oct 8, 2023
01e18a7
Explicitly return on missing type
jackyaz Oct 8, 2023
7bb3210
pylint improvements
jackyaz Oct 10, 2023
7b25fd2
Update Dockerfile to multi-stage to reduce size
jackyaz Oct 21, 2023
f2199ac
Upload raid egg icons
jackyaz Oct 21, 2023
21112dc
Start updating raid tiers
jackyaz Oct 21, 2023
21208a4
pylint fixes
jackyaz Oct 21, 2023
dcd52b6
Add commands compatible with auto-report raids from another bot
jackyaz Oct 21, 2023
f4bdb87
pylint fixes
jackyaz Oct 21, 2023
83e46d5
Remove Silph Road API code
jackyaz Oct 21, 2023
bdb56ac
Add shadow and purified emojis as config
jackyaz Oct 21, 2023
0b36432
Update Dockerfile
jackyaz Oct 21, 2023
bd02e2a
Update pkmn_cog.py
jackyaz Oct 21, 2023
20e93c6
Update moves and move_names not just movesets
jackyaz Oct 21, 2023
99adb82
Update config_template.py
jackyaz Oct 26, 2023
8465543
Update config_template.py
jackyaz Oct 26, 2023
649e402
Update config_template.py
jackyaz Oct 26, 2023
b4bba8f
Add support for a delay in deleting channels post-raid end
jackyaz Oct 26, 2023
4c4eaf5
New images (host in repo instead of 3rd party)
jackyaz Oct 26, 2023
02d57f3
pylint improvements
jackyaz Oct 26, 2023
faec3cb
More pylint fixes
jackyaz Oct 26, 2023
7f2f1dd
Use our images
jackyaz Oct 26, 2023
42bc7f2
Update .gitignore
jackyaz Nov 1, 2023
20e7443
Upload emojis
jackyaz Nov 1, 2023
e25dc5c
Delete build_s2.sh
jackyaz Nov 1, 2023
a006efd
Update README.md
jackyaz Nov 1, 2023
a834a46
Update README.md
jackyaz Nov 1, 2023
1bff2c7
Fix f-string typo
jackyaz Nov 1, 2023
04297a1
Update entry.sh
jackyaz Nov 1, 2023
d1946ab
Fix grace period sleep
jackyaz Nov 1, 2023
05592d8
Update Dockerfile
jackyaz Nov 3, 2023
847eeab
Update Dockerfile
jackyaz Nov 3, 2023
df66433
Update Dockerfile
jackyaz Nov 3, 2023
fe54df9
Create Dockerfile-arm64
jackyaz Nov 3, 2023
6654648
Update requirements.txt
jackyaz Nov 3, 2023
03b8112
Update requirements.txt
jackyaz Nov 3, 2023
0739fd2
Dockerfile without postgresql baked in
jackyaz Nov 15, 2023
51bd5fb
Indentation cleanup
jackyaz Jan 7, 2024
f725e7a
Show when raid boss is missing from pokedex
jackyaz Jan 7, 2024
8c1f294
Make sure shadow emoji isn't shown in autocomplete
jackyaz Jan 7, 2024
b9320ab
Update Dockerfiles
jackyaz Jan 7, 2024
5396010
Add Pawmi images
jackyaz Jan 7, 2024
507aaed
Simplify raid category setup
jackyaz Feb 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,7 @@ __pycache__/
*.so

# Distribution / packaging
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
.vscode/
.vs/
meowth/config.py
docs/
logs/
meowth-logo.jpg
config/config.py
314 changes: 314 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,314 @@
FROM python:3.10.13-slim-bookworm as s2geometry
LABEL maintainer="Jack Yaz <[email protected]>"


### START S2GEOMETRY BUILD AND SETUP ###

RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
git \
libgflags-dev \
libgoogle-glog-dev \
libgtest-dev \
libssl-dev \
swig \
cmake \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir /app
RUN python3 -m venv /app/venv
ENV PATH="/app/venv/bin:$PATH"
RUN python3 -m pip install --upgrade pip

WORKDIR /src
RUN git clone https://github.com/abseil/abseil-cpp --branch 20230802.1
WORKDIR /src/abseil-cpp/build
RUN cmake -S /src/abseil-cpp -B /build/abseil-cpp -DCMAKE_INSTALL_PREFIX=/output -DABSL_BUILD_TESTING=OFF -DABSL_ENABLE_INSTALL=ON -DCMAKE_CXX_STANDARD=17 -DCMAKE_POSITION_INDEPENDENT_CODE=ON
RUN cmake --build /build/abseil-cpp --target install

WORKDIR /src
RUN git clone https://github.com/google/s2geometry.git
WORKDIR /src/s2geometry/
RUN cmake -DCMAKE_PREFIX_PATH=/output/lib/cmake/absl -DCMAKE_CXX_STANDARD=17 -DWITH_PYTHON=ON -DBUILD_TESTS=OFF
RUN make -j $(nproc)
RUN make install -j $(nproc)

WORKDIR /src/s2geometry/

RUN sed -i "s/'-DWITH_PYTHON=ON'/'-DWITH_PYTHON=ON',/" /src/s2geometry/setup.py
RUN sed -i "/'-DWITH_PYTHON=ON',/a \ '-DCMAKE_PREFIX_PATH=/output/lib/cmake'" /src/s2geometry/setup.py
RUN sed -i "/'-DWITH_PYTHON=ON',/a \ '-DCMAKE_CXX_STANDARD=17'," /src/s2geometry/setup.py
RUN sed -i "/'-DWITH_PYTHON=ON',/a \ '-DBUILD_TESTS=OFF'," /src/s2geometry/setup.py
RUN sed -i 's/install_prefix="s2geometry"/install_prefix="pywraps2"/' /src/s2geometry/setup.py

RUN python3 -m pip install cmake_build_extension wheel
RUN python3 setup.py bdist_wheel

### END S2GEOMETRY BUILD AND SETUP ###

### START POSTGRES BUILD AND SETUP ###

FROM python:3.10.13-slim-bookworm as meowth
LABEL maintainer="Jack Yaz <[email protected]>"

# explicitly set user/group IDs
RUN set -eux; \
groupadd -r postgres --gid=999; \
# https://salsa.debian.org/postgresql/postgresql-common/blob/997d842ee744687d99a2b2d95c1083a2615c79e8/debian/postgresql-common.postinst#L32-35
useradd -r -g postgres --uid=999 --home-dir=/var/lib/postgresql --shell=/bin/bash postgres; \
# also create the postgres user's home directory with appropriate permissions
# see https://github.com/docker-library/postgres/issues/274
mkdir -p /var/lib/postgresql; \
chown -R postgres:postgres /var/lib/postgresql

RUN set -ex; \
apt-get update; \
apt-get install -y --no-install-recommends \
gnupg \
; \
rm -rf /var/lib/apt/lists/*

# grab gosu for easy step-down from root
# https://github.com/tianon/gosu/releases
ENV GOSU_VERSION 1.17
RUN set -eux; \
savedAptMark="$(apt-mark showmanual)"; \
apt-get update; \
apt-get install -y --no-install-recommends ca-certificates wget; \
rm -rf /var/lib/apt/lists/*; \
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
export GNUPGHOME="$(mktemp -d)"; \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
apt-mark auto '.*' > /dev/null; \
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
chmod +x /usr/local/bin/gosu; \
gosu --version; \
gosu nobody true

# make the "en_US.UTF-8" locale so postgres will be utf-8 enabled by default
RUN set -eux; \
if [ -f /etc/dpkg/dpkg.cfg.d/docker ]; then \
# if this file exists, we're likely in "debian:xxx-slim", and locales are thus being excluded so we need to remove that exclusion (since we need locales)
grep -q '/usr/share/locale' /etc/dpkg/dpkg.cfg.d/docker; \
sed -ri '/\/usr\/share\/locale/d' /etc/dpkg/dpkg.cfg.d/docker; \
! grep -q '/usr/share/locale' /etc/dpkg/dpkg.cfg.d/docker; \
fi; \
apt-get update; apt-get install -y --no-install-recommends locales; rm -rf /var/lib/apt/lists/*; \
localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8

RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
libnss-wrapper \
xz-utils \
zstd \
; \
rm -rf /var/lib/apt/lists/*

RUN mkdir /docker-entrypoint-initdb.d

RUN set -ex; \
# pub 4096R/ACCC4CF8 2011-10-13 [expires: 2019-07-02]
# Key fingerprint = B97B 0AFC AA1A 47F0 44F2 44A0 7FCC 7D46 ACCC 4CF8
# uid PostgreSQL Debian Repository
key='B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8'; \
export GNUPGHOME="$(mktemp -d)"; \
mkdir -p /usr/local/share/keyrings/; \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key"; \
gpg --batch --export --armor "$key" > /usr/local/share/keyrings/postgres.gpg.asc; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME"

ENV PG_MAJOR 15
ENV PATH $PATH:/usr/lib/postgresql/$PG_MAJOR/bin

ENV PG_VERSION 15.6-1.pgdg120+2

RUN set -ex; \
\
# see note below about "*.pyc" files
export PYTHONDONTWRITEBYTECODE=1; \
\
dpkgArch="$(dpkg --print-architecture)"; \
aptRepo="[ signed-by=/usr/local/share/keyrings/postgres.gpg.asc ] http://apt.postgresql.org/pub/repos/apt/ bookworm-pgdg main $PG_MAJOR"; \
case "$dpkgArch" in \
amd64 | arm64 | ppc64el | s390x) \
# arches officialy built by upstream
echo "deb $aptRepo" > /etc/apt/sources.list.d/pgdg.list; \
apt-get update; \
;; \
*) \
# we're on an architecture upstream doesn't officially build for
# let's build binaries from their published source packages
echo "deb-src $aptRepo" > /etc/apt/sources.list.d/pgdg.list; \
\
savedAptMark="$(apt-mark showmanual)"; \
\
tempDir="$(mktemp -d)"; \
cd "$tempDir"; \
\
# create a temporary local APT repo to install from (so that dependency resolution can be handled by APT, as it should be)
apt-get update; \
apt-get install -y --no-install-recommends dpkg-dev; \
echo "deb [ trusted=yes ] file://$tempDir ./" > /etc/apt/sources.list.d/temp.list; \
_update_repo() { \
dpkg-scanpackages . > Packages; \
# work around the following APT issue by using "Acquire::GzipIndexes=false" (overriding "/etc/apt/apt.conf.d/docker-gzip-indexes")
# Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)
# ...
# E: Failed to fetch store:/var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)
apt-get -o Acquire::GzipIndexes=false update; \
}; \
_update_repo; \
\
# build .deb files from upstream's source packages (which are verified by apt-get)
nproc="$(nproc)"; \
export DEB_BUILD_OPTIONS="nocheck parallel=$nproc"; \
# we have to build postgresql-common first because postgresql-$PG_MAJOR shares "debian/rules" logic with it: https://salsa.debian.org/postgresql/postgresql/-/commit/99f44476e258cae6bf9e919219fa2c5414fa2876
# (and it "Depends: pgdg-keyring")
apt-get build-dep -y postgresql-common pgdg-keyring; \
apt-get source --compile postgresql-common pgdg-keyring; \
_update_repo; \
apt-get build-dep -y "postgresql-$PG_MAJOR=$PG_VERSION"; \
apt-get source --compile "postgresql-$PG_MAJOR=$PG_VERSION"; \
\
# we don't remove APT lists here because they get re-downloaded and removed later
\
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
# (which is done after we install the built packages so we don't have to redownload any overlapping dependencies)
apt-mark showmanual | xargs apt-mark auto > /dev/null; \
apt-mark manual $savedAptMark; \
\
ls -lAFh; \
_update_repo; \
grep '^Package: ' Packages; \
cd /; \
;; \
esac; \
\
apt-get install -y --no-install-recommends postgresql-common; \
sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf; \
apt-get install -y --no-install-recommends \
"postgresql-$PG_MAJOR=$PG_VERSION" \
; \
\
rm -rf /var/lib/apt/lists/*; \
\
if [ -n "$tempDir" ]; then \
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
apt-get purge -y --auto-remove; \
rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; \
fi; \
\
# some of the steps above generate a lot of "*.pyc" files (and setting "PYTHONDONTWRITEBYTECODE" beforehand doesn't propagate properly for some reason), so we clean them up manually (as long as they aren't owned by a package)
find /usr -name '*.pyc' -type f -exec bash -c 'for pyc; do dpkg -S "$pyc" &> /dev/null || rm -vf "$pyc"; done' -- '{}' +; \
\
postgres --version

# make the sample config easier to munge (and "correct by default")
RUN set -eux; \
dpkg-divert --add --rename --divert "/usr/share/postgresql/postgresql.conf.sample.dpkg" "/usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample"; \
cp -v /usr/share/postgresql/postgresql.conf.sample.dpkg /usr/share/postgresql/postgresql.conf.sample; \
ln -sv ../postgresql.conf.sample "/usr/share/postgresql/$PG_MAJOR/"; \
sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/share/postgresql/postgresql.conf.sample; \
grep -F "listen_addresses = '*'" /usr/share/postgresql/postgresql.conf.sample

RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod 2777 /var/run/postgresql

ENV PGDATA /var/lib/postgresql/data
# this 777 will be replaced by 700 at runtime (allows semi-arbitrary "--user" values)
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 777 "$PGDATA"

# We set the default STOPSIGNAL to SIGINT, which corresponds to what PostgreSQL
# calls "Fast Shutdown mode" wherein new connections are disallowed and any
# in-progress transactions are aborted, allowing PostgreSQL to stop cleanly and
# flush tables to disk, which is the best compromise available to avoid data
# corruption.
#
# Users who know their applications do not keep open long-lived idle connections
# may way to use a value of SIGTERM instead, which corresponds to "Smart
# Shutdown mode" in which any existing sessions are allowed to finish and the
# server stops when all sessions are terminated.
#
# See https://www.postgresql.org/docs/12/server-shutdown.html for more details
# about available PostgreSQL server shutdown signals.
#
# See also https://www.postgresql.org/docs/12/server-start.html for further
# justification of this as the default value, namely that the example (and
# shipped) systemd service files use the "Fast Shutdown mode" for service
# termination.
#
STOPSIGNAL SIGINT
#
# An additional setting that is recommended for all users regardless of this
# value is the runtime "--stop-timeout" (or your orchestrator/runtime's
# equivalent) for controlling how long to wait between sending the defined
# STOPSIGNAL and sending SIGKILL (which is likely to cause data corruption).
#
# The default in most runtimes (such as Docker) is 10 seconds, and the
# documentation at https://www.postgresql.org/docs/12/server-start.html notes
# that even 90 seconds may not be long enough in many instances.

### END POSTGRES BUILD AND SETUP ###

### START MEOWTH BUILD AND SETUP ###

RUN mkdir /app
COPY --from=s2geometry /src/s2geometry/dist/*.whl /app/.

RUN apt-get update && \
apt-get install -y --no-install-recommends \
git \
sudo \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN echo 'postgres ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

RUN python3 -m venv /app/venv
ENV PATH="/app/venv/bin:$PATH"
RUN python3 -m pip install --upgrade pip

RUN python3 -m pip install /app/*.whl

COPY config /app/config
COPY database /app/database
COPY meowth /app/meowth
COPY requirements.txt /app/
COPY setup.py /app/
COPY README.md /app/
COPY LICENSE /app/

WORKDIR /app

RUN python3 -m pip install -r requirements.txt
RUN python3 setup.py install

RUN ln -s /app/config/config.py /app/meowth/config.py

WORKDIR /

### END MEOWTH BUILD AND SETUP ###

ENV PYTHONPATH="/app"

COPY entry.sh /
RUN chmod 0755 /entry.sh

VOLUME /app/config
VOLUME /var/lib/postgresql/data

EXPOSE 5432

ENTRYPOINT ["/entry.sh"]

CMD ["postgres"]
Loading