diff options
author | Parker <contact@pkrm.dev> | 2024-11-11 23:57:44 -0600 |
---|---|---|
committer | Parker <contact@pkrm.dev> | 2024-11-11 23:57:44 -0600 |
commit | 52127adb08cff9e6bf6bad0125c3b5f7e0d04db2 (patch) | |
tree | 9b2b8a793aed986a54603b8530af2a0f8ae4ca30 | |
parent | 386e6dcb35c866d204e2d32fd814aa7ca3ed15ae (diff) |
Merge API+APP in Docker
-rw-r--r-- | Dockerfile | 21 | ||||
-rw-r--r-- | api/main.py | 18 | ||||
-rw-r--r-- | config.py | 6 | ||||
-rw-r--r-- | docker-compose.yaml | 5 | ||||
-rw-r--r-- | models.py | 1 | ||||
-rw-r--r-- | nginx.conf | 24 |
6 files changed, 51 insertions, 24 deletions
@@ -1,12 +1,25 @@ -FROM python:3.11-slim +FROM node:18-slim AS build-ui + +WORKDIR /app +COPY app/ ./ +RUN yarn install +RUN yarn build + +FROM python:3.11-slim AS api LABEL org.opencontainers.image.source="https://github.com/PacketParker/LinkLogger" LABEL maintainer="parker <mailto:contact@pkrm.dev>" WORKDIR / - COPY . . RUN pip install -r requirements.txt -ENTRYPOINT [ "python" ] -CMD [ "-u", "linklogger.py" ]
\ No newline at end of file +RUN apt-get update && apt-get install -y nginx && \ + rm -rf /var/lib/apt/lists/* + +# Move the built files into the nginx share +COPY --from=build-ui /app/dist /usr/share/nginx/html +# Replace the default site with the LinkLogger config +COPY nginx.conf /etc/nginx/sites-enabled/default + +CMD service nginx start && python -u linklogger.py
\ No newline at end of file diff --git a/api/main.py b/api/main.py index 8ce333f..8be260d 100644 --- a/api/main.py +++ b/api/main.py @@ -67,20 +67,10 @@ async def log_redirect( return RedirectResponse(url=link_record.redirect_link) -# Redirect /api -> /api/docs -@app.get("/api") -async def redirect_to_docs(): - return RedirectResponse(url="/docs") - - # Custom handler for 404 errors @app.exception_handler(HTTP_404_NOT_FOUND) async def custom_404_handler(request: Request, exc: HTTPException): - # If the request is from /api, return a JSON response - if request.url.path.startswith("/api"): - return JSONResponse( - status_code=404, - content={"message": "Resource not found"}, - ) - # Otherwise, redirect to the login page - return RedirectResponse(url="/login") + return JSONResponse( + status_code=404, + content={"message": "Resource not found"}, + ) @@ -58,9 +58,9 @@ def load_config(): with open(file_path, "w") as f: f.write( """ - ip_to_location: "" - api_key: "" - """ +config: + ip_to_location: + api_key:""" ) LOG.critical( "`config.yaml` was not found, a template has been created." diff --git a/docker-compose.yaml b/docker-compose.yaml index 0f9f033..6629c61 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,7 +2,8 @@ services: linklogger: container_name: linklogger image: ghcr.io/packetparker/linklogger:latest - network_mode: host volumes: - /path/on/system:/data - restart: on-failure
\ No newline at end of file + ports: + - 5100:5000 + restart: always
\ No newline at end of file @@ -6,7 +6,6 @@ from sqlalchemy import ( Text, DateTime, ) -import datetime from database import Base diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..c07ddcb --- /dev/null +++ b/nginx.conf @@ -0,0 +1,24 @@ +server { + listen 5000; + + # Serve React static files + location / { + root /usr/share/nginx/html; + try_files $uri $uri/ /index.html; + } + + # Proxy API requests to FastAPI + location /api/ { + proxy_pass http://localhost:5252; + set_real_ip_from 0.0.0.0/0; + real_ip_header X-Forwarded-For; + real_ip_recursive on; + } + # Proxy short link requests to FastAPI + location /c/ { + proxy_pass http://localhost:5252; + set_real_ip_from 0.0.0.0/0; + real_ip_header X-Forwarded-For; + real_ip_recursive on; + } +}
\ No newline at end of file |