Skip to content

Commit

Permalink
♻️ 🐳 improve init execution on entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellodesales committed Mar 8, 2023
1 parent 7ae6f3c commit 138327a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@ COPY *.sql /viasat/minitwit
####
FROM builder AS tester

# Only copy the development tools from the requirements for tests
COPY requirements-dev.txt .
RUN pip install -r requirements-dev.txt

# Note that we are executing the tests here because we don't want to build
# A runtime image before the tests are executed successfully!
RUN pytest test_minitwit.py
# All the requirements are installed and so the test cases can be executed
CMD ["pytest", "test_minitwit.py"]

###
### runtime environment containing only the runtime dependencies.
### Runtime environment containing only the runtime dependencies.
### Note that this image does NOT have anything for testing!
###
FROM builder AS runtime

# All the other resources are there, so let's add the run-app as it's part of the runtime
# Note that the builder runtime defines the WORKDIR already so we can COPY to .
COPY run-app .
COPY init-db .

RUN rm -rf requirements* test_minitwit.py

ENTRYPOINT ["bash", "/viasat/minitwit/run-app"]
6 changes: 4 additions & 2 deletions init-db
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ export FLASK_APP=minitwit.py
export LC_ALL=en_US.utf-8
export LANG=en_US.utf-8

DB_DIR=${DB_DIR:-/var/minitwit}

# Initialize the path where the db is
if [ ! -d /var/minitwit ]; then
mkdir -p /var/minitwit/
if [ ! -d ${DB_DIR} ]; then
mkdir -p ${DB_DIR}
fi

flask initdb
6 changes: 4 additions & 2 deletions run-app
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ export FLASK_APP=minitwit.py
export LC_ALL=en_US.utf-8
export LANG=en_US.utf-8

if [ ! -f /var/minitwit/minitwit.db ] || [ -n "${INIT_DB}" ]; then
echo "Initializing database at /var/minitwit/minitwit.db"
export DB_DIR=${DB_DIR:-/var/minitwit}

if [ ! -f ${DB_DIR}/minitwit.db ] || [ -n "${INIT_DB}" ]; then
echo "Initializing database at ${DB_DIR}/minitwit.db"
./init-db
fi

Expand Down

0 comments on commit 138327a

Please sign in to comment.