Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the backend in Python #107

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

Refactor the backend in Python #107

wants to merge 7 commits into from

Conversation

atxr
Copy link
Contributor

@atxr atxr commented May 19, 2023

WORK IN PROGRESS

ctmbl and others added 6 commits April 15, 2023 01:20
* Add requirements.txt file for future python backend

* Refactor Dockerfile to run a flask backend

* Rename NODE_PORT to BACKEND_PORT

* Rename node-app to flask-app

* Rename BACKEND_PORT to FLASK_RUN_PORT

* Merge with main: FIX: remove the `with` block under `actions/checkout@v3` in `prettier` (#91)

* Run prettier

---------

Co-authored-by: Antoine Stevan <[email protected]>
This merge is needed to bring the recent changes of #92 to the
'backend/python` branch
* Fix non persistent DB by mounting the right volume in the container

* Configure MongoDB port through additional flags to pass to mongod in conatiner

* Run prettier

* Add mongodb folder to gitignore

* Set bitnami/mongodb version tag to latest

pros and cons have been discussed here: #95 (comment)
* add a Makefile with `pretty` rule

* add a note about failing CI in the PR template

* Fix pretty make rule to exclude mongodb folder from prettier checks

* Use npm run instead of make for the 'pretty rule'

---------

Co-authored-by: ctmbl <[email protected]>
* Update backend/.gitignore

* Add basic app.py

* Add /articles and /article/<id> routes

* Fixes: working basic routes articles and articles/<id>
* Add Node development environment (#86 still not merged)

Remove env-cmd call in npm 'start' script --> handle by docker compose

Add nginx dev config (see commit body)

Took the one before [https](8087def) was introduced
It was introduced with [dev and prod mode](f20a338)

Add backend dev Dockerfile

Add frontend dev Dockerfile

Add dev docker compose

Separate dev and prod mode for the nginx template

created 2 separate template conf and pass an env var MODE
from .env to docker to run.sh for the nginx config

Update shared volumes in docker compose dev to only share source code

Fix nginx container error because targets not found

name of react and not containers was wrong

Remove commented dead config from nginx conf dev template

Add explicit logging config to nginx conf dev template

Adapt docker-compose-dev.yml to local containerized DB

Refactor docker-compose-dev.yml to be easier to understand

I simply refactor each service config attributes order
the order I chose is arbitrary but seems logical
 - [A|B] means A OR B, because they are mutually exclusive
```yml
services:
  <service name>:
    depends_on:
    [build|image]:
    networks:
    restart:
    env_file:
    ports:
    volumes:
```

Remove a useless tabulation in docker-compose-dev.yml

Refactor docker-compose.yml the same way than docker-compose-dev.yml

I simply refactor each service config attributes order
the order I chose is arbitrary but seems logical
 - [A|B] means A OR B, because they are mutually exclusive
```yml
services:
  <service name>:
    depends_on:
    [build|image]:
    networks:
    restart:
    env_file:
    ports:
    volumes:
```

Set the frontend's `proxy` with env var instead of hardcoded value

remove the hardcoded value of `proxy` in package.json

the frontend fails to reach the backend in container because
thanks to docker networks the backend exists at
`node-app[-dev]:$NODE_PORT` from the frontend container,
not at `localhost:$NODE_PORT`

add http-proxy-middleware to package.json and create a
./frontend/src/setupProxy.js to configure the proxy
following [react tutorial](https://create-react-app.dev/docs/proxying-api-requests-in-development/#configuring-the-proxy-manually)

PS: the changes in `package-lock.json` seems to come from the fact
that the newly installed package shares dependencies with other
and they ahve different needs over these shared dependencies

Update .env.example

Fix nginx container crash because it can't access to logs folder

git addugit addu I keep these lines commented because I want to add logging withb it #10

Configure MongoDB port through additional flags to pass to mongod in conatiner

Fix non persistent DB by mounting the right volume in the container

Run prettier

Specify read-write permissions on mounted volumes

Remove containers restart option in dev mode

Fix database container (#95)

* Fix non persistent DB by mounting the right volume in the container

* Configure MongoDB port through additional flags to pass to mongod in conatiner

* Run prettier

* Add mongodb folder to gitignore

* Set bitnami/mongodb version tag to latest

pros and cons have been discussed here: #95 (comment)

Improve DB_PORT passing to MongoDB

I just better read the doc https://hub.docker.com/r/bitnami/mongodb/ search for MONGODB_PORT_NUMBER

Write a first version of README about dev mode containerized

Add setup-db-folder.sh script

Update README with DB folder setup and clean it

Add an important waning about mongodb folder permissions to README

Fix setup-db-folder.sh script

Update bitnami mongoDB used image to latest

Remove restart attribute in docker compose dev, useless in dev mode

Update GH Action to exclude mongodb folder from prettier checking

Run prettier

Try a prettier GH Action fix

Armor nginx run script against unexpected MODE value leading to conf template not found

Fix variables wrongly substituted in nginx dev conf and comment logs format

This log_format named 'main' isn't used anyway so it is useless, I keep those lines commented anyway for a later PR where I'll properly set the logging in dev and prod mode

Improve setup database script

* Update docker-compose-dev.yml for a flask backend

* Update backend/Dockerfile.dev to a python image running flask

* Fix FLASK_RUN_PORT env var name

* Update nginx conf to proxy to the flask app

* Fix flaks container not accessible from outside the container

* Update lasting wrong NODE_PORT var in .env.example

Co-authored-by: Alexandre Tullot <[email protected]>

---------

Co-authored-by: Alexandre Tullot <[email protected]>
* Add article logic

Add basis for the article routes
The functions are not implemented yet

* Add user logic

Add basis (functions not implemented) for user routes

* Fix missing id parameter

* Add missing fixme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

3 participants