forked from rochacbruno/fastapi-project-template
-
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.
feature: Enabling containerized development
fixes rochacbruno#5 enables rochacbruno#7
- Loading branch information
Sarath P S
committed
Sep 24, 2021
1 parent
031b494
commit 962817b
Showing
7 changed files
with
109 additions
and
7 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,36 @@ | ||
|
||
# Base Image for builder | ||
FROM python:3.9 as builder | ||
|
||
# Install Requirements | ||
COPY requirements.txt / | ||
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /wheels -r requirements.txt | ||
|
||
|
||
# Build the app image | ||
FROM python:3.9 | ||
|
||
# Create directory for the app user | ||
RUN mkdir -p /home/app | ||
|
||
# Create the app user | ||
RUN groupadd app && useradd -g app app | ||
|
||
# Create the home directory | ||
ENV HOME=/home/app | ||
ENV APP_HOME=/home/app/web | ||
RUN mkdir $APP_HOME | ||
WORKDIR $APP_HOME | ||
|
||
# Install Requirements | ||
COPY --from=builder /wheels /wheels | ||
COPY --from=builder requirements.txt . | ||
RUN pip install --no-cache /wheels/* | ||
|
||
COPY . $APP_HOME | ||
|
||
RUN chown -R app:app $APP_HOME | ||
|
||
USER app | ||
|
||
CMD ["uvicorn", "project_name.app:app", "--host=0.0.0.0","--port=8000","--reload"] |
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,26 @@ | ||
version: '3.9' | ||
|
||
services: | ||
app: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.dev | ||
ports: | ||
- "8000:8000" | ||
environment: | ||
- DATABASE_URL=postgres://postgres:postgres@db:5432/project_name | ||
volumes: | ||
- .:/home/app/web | ||
depends_on: | ||
- db | ||
db: | ||
build: postgres | ||
image: project_name_postgres-13-alpine-multi-user | ||
volumes: | ||
- $HOME/.postgres/project_name_db/data/postgresql:/var/lib/postgresql/data | ||
ports: | ||
- 5435:5432 | ||
environment: | ||
- POSTGRES_DBS=project_name, project_name_test | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_PASSWORD=postgres |
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,2 @@ | ||
FROM postgres:alpine3.14 | ||
COPY create-databases.sh /docker-entrypoint-initdb.d/ |
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,23 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
set -u | ||
|
||
function create_user_and_database() { | ||
local database=$1 | ||
echo "Creating user and database '$database'" | ||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL | ||
CREATE USER $database PASSWORD '$database'; | ||
CREATE DATABASE $database; | ||
GRANT ALL PRIVILEGES ON DATABASE $database TO $database; | ||
EOSQL | ||
} | ||
|
||
if [ -n "$POSTGRES_DBS" ]; then | ||
echo "Creating DB(s): $POSTGRES_DBS" | ||
for db in $(echo $POSTGRES_DBS | tr ',' ' '); do | ||
create_user_and_database $db | ||
done | ||
echo "Multiple databases created" | ||
fi |
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