Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhea0 committed Dec 4, 2024
1 parent fae4e6d commit 990020d
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Deploying a Flask and React Microservice to AWS ECS

https://testdriven.io/courses/aws-flask-react/
38 changes: 38 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
services:

api:
build:
context: ./services/users
dockerfile: Dockerfile.prod
ports:
- 5004:5000
environment:
- FLASK_ENV=production
- APP_SETTINGS=src.config.ProductionConfig
- DATABASE_URL=postgres://postgres:postgres@api-db:5432/api_prod
- DATABASE_TEST_URL=postgres://postgres:postgres@api-db:5432/api_test
- SECRET_KEY=my_precious
depends_on:
- api-db

api-db:
build:
context: ./services/users/src/db
dockerfile: Dockerfile
expose:
- 5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres

client:
build:
context: ./services/client
dockerfile: Dockerfile.prod
args:
- NODE_ENV=production
- VITE_API_SERVICE_URL=${VITE_API_SERVICE_URL}
ports:
- 3007:80
depends_on:
- api
48 changes: 48 additions & 0 deletions services/client/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
###########
# BUILDER #
###########

# pull official base image
FROM node:20.16.0 AS builder

# set working directory
WORKDIR /usr/src/app

# add `/usr/src/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH

# install and cache app dependencies
COPY package.json .
COPY package-lock.json .
RUN npm ci

# set environment variables
ARG VITE_API_SERVICE_URL
ENV VITE_API_SERVICE_URL=$VITE_API_SERVICE_URL
ARG NODE_ENV
ENV NODE_ENV=$NODE_ENV

# create build
COPY . .
RUN vite build


#########
# FINAL #
#########

# base image
FROM nginx:stable-alpine

# update nginx conf
RUN rm -rf /etc/nginx/conf.d
COPY conf /etc/nginx

# copy static files
COPY --from=builder /usr/src/app/dist /usr/share/nginx/html

# expose port
EXPOSE 80

# run nginx
CMD ["nginx", "-g", "daemon off;"]
12 changes: 12 additions & 0 deletions services/client/conf/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
25 changes: 25 additions & 0 deletions services/users/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# pull official base image
FROM python:3.12.0-slim-bookworm

# set working directory
WORKDIR /usr/src/app

# set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

# install system dependencies
RUN apt-get update \
&& apt-get -y install netcat-traditional \
&& apt-get clean

# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt

# add app
COPY . .

# run server
CMD gunicorn -b 0.0.0.0:5000 manage:app
1 change: 1 addition & 0 deletions services/users/src/db/create.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
CREATE DATABASE api_prod;
CREATE DATABASE api_dev;
CREATE DATABASE api_test;

0 comments on commit 990020d

Please sign in to comment.