File tree Expand file tree Collapse file tree 6 files changed +126
-0
lines changed
Expand file tree Collapse file tree 6 files changed +126
-0
lines changed Original file line number Diff line number Diff line change 11# Deploying a Flask and React Microservice to AWS ECS
2+
3+ https://testdriven.io/courses/aws-flask-react/
Original file line number Diff line number Diff line change 1+ services :
2+
3+ api :
4+ build :
5+ context : ./services/users
6+ dockerfile : Dockerfile.prod
7+ ports :
8+ - 5004:5000
9+ environment :
10+ - FLASK_ENV=production
11+ - APP_SETTINGS=src.config.ProductionConfig
12+ - DATABASE_URL=postgres://postgres:postgres@api-db:5432/api_prod
13+ - DATABASE_TEST_URL=postgres://postgres:postgres@api-db:5432/api_test
14+ - SECRET_KEY=my_precious
15+ depends_on :
16+ - api-db
17+
18+ api-db :
19+ build :
20+ context : ./services/users/src/db
21+ dockerfile : Dockerfile
22+ expose :
23+ - 5432
24+ environment :
25+ - POSTGRES_USER=postgres
26+ - POSTGRES_PASSWORD=postgres
27+
28+ client :
29+ build :
30+ context : ./services/client
31+ dockerfile : Dockerfile.prod
32+ args :
33+ - NODE_ENV=production
34+ - VITE_API_SERVICE_URL=${VITE_API_SERVICE_URL}
35+ ports :
36+ - 3007:80
37+ depends_on :
38+ - api
Original file line number Diff line number Diff line change 1+ ###########
2+ # BUILDER #
3+ ###########
4+
5+ # pull official base image
6+ FROM node:20.16.0 AS builder
7+
8+ # set working directory
9+ WORKDIR /usr/src/app
10+
11+ # add `/usr/src/app/node_modules/.bin` to $PATH
12+ ENV PATH /usr/src/app/node_modules/.bin:$PATH
13+
14+ # install and cache app dependencies
15+ COPY package.json .
16+ COPY package-lock.json .
17+ RUN npm ci
18+
19+ # set environment variables
20+ ARG VITE_API_SERVICE_URL
21+ ENV VITE_API_SERVICE_URL=$VITE_API_SERVICE_URL
22+ ARG NODE_ENV
23+ ENV NODE_ENV=$NODE_ENV
24+
25+ # create build
26+ COPY . .
27+ RUN vite build
28+
29+
30+ #########
31+ # FINAL #
32+ #########
33+
34+ # base image
35+ FROM nginx:stable-alpine
36+
37+ # update nginx conf
38+ RUN rm -rf /etc/nginx/conf.d
39+ COPY conf /etc/nginx
40+
41+ # copy static files
42+ COPY --from=builder /usr/src/app/dist /usr/share/nginx/html
43+
44+ # expose port
45+ EXPOSE 80
46+
47+ # run nginx
48+ CMD ["nginx", "-g", "daemon off;"]
Original file line number Diff line number Diff line change 1+ server {
2+ listen 80;
3+ location / {
4+ root /usr/share/nginx/html;
5+ index index.html index.htm;
6+ try_files $uri $uri/ /index.html;
7+ }
8+ error_page 500 502 503 504 /50x.html;
9+ location = /50x.html {
10+ root /usr/share/nginx/html;
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ # pull official base image
2+ FROM python:3.12.0-slim-bookworm
3+
4+ # set working directory
5+ WORKDIR /usr/src/app
6+
7+ # set environment variables
8+ ENV PYTHONDONTWRITEBYTECODE=1
9+ ENV PYTHONUNBUFFERED=1
10+
11+ # install system dependencies
12+ RUN apt-get update \
13+ && apt-get -y install netcat-traditional \
14+ && apt-get clean
15+
16+ # install dependencies
17+ RUN pip install --upgrade pip
18+ COPY ./requirements.txt .
19+ RUN pip install -r requirements.txt
20+
21+ # add app
22+ COPY . .
23+
24+ # run server
25+ CMD gunicorn -b 0.0.0.0:5000 manage:app
Original file line number Diff line number Diff line change 1+ CREATE DATABASE api_prod ;
12CREATE DATABASE api_dev ;
23CREATE DATABASE api_test ;
You can’t perform that action at this time.
0 commit comments