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

Production ready docker #919

Merged
merged 15 commits into from Nov 25, 2021
20 changes: 20 additions & 0 deletions .dockerignore
@@ -1,2 +1,22 @@
.dockerignore
.env
.git
.github
.gitignore
.isort.cfg
.readthedocs.yaml
.travis.yml
.venv
.vscode
assets
CHANGELOG.md
CONTRIBUTORS
docker-compose.*
Dockerfile
docs
LICENSE
Makefile
MANIFEST.in
README.md
SECURITY.md
tox.ini
24 changes: 18 additions & 6 deletions Dockerfile
@@ -1,5 +1,8 @@
FROM python:3.7-alpine
FROM python:3.9-alpine
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using 3.10-alpine? Is it because we don't officially support it yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, didn't test with 3.10, but once tests are updated we should update this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can go ahead with 3.10 now that #921 was merged

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright !


ENV PORT="8000"

# ihatemoney configuration
ENV DEBUG="False" \
ACTIVATE_ADMIN_DASHBOARD="False" \
ACTIVATE_DEMO_PROJECT="True" \
Expand All @@ -21,13 +24,22 @@ ENV DEBUG="False" \
ENABLE_CAPTCHA="False" \
LEGAL_LINK="False"

RUN mkdir -p /etc/ihatemoney &&\
pip install --no-cache-dir gunicorn pymysql;

ADD . /src

RUN pip install --no-cache-dir -e /src
RUN echo "**** install runtime packages ****" && \
apk add --no-cache \
shadow && \
echo "**** create runtime folder ****" && \
mkdir -p /etc/ihatemoney &&\
echo "**** install pip packages ****" && \
pip install --no-cache-dir gunicorn pymysql && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about installing psycopg2 too, so you can use a postgres database with the docker image?

Copy link
Contributor

@Nikos410 Nikos410 Nov 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried adding it afterwards by running from a simple local Dockerfile like this:

FROM ihatemoney/ihatemoney:5.1.1
RUN pip install --no-cache-dir psycopg2

But building fails, not sure why - I don't really have experience using python.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tell us how it fails, maybe you have some logs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I've opened a proper Issue: #924

pip install --no-cache-dir -e /src && \
echo "**** create user abc:abc ****" && \
useradd -u 1000 -U -d /src abc && \
echo "**** cleanup ****" && \
rm -rf \
/tmp/*

VOLUME /database
EXPOSE 8000
EXPOSE ${PORT}
ENTRYPOINT ["/src/conf/entrypoint.sh"]
24 changes: 20 additions & 4 deletions conf/entrypoint.sh
Expand Up @@ -3,7 +3,7 @@
# Fail the whole script on the first failure.
set -e

cat <<EOF > /etc/ihatemoney/ihatemoney.cfg
cat <<EOF >/etc/ihatemoney/ihatemoney.cfg
DEBUG = $DEBUG
ACTIVATE_ADMIN_DASHBOARD = $ACTIVATE_ADMIN_DASHBOARD
ACTIVATE_DEMO_PROJECT = $ACTIVATE_DEMO_PROJECT
Expand All @@ -26,8 +26,24 @@ ENABLE_CAPTCHA = $ENABLE_CAPTCHA
LEGAL_LINK = "$LEGAL_LINK"
EOF

PUID=${PUID:-0}
PGID=${PGID:-0}

echo "
User uid: $PUID
User gid: $PGID
"

# Start gunicorn without forking
exec gunicorn ihatemoney.wsgi:application \
-b 0.0.0.0:8000 \
cmd="exec gunicorn ihatemoney.wsgi:application \
-b 0.0.0.0:$PORT \
--log-syslog \
"$@"
$@"

if [ "$PGID" -ne 0 -a "$PUID" -ne 0 ]; then
groupmod -o -g "$PGID" abc
usermod -o -u "$PUID" abc
cmd="su - abc -c '$cmd'"
fi

eval "$cmd"
4 changes: 1 addition & 3 deletions docker-compose.test.yml
Expand Up @@ -4,10 +4,8 @@ version: "3.9"
services:
ihatemoney:
build: .
ports:
- "8000:8000"
sut:
image: alpine
command: wget --spider ihatemoney:8000
command: sh -c 'wget -qO- ihatemoney:8000/healthcheck | grep "OK"'
Glandos marked this conversation as resolved.
Show resolved Hide resolved
depends_on:
- ihatemoney
5 changes: 4 additions & 1 deletion docker-compose.yml
Expand Up @@ -4,7 +4,7 @@ version: "3.9"

services:
ihatemoney:
build: .
image: ihatemoney/ihatemoney:latest
environment:
- DEBUG=False
- ACTIVATE_ADMIN_DASHBOARD=False
Expand All @@ -26,5 +26,8 @@ services:
- SQLALCHEMY_TRACK_MODIFICATIONS=False
- ENABLE_CAPTCHA=False
- LEGAL_LINK=
- PORT=8000
- PUID=0
- PGID=0
ports:
- "8000:8000"
5 changes: 5 additions & 0 deletions ihatemoney/web.py
Expand Up @@ -152,6 +152,11 @@ def pull_project(endpoint, values):
raise Redirect303(url_for(".authenticate", project_id=project_id))


@main.route("/healthcheck", methods=["GET"])
def health():
return "OK"


@main.route("/admin", methods=["GET", "POST"])
def admin():
"""Admin authentication.
Expand Down