-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Dockerfiles and development Docker Compose script
- Loading branch information
Showing
13 changed files
with
147 additions
and
13 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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,22 @@ | ||
# ---------------------------------------------------------------------------- # | ||
# Stage 1 (Build) # | ||
# ---------------------------------------------------------------------------- # | ||
FROM node:18-alpine AS builder | ||
|
||
WORKDIR /app | ||
|
||
COPY package.json . | ||
RUN yarn install | ||
|
||
COPY . . | ||
|
||
RUN ["yarn", "build-docker-compose"] | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# Stage 2 (Serve) # | ||
# ---------------------------------------------------------------------------- # | ||
|
||
FROM nginx:1.23-alpine | ||
|
||
COPY nginx.conf /etc/nginx/nginx.conf | ||
COPY --from=builder /app/build /app/build |
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,17 @@ | ||
# It's necessary to have an `events` directive, even if it's just empty. | ||
# Source: https://stackoverflow.com/questions/54481423/nginx-startup-prompt-emerg-no-events-section-in-configuration. | ||
events {} | ||
http { | ||
server { | ||
root /app/build; | ||
index index.html; | ||
|
||
location / { | ||
# This `include` directive is necessary for correctly loading CSS | ||
# files. | ||
# Source: https://stackoverflow.com/questions/10075304/nginx-fails-to-load-css-files. | ||
include /etc/nginx/mime.types; | ||
try_files $uri /index.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
Empty file.
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
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,42 @@ | ||
# This docker-compose file is meant to be run for development and serves as a | ||
# guideline for a production deployment. | ||
version: '3.8' | ||
|
||
# Techsuite consists of 3 services: | ||
# 1. React client at port 3000. | ||
# 2. Flask REST API and websocket server at port 5000. | ||
# 3. PostgreSQL database server at port 4000. | ||
services: | ||
client: | ||
build: | ||
context: client | ||
dockerfile: Dockerfile | ||
ports: | ||
- 3000:80 | ||
db: | ||
build: | ||
context: server | ||
dockerfile: Dockerfile.db | ||
environment: | ||
# These credentials are used for creating the db superuser. They're not | ||
# the credentials we use from the API side. | ||
POSTGRES_PASSWORD: 1989 | ||
POSTGRES_USER: admin | ||
ports: | ||
- 5432:5432 | ||
volumes: | ||
- db-data:/var/lib/postgres/data | ||
api: | ||
build: | ||
context: server | ||
dockerfile: Dockerfile.api | ||
depends_on: | ||
- db | ||
environment: | ||
PORT: 5000 | ||
DATABASE_URI: postgresql://tim:1989@db:5432/techsuite | ||
BASE_URI: http://localhost:5000/api | ||
ports: | ||
- 5000:5000 | ||
volumes: | ||
db-data: |
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 @@ | ||
venv |
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,30 @@ | ||
# ----------------------------------- Setup ---------------------------------- # | ||
FROM python:3.10-alpine | ||
|
||
WORKDIR /api | ||
|
||
COPY requirements.txt . | ||
|
||
# There are issues with installing psycopg2 on Alpine Linux (and other Linux | ||
# distributions). | ||
# See a good discussion of dependency issues: https://github.com/psycopg/psycopg2/issues/684. | ||
RUN apk update \ | ||
&& apk add postgresql-dev gcc python3-dev musl-dev \ | ||
&& pip install psycopg2 \ | ||
&& pip install gunicorn \ | ||
&& pip install -r requirements.txt | ||
|
||
COPY . . | ||
|
||
# -------------------------------- Production -------------------------------- # | ||
# Create all tables | ||
RUN echo "create_all()" | python3 -i src/db_manage.py 2> /dev/null | ||
|
||
# Using Gunicorn and gevent-websocket server. | ||
# See: | ||
# - https://flask.palletsprojects.com/en/2.2.x/deploying/gunicorn/. | ||
# - https://stackoverflow.com/questions/9444405/gunicorn-and-websockets. | ||
WORKDIR /api/src | ||
|
||
|
||
CMD gunicorn -k "geventwebsocket.gunicorn.workers.GeventWebSocketWorker" -b 0.0.0.0:5000 server: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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM postgres:14-alpine | ||
|
||
EXPOSE 4000 | ||
|
||
WORKDIR / | ||
|
||
COPY db-init.sh /docker-entrypoint-initdb.d | ||
|
||
# Create all the tables and initialise the database with a set of existing | ||
# channels, users, connections, messages, etc. | ||
COPY ./seeds/full-2.sql /docker-entrypoint-initdb.d | ||
|
||
# No need to override the default postgres CMD in this Dockerfile. |
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,10 @@ | ||
#!/bin/sh | ||
# A script to initialise the PostgreSQL Docker container. | ||
|
||
set -e | ||
|
||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL | ||
CREATE USER tim WITH PASSWORD '1989'; | ||
CREATE DATABASE techsuite; | ||
GRANT ALL PRIVILEGES ON DATABASE techsuite TO tim; | ||
EOSQL |
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
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