From 0fa1560e7faa61e262c3e0efddac2b8f89e6e29c Mon Sep 17 00:00:00 2001 From: Tudor Amariei Date: Wed, 27 Dec 2023 10:17:57 +0200 Subject: [PATCH 1/2] Update the dockerfile to work for the prod config --- Makefile | 2 +- backend/requirements-dev.txt | 20 ++++++++++++++++++++ backend/requirements.in | 7 +++++++ backend/requirements.txt | 17 +++++++++++++++++ docker/dockerfiles/Dockerfile | 12 ++++++------ 5 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 06b8ece1..e752ee23 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ upd-sqlite: ## run the project with sqlite in detached mod docker compose --profile sqlite3 up -d --build up-mysql: ## run the project with mysql - docker compose --profile mysql up --build + docker compose --profile mysql up --build`` upd-mysql: ## run the project with mysql in detached mode docker compose --profile mysql up -d --build diff --git a/backend/requirements-dev.txt b/backend/requirements-dev.txt index d58e52d1..1c8ae564 100644 --- a/backend/requirements-dev.txt +++ b/backend/requirements-dev.txt @@ -53,6 +53,14 @@ frozenlist==1.4.1 # via # aiohttp # aiosignal +gevent==23.9.1 + # via -r requirements.txt +greenlet==3.0.3 + # via + # -r requirements.txt + # gevent +gunicorn==21.2.0 + # via -r requirements.txt idna==3.6 # via yarl jinja2==3.1.2 @@ -69,8 +77,10 @@ mypy-extensions==1.0.0 # via black packaging==23.2 # via + # -r requirements.txt # black # build + # gunicorn pathspec==0.12.1 # via black pip-tools==7.3.0 @@ -124,8 +134,18 @@ wcwidth==0.2.12 # blessed wheel==0.42.0 # via pip-tools +whitenoise==6.6.0 + # via -r requirements.txt yarl==1.9.4 # via aiohttp +zope-event==5.0 + # via + # -r requirements.txt + # gevent +zope-interface==6.1 + # via + # -r requirements.txt + # gevent # The following packages are considered to be unsafe in a requirements file: # pip diff --git a/backend/requirements.in b/backend/requirements.in index 1fa9a0fd..4a113d08 100644 --- a/backend/requirements.in +++ b/backend/requirements.in @@ -19,3 +19,10 @@ jinja2~=3.1.2 # GeoIP support python-geoip-geolite2==2015.303 + +# web server +gevent~=23.9.1 +gunicorn~=21.2.0 + +# file storage +whitenoise~=6.6.0 diff --git a/backend/requirements.txt b/backend/requirements.txt index 409fa34f..3df2f0fc 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -28,10 +28,18 @@ django-picklefield==3.1 # via django-q2 django-q2==1.6.1 # via -r requirements.in +gevent==23.9.1 + # via -r requirements.in +greenlet==3.0.3 + # via gevent +gunicorn==21.2.0 + # via -r requirements.in jinja2==3.1.2 # via -r requirements.in markupsafe==2.1.3 # via jinja2 +packaging==23.2 + # via gunicorn psutil==5.9.7 # via -r requirements.in pycparser==2.21 @@ -60,3 +68,12 @@ urllib3==2.1.0 # via sentry-sdk wcwidth==0.2.12 # via blessed +whitenoise==6.6.0 + # via -r requirements.in +zope-event==5.0 + # via gevent +zope-interface==6.1 + # via gevent + +# The following packages are considered to be unsafe in a requirements file: +# setuptools diff --git a/docker/dockerfiles/Dockerfile b/docker/dockerfiles/Dockerfile index 9920470d..63dd0dd0 100644 --- a/docker/dockerfiles/Dockerfile +++ b/docker/dockerfiles/Dockerfile @@ -1,12 +1,11 @@ FROM node:18.17.1-bookworm-slim as frontend -WORKDIR /var/www/redirect/frontend - -COPY ./frontend/ . +WORKDIR /var/www/redirect/build +COPY ./backend/ . # install the frontend libraries: -RUN npm ci --no-audit --ignore-scripts && \ - npm run prod +RUN npm install -g npm bower && \ + bower install --allow-root --config.interactive=false FROM python:3.11.7-slim-bookworm as backend @@ -25,6 +24,7 @@ ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" WORKDIR /build COPY ./backend/requirements.txt . + RUN python3 -m pip install --upgrade pip setuptools && \ python3 -m pip install -r ./requirements.txt @@ -74,7 +74,7 @@ ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" COPY --from=backend "${VIRTUAL_ENV}" "${VIRTUAL_ENV}" COPY ./backend/ /var/www/redirect/backend/ -COPY --from=frontend /var/www/redirect/frontend/dist/ /var/www/redirect/frontend/dist/ +COPY --from=frontend /var/www/redirect/build/bower_components/ /var/www/redirect/backend/bower_components/ # activate the virtualenv: RUN . "${VIRTUAL_ENV}/bin/activate" From d25eee5e06aa74f4cc430b3528b3f502fa93e6e5 Mon Sep 17 00:00:00 2001 From: Tudor Amariei Date: Wed, 27 Dec 2023 10:18:06 +0200 Subject: [PATCH 2/2] Add a build image workflow --- .github/workflows/build-image.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/build-image.yml diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml new file mode 100644 index 00000000..b0b0df6b --- /dev/null +++ b/.github/workflows/build-image.yml @@ -0,0 +1,20 @@ +name: Build and push image to registry + +on: + push: + branches: + - main + tags: + - v* + +jobs: + build: + uses: code4romania/.github/.github/workflows/build-push-image.yml@main + with: + images: ghcr.io/code4romania/redirectioneaza + registry: ghcr.io + context: ./ + dockerfile: ./docker/dockerfiles/Dockerfile + secrets: + username: ${{ github.actor }} + token: ${{ secrets.GITHUB_TOKEN }}