-
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.
- Loading branch information
Showing
2 changed files
with
26 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM python:3.10-slim | ||
|
||
USER root | ||
RUN mkdir /app | ||
COPY ./requirements.txt /app | ||
WORKDIR /app | ||
RUN pip install --no-cache-dir --upgrade -r requirements.txt | ||
COPY ./src /app/src | ||
WORKDIR /app/src | ||
|
||
ENV FLASK_APP=app.py | ||
ENV FLASK_DEBUG=1 | ||
|
||
CMD ["flask", "run", "--host=0.0.0.0"] |
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 @@ | ||
When creating a docker mongodb container we must implement two steps to enhance security. | ||
|
||
1. Authentication: we need to put some auth security when creating the docker container. Either in docker-compose or dockerfile. | ||
What I did: In docker-compose, when adding an env file, this file needs to have 3 env variables: MONGO_INITDB_ROOT_USERNAME, MONGO_INITDB_ROOT_PASSWORD, MONGO_INITDB_DATABASE | ||
|
||
2. Seeding and creating some database: after creating the container, it would be great to have some databases, collections and data so the app can use them. | ||
What I did: Create a script file (.sh) which is going to be executed inmediately by the container after being up. | ||
Using mongoimport command on the OS cli (container linux OS): | ||
mongoimport --authenticationDatabase=$MONGO_INITDB_DATABASE -u=$MONGO_INITDB_ROOT_USERNAME -p=$MONGO_INITDB_ROOT_PASSWORD -d=<database> -c=<collection> --file=<filepath> | ||
* we can add --drop to erase any old collection and --jsonArray if we have an array of documents (array of js objects/dictionaries) | ||
|
||
|