diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c538ade --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM python:3.12-slim + +RUN groupadd -r greybook && useradd -r -g greybook greybook + +WORKDIR /home/greybook +RUN apt-get update +RUN apt-get install -y gcc g++ + +COPY requirements.txt requirements.txt +RUN python3 -m venv venv +RUN venv/bin/pip install -r requirements.txt +RUN venv/bin/pip install gunicorn + +COPY greybook greybook +COPY migrations migrations +COPY logs logs +COPY uploads uploads +COPY app.py . + +ENV FLASK_APP app +ENV FLASK_CONFIG production + +RUN chown -R greybook:greybook . +USER greybook + +EXPOSE 5000 +RUN venv/bin/flask db upgrade +ENTRYPOINT ["venv/bin/gunicorn", "-b", ":5000", "--access-logfile", "-", "--error-logfile", "-", "app:app"] diff --git a/Dockerfile.multi-stage b/Dockerfile.multi-stage new file mode 100644 index 0000000..ed28336 --- /dev/null +++ b/Dockerfile.multi-stage @@ -0,0 +1,38 @@ +# stage 1: build +ARG base_image=python:3.12-slim +FROM ${base_image} AS build + +WORKDIR /home/greybook +RUN apt-get update && apt-get install -y gcc g++ + +# install dependencies +COPY requirements.txt requirements.txt +RUN python3 -m venv venv +RUN venv/bin/pip install -r requirements.txt +RUN venv/bin/pip install gunicorn + +# stage 2: production +FROM ${base_image} + +RUN groupadd -r greybook && useradd -r -g greybook greybook +WORKDIR /home/greybook + +# copy the installed dependencies from the previous stage +COPY --from=build /home/greybook/venv/ venv/ + +# copy the application source code from the previous stage +COPY greybook greybook +COPY migrations migrations +COPY logs logs +COPY uploads uploads +COPY app.py . + +ENV FLASK_APP app +ENV FLASK_CONFIG production + +RUN chown -R greybook:greybook . +USER greybook + +EXPOSE 5000 +RUN venv/bin/flask db upgrade +ENTRYPOINT ["venv/bin/gunicorn", "-b", ":5000", "--access-logfile", "-", "--error-logfile", "-", "app:app"] diff --git a/tests/test_cli.py b/tests/test_cli.py index 134e4e2..9029e8a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -27,7 +27,7 @@ def test_init_command(self): result = self.cli_runner.invoke( args=['init', '--username', 'grey', '--password', '123'] ) - self.assertIn('Created the temporary administrator account.', result.output) + self.assertIn('Created the administrator account.', result.output) self.assertIn('Created the default category.', result.output) self.assertEqual(db.session.execute(select(func.count(Admin.id))).scalars().one(), 1) self.assertEqual(db.session.execute(select(Admin)).scalar().username, 'grey') @@ -39,7 +39,7 @@ def test_init_command_with_update(self): args=['init', '--username', 'new grey', '--password', '123'] ) self.assertIn('Updated the existing administrator account.', result.output) - self.assertNotIn('Created the temporary administrator account.', result.output) + self.assertNotIn('Created the administrator account.', result.output) self.assertEqual(db.session.execute(select(func.count(Admin.id))).scalars().one(), 1) self.assertEqual(db.session.execute(select(Admin)).scalar().username, 'new grey') self.assertEqual(db.session.execute(select(Category)).scalar().name, 'Default')