-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |