Skip to content

Commit

Permalink
Refactored docker compose and dependencies to fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Ionescu committed Jan 7, 2024
1 parent 2ae22f9 commit 8182e45
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 45 deletions.
33 changes: 9 additions & 24 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,18 @@ services:

# Section for our containers

# base image for building our python apps, used for speeding up the build process
web-base-image:
build:
context: ./docker-python/base
args:
requirements: /root/flask-mongodb-example/python/requirements.txt
image: web-base

# generates random numbers and lists them
# uses healthcheck by making a curl request to a GET endpoint
web-random:
build:
context: ./docker-python
context: ./docker-python/base
args:
requirements: /root/flask-mongodb-example/python/requirements.txt
image: web-standard
ports:
- "800:5000"
entrypoint: python /root/flask-mongodb-example/python/random/random_demo.py
depends_on:
- mongo
- web-base-image
healthcheck:
test: curl --silent --show-error --fail "http://localhost:5000/random?lower=0&upper10"
interval: 10s
Expand All @@ -139,10 +129,9 @@ services:
# Create, read, update and delete operations over a user collection
web-users:
build:
context: ./docker-python
context: ./docker-python/base
args:
requirements: /root/flask-mongodb-example/python/requirements.txt
image: web-standard
ports:
- "81:5000"
entrypoint: python /root/flask-mongodb-example/python/users/users.py
Expand All @@ -153,7 +142,6 @@ services:
- redis_password
depends_on:
- mongo
- web-base-image
- redis

# Uses an MQTT server (Mosquitto) to allow to publish sensor updates over MQTT
Expand All @@ -180,10 +168,9 @@ services:
# Fulltext search engine backed by fulltext MongoDb index
web-fulltext-search:
build:
context: ./docker-python
context: ./docker-python/base
args:
requirements: /root/flask-mongodb-example/python/requirements.txt
image: web-standard
ports:
- "82:5000"
entrypoint: python /root/flask-mongodb-example/python/fulltextsearch/fulltext_search.py
Expand All @@ -206,10 +193,9 @@ services:
# Baesian average demo (https://en.wikipedia.org/wiki/Bayesian_average)
web-baesian:
build:
context: ./docker-python
context: ./docker-python/base
args:
requirements: /root/flask-mongodb-example/python/requirements.txt
image: web-standard
ports:
- "84:5000"
entrypoint: python /root/flask-mongodb-example/python/baesian/baesian.py
Expand Down Expand Up @@ -264,10 +250,9 @@ services:
# A two player tic tac toe game written in flask using flask_session. It has a simple UI
web-tictactoe:
build:
context: ./docker-python
context: ./docker-python/base
args:
requirements: /root/flask-mongodb-example/python/requirements.txt
image: web-standard
ports:
- "89:5000"
entrypoint: python /root/flask-mongodb-example/python/tictactoe/tictactoe.py
Expand All @@ -288,7 +273,6 @@ services:
web-test:
image: alpine
depends_on:
- web-base-image
- web-random
- web-random-pypy
- web-users
Expand Down Expand Up @@ -322,6 +306,7 @@ secrets:
file: ./secrets/redis_pass.txt

networks:
default:
external:
name: project-network
default:
name: project-network
external: true

22 changes: 20 additions & 2 deletions docker-python/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
FROM web-base
# web-base is the Dockerfile inside ./base folder, it's splitted in 2 to speed up the multiple image build process
FROM python:3.10-buster as web-base

#[DEVELOPMENT ONLY] run in shell from root location
# mkdir docker-python/base/project; rsync -av --progress ./ docker-python/base/project --exclude docker-python

# this is the python base image that contains olny git and the downloaded project
RUN apt-get update
RUN apt install git -y

WORKDIR /root

# 1. [DEVELOPMENT ONLY] uncomment the following 2 lines (will copy files from local instead from github)
# RUN mkdir flask-mongodb-example
# COPY ./project ./flask-mongodb-example/

# 2. [DEVELOPMENT ONLY] comment the line with git clone
RUN git clone https://github.com/danionescu0/docker-flask-mongodb-example.git flask-mongodb-example

FROM python:3.10-buster
COPY --from=web-base /root/flask-mongodb-example /root/flask-mongodb-example

ARG requirements

Expand Down
17 changes: 0 additions & 17 deletions docker-python/base/Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion python/photo/requirements-photo.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Flask==2.1.1
Flask==2.3.3
pymongo==4.0.2
#flasgger 0.9.5 is not compatible with Flask 2.1.1
flasgger==0.9.7.1
Expand Down
2 changes: 1 addition & 1 deletion python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Flask==2.0.1
flask-httpauth==4.3.0
Flask-Session==0.3.2
flasgger==0.9.7.1
flasgger==0.9.4
pymongo==3.12.1
requests==2.31.0
python-dateutil==2.8.1
Expand Down

0 comments on commit 8182e45

Please sign in to comment.