From 4eeeff474cd60aa6cf8ede7f85a3dba6f04f147e Mon Sep 17 00:00:00 2001 From: Liam Fitzpatrick Date: Sat, 3 Jan 2026 18:50:06 -0500 Subject: [PATCH] create containerfiles --- backend/Containerfile | 12 ++++++++++++ backend/app.py | 2 +- backend/requirements.txt | 1 + frontend/Containerfile | 21 +++++++++++++++++++++ frontend/nginx.conf | 19 +++++++++++++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 backend/Containerfile create mode 100644 frontend/Containerfile create mode 100644 frontend/nginx.conf diff --git a/backend/Containerfile b/backend/Containerfile new file mode 100644 index 0000000..af41b21 --- /dev/null +++ b/backend/Containerfile @@ -0,0 +1,12 @@ +FROM docker.io/library/python:3.11-slim + +WORKDIR /app + +COPY requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt + +COPY app.py ./ + +EXPOSE 5000 + +CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:app"] diff --git a/backend/app.py b/backend/app.py index c5fc726..1abff21 100644 --- a/backend/app.py +++ b/backend/app.py @@ -5,7 +5,7 @@ app = Flask(__name__) CORS(app) -@app.get("/api/hello") +@app.get("/hello") def hello(): return jsonify(message="Hello from Flask") diff --git a/backend/requirements.txt b/backend/requirements.txt index 4017e14..ea39874 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,2 +1,3 @@ flask==3.0.0 flask-cors==4.0.0 +gunicorn==21.2.0 diff --git a/frontend/Containerfile b/frontend/Containerfile new file mode 100644 index 0000000..71e9bd1 --- /dev/null +++ b/frontend/Containerfile @@ -0,0 +1,21 @@ +FROM docker.io/library/node:20-alpine AS build + +WORKDIR /app + +COPY package*.json ./ + +RUN if [ -f package-lock.json ]; then npm ci; else npm install; fi + +COPY . ./ + +RUN npm run build + +FROM docker.io/library/nginx:1.25-alpine + +ENV BACKEND_URL=http://backend:5000/ +COPY nginx.conf /etc/nginx/templates/default.conf.template +COPY --from=build /app/dist /usr/share/nginx/html + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/frontend/nginx.conf b/frontend/nginx.conf new file mode 100644 index 0000000..02d02a2 --- /dev/null +++ b/frontend/nginx.conf @@ -0,0 +1,19 @@ +server { + listen 80; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + location /api/ { + proxy_pass ${BACKEND_URL}/; # trailing slash is the key + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location / { + try_files $uri /index.html; + } +}