From 1887be54e5f87e2e27e184b9cb146a12816c45fa Mon Sep 17 00:00:00 2001 From: Elia el Lazkani Date: Fri, 27 Dec 2024 09:58:15 +0100 Subject: [PATCH] chore(#17): Adds Docker packaging to the project --- Dockerfile | 25 +++++++++++++++++++++++++ config/config.yaml | 3 ++- shortenit/main.py | 2 +- shortenit/web.py | 4 +++- 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..599a9f9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM node:23-alpine3.20 AS node + +WORKDIR /shortenit +COPY frontend /shortenit + +RUN npm run build + +FROM python:3.13-alpine3.21 AS python + +WORKDIR /shortenit +COPY . /shortenit +COPY --from=node /ui/ /shorthenit/ui/ + +RUN rm -rf dist/ && \ + pip install poetry && \ + poetry build + +FROM python:3.13-alpine3.21 + +COPY --from=python /shortenit/dist/*.tar.gz /shortenit/ + +RUN pip install /shortenit/*.tar.gz && \ + rm -rf /shortenit + +ENTRYPOINT ["shortenit"] diff --git a/config/config.yaml b/config/config.yaml index 0f0d050..2c76349 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -1,5 +1,6 @@ Server: - host: 127.0.0.1 + hostname: localhost + bind_ip: 0.0.0.0 port: 8000 scheme: http cors: False diff --git a/shortenit/main.py b/shortenit/main.py index ea2d32f..16d890f 100644 --- a/shortenit/main.py +++ b/shortenit/main.py @@ -45,7 +45,7 @@ def main() -> typing.NoReturn: with Session(bind=engine, autoflush=True, future=True) as session: handler = SiteHandler(config, session, shorten_it, lengthen_it) web = Web(handler, debug=debug) - web.host = server_config.get("host", None) + web.host = server_config.get("bind_ip", None) web.port = server_config.get("port", None) web.start_up() diff --git a/shortenit/web.py b/shortenit/web.py index 179c50a..c3d5363 100644 --- a/shortenit/web.py +++ b/shortenit/web.py @@ -63,13 +63,15 @@ class SiteHandler: return self.configuration.get("Server", None) def _get_host(self): - host = self._get_server_config()["host"] + host = self._get_server_config()["hostname"] port = self._get_server_config()["port"] scheme = self._get_server_config()["scheme"] return scheme, host, port def _get_url(self, stub): scheme, host, port = self._get_host() + if (port == "443" and scheme == "https") or (port == "80" and scheme == "http"): + return urlunparse((scheme, f"{host}", f"/r/{stub}", "", "", "")) return urlunparse((scheme, f"{host}:{port}", f"/r/{stub}", "", "", "")) def shortenit(self):