Merge API+APP in Docker
This commit is contained in:
parent
386e6dcb35
commit
52127adb08
21
Dockerfile
21
Dockerfile
@ -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 org.opencontainers.image.source="https://github.com/PacketParker/LinkLogger"
|
||||||
LABEL maintainer="parker <mailto:contact@pkrm.dev>"
|
LABEL maintainer="parker <mailto:contact@pkrm.dev>"
|
||||||
|
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
ENTRYPOINT [ "python" ]
|
RUN apt-get update && apt-get install -y nginx && \
|
||||||
CMD [ "-u", "linklogger.py" ]
|
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
|
18
api/main.py
18
api/main.py
@ -67,20 +67,10 @@ async def log_redirect(
|
|||||||
return RedirectResponse(url=link_record.redirect_link)
|
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
|
# Custom handler for 404 errors
|
||||||
@app.exception_handler(HTTP_404_NOT_FOUND)
|
@app.exception_handler(HTTP_404_NOT_FOUND)
|
||||||
async def custom_404_handler(request: Request, exc: HTTPException):
|
async def custom_404_handler(request: Request, exc: HTTPException):
|
||||||
# If the request is from /api, return a JSON response
|
return JSONResponse(
|
||||||
if request.url.path.startswith("/api"):
|
status_code=404,
|
||||||
return JSONResponse(
|
content={"message": "Resource not found"},
|
||||||
status_code=404,
|
)
|
||||||
content={"message": "Resource not found"},
|
|
||||||
)
|
|
||||||
# Otherwise, redirect to the login page
|
|
||||||
return RedirectResponse(url="/login")
|
|
||||||
|
@ -58,9 +58,9 @@ def load_config():
|
|||||||
with open(file_path, "w") as f:
|
with open(file_path, "w") as f:
|
||||||
f.write(
|
f.write(
|
||||||
"""
|
"""
|
||||||
ip_to_location: ""
|
config:
|
||||||
api_key: ""
|
ip_to_location:
|
||||||
"""
|
api_key:"""
|
||||||
)
|
)
|
||||||
LOG.critical(
|
LOG.critical(
|
||||||
"`config.yaml` was not found, a template has been created."
|
"`config.yaml` was not found, a template has been created."
|
||||||
|
@ -2,7 +2,8 @@ services:
|
|||||||
linklogger:
|
linklogger:
|
||||||
container_name: linklogger
|
container_name: linklogger
|
||||||
image: ghcr.io/packetparker/linklogger:latest
|
image: ghcr.io/packetparker/linklogger:latest
|
||||||
network_mode: host
|
|
||||||
volumes:
|
volumes:
|
||||||
- /path/on/system:/data
|
- /path/on/system:/data
|
||||||
restart: on-failure
|
ports:
|
||||||
|
- 5100:5000
|
||||||
|
restart: always
|
@ -6,7 +6,6 @@ from sqlalchemy import (
|
|||||||
Text,
|
Text,
|
||||||
DateTime,
|
DateTime,
|
||||||
)
|
)
|
||||||
import datetime
|
|
||||||
|
|
||||||
from database import Base
|
from database import Base
|
||||||
|
|
||||||
|
24
nginx.conf
Normal file
24
nginx.conf
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user