Skip to content

Commit

Permalink
Changes to Project structure (#4269)
Browse files Browse the repository at this point in the history
* structure

* fix docker compose

* Changes to project structure and Docker image building
- Project installs as packaget on dist image
- Rebuild dockerfile structure
- removed unused file
- addjusted entrypoint and manage.py

* fix code style

* selenium test fixes

* changed settings

---------

Co-authored-by: Domenico DiNicola <[email protected]>
  • Loading branch information
johniak and domdinicola authored Oct 1, 2024
1 parent 8c8b1f7 commit a3a8739
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 109 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions .github/helpers/docker-compose.selenium.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
- ../src/report/:/code/report/
- type: volume
source: backend-web-app
target: /code/hct_mis_api/apps/web
target: /code/src/hct_mis_api/apps/web
volume:
nocopy: false
depends_on:
Expand All @@ -31,7 +31,7 @@ services:
- backend-web-app:/tmp/
command: |
sh -c "
cp -r ./hct_mis_api/apps/web/* /tmp/
cp -r /packages/__pypackages__/3.11/lib/hct_mis_api/apps/web/* /tmp/
"
restart: "no"

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ ENV/
env.bak/
venv.bak/

.pdm-python

# Spyder project settings
.spyderproject
.spyproject
Expand Down
9 changes: 6 additions & 3 deletions development_tools/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ services:
ports:
- "8080:8000"
volumes:
- ../src:/code/
- ../src:/code/src/
- ../manage.py:/code/manage.py
- ../pyproject.toml:/code/pyproject.toml
- ../pdm.lock:/code/pdm.lock
- ../tests:/tests/
- backend-data:/data
- ../src/pyproject.toml:/packages/pyproject.toml
- ../src/pdm.lock:/packages/pdm.lock
- ../pyproject.toml:/packages/pyproject.toml
- ../pdm.lock:/packages/pdm.lock
- ipython_data_local:/root/.ipython
command: "dev"
depends_on:
Expand Down
54 changes: 28 additions & 26 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ RUN apt-get update \

ENV PDM_PACKAGES=/packages
ENV CODE=/code
ENV PDM_NO_SELF=True
ENV PDM_PROJECT=$PDM_PACKAGES
ENV PYPACKAGES=$PDM_PACKAGES/__pypackages__/3.11
ENV PYTHONPYCACHEPREFIX=/tmp/pycache \
PYTHONPATH=$PYPACKAGES/lib:$CODE:$PYTHONPATH \
PYTHONPATH=$PYPACKAGES/lib:$PYTHONPATH \
PATH=$PYPACKAGES/bin:$PATH \
XDG_RUNTIME_DIR=/run/user/"${UID}"

Expand All @@ -54,22 +53,22 @@ WORKDIR $CODE
COPY --from=waitforit /data/waitforit /usr/local/bin/waitforit

# Dist builder image
FROM base as builder

FROM base as pdm
RUN pip install --upgrade pip &&\
pip install pdm==2.15.2 &&\
pip install setuptools==71.1.0 &&\
pdm config cache_dir /var/cache/pdm &&\
pdm config python.use_venv false &&\
pdm config venv.in_project true &&\
pdm config check_update false

WORKDIR $PDM_PACKAGES
COPY src/pyproject.toml src/pdm.lock ./
RUN pdm sync --prod --no-editable --no-self --no-isolation
COPY README.md LICENSE pyproject.toml pdm.lock ./




# Dev image
FROM builder AS dev
FROM pdm AS dev

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
Expand All @@ -83,26 +82,14 @@ RUN apt-get update \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

ENV PYTHONPATH=$CODE/src:/test/:$PYTHONPATH
RUN pdm sync --no-editable --no-self --no-isolation

WORKDIR $CODE
COPY ./src/ ./
COPY ./src/ ./src/
COPY ./tests /tests



COPY ./docker/entrypoint.sh /bin/
ENTRYPOINT ["entrypoint.sh"]

## Dist (backend only) image
FROM base AS be-dist

COPY ./src/ ./
COPY --chown=hope:hope --from=builder $PDM_PACKAGES $PDM_PACKAGES
COPY --chown=hope:hope --from=certs /data/psql-cert.crt /code/psql-cert.crt

USER hope

COPY ./manage.py ./manage.py
COPY .flake8 pyproject.toml pdm.lock ./
COPY ./docker/entrypoint.sh /bin/
ENTRYPOINT ["entrypoint.sh"]

Expand All @@ -117,7 +104,22 @@ RUN yarn install --frozen-lockfile --network-timeout 600000
COPY ./src/frontend ./
RUN NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=4096" yarn build

# Dist builder image
FROM pdm as dist-builder
COPY ./src/ ./src/
COPY --chown=hope:hope --from=frontend-builder /fe-build/build $PDM_PACKAGES/src/hct_mis_api/apps/web/static/web
RUN pdm sync --prod --no-editable --no-isolation


## Dist (backend only) image
FROM base AS dist


COPY ./src/gunicorn_config.py /conf/gunicorn_config.py
COPY --chown=hope:hope --from=dist-builder $PDM_PACKAGES $PDM_PACKAGES
COPY --chown=hope:hope --from=certs /data/psql-cert.crt /certs/psql-cert.crt

FROM be-dist AS dist
USER hope

COPY --chown=hope:hope --from=frontend-builder /fe-build/build ./hct_mis_api/apps/web/static/web
COPY ./docker/entrypoint.sh /bin/
ENTRYPOINT ["entrypoint.sh"]
2 changes: 1 addition & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ wait_for_db() {
}

if [ $# -eq 0 ]; then
exec gunicorn hct_mis_api.wsgi -c /code/gunicorn_config.py
exec gunicorn hct_mis_api.wsgi -c /conf/gunicorn_config.py
else
case "$1" in
"dev")
Expand Down
File renamed without changes.
Loading

0 comments on commit a3a8739

Please sign in to comment.