Draft: Gitlab CI #8
11 changed files with 245 additions and 1 deletions
6
.dockerignore
Normal file
6
.dockerignore
Normal file
|
@ -0,0 +1,6 @@
|
|||
.git/
|
||||
.idea/
|
||||
*.drawio
|
||||
.ruff_cache/
|
||||
*.sqlite3
|
||||
*.db
|
34
.gitlab-ci.yml
Normal file
34
.gitlab-ci.yml
Normal file
|
@ -0,0 +1,34 @@
|
|||
stages:
|
||||
- linting
|
||||
- testing
|
||||
- build
|
||||
- staging
|
||||
- production
|
||||
|
||||
default:
|
||||
image: python:3.12-alpine
|
||||
|
||||
pre_commit:
|
||||
stage: linting
|
||||
script:
|
||||
- apk add git
|
||||
- pip install --root-user-action ignore pre-commit
|
||||
- pre-commit run -a
|
||||
|
||||
build_image:
|
||||
stage: build
|
||||
image: docker
|
||||
services:
|
||||
- docker
|
||||
variables:
|
||||
COMPOSE_FILE: docker-compose.build.yml
|
||||
before_script:
|
||||
- docker login ${CI_REGISTRY} -u gitlab-ci-token -p ${CI_JOB_TOKEN}
|
||||
script:
|
||||
- docker compose build
|
||||
- docker compose push
|
||||
- |
|
||||
if [[ -n "${CI_COMMIT_TAG}" ]]; then
|
||||
docker tag ${CI_REGISTRY_IMAGE}/facturio:${CI_COMMIT_REF_NAME} ${CI_REGISTRY_IMAGE}/facturio:${CI_COMMIT_TAG}
|
||||
docker push ${CI_REGISTRY_IMAGE}/facturio:${CI_COMMIT_TAG}
|
||||
fi
|
74
Dockerfile
Normal file
74
Dockerfile
Normal file
|
@ -0,0 +1,74 @@
|
|||
ARG PYTHON_VERSION=3.12
|
||||
|
||||
FROM python:${PYTHON_VERSION}-alpine AS base
|
||||
|
||||
ENV PYTHONUNBUFFERED=1 \
|
||||
PIP_DISABLE_PIP_VERSION_CHECK=on \
|
||||
POETRY_VIRTUALENVS_CREATE=false \
|
||||
VENV=/root/.venv
|
||||
|
||||
RUN adduser --disabled-password --gecos "" django
|
||||
|
||||
FROM base AS poetry
|
||||
|
||||
ARG POETRY_VERSION=1.8.3
|
||||
|
||||
RUN : \
|
||||
&& python -m venv ${VENV} \
|
||||
&& . ${VENV}/bin/activate \
|
||||
&& pip install poetry==${POETRY_VERSION} \
|
||||
&& apk add gettext shadow \
|
||||
&& apk -v cache clean \
|
||||
&& :
|
||||
|
||||
ENV PATH="${VENV}/bin:${PATH}"
|
||||
|
||||
FROM poetry AS deps
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY pyproject.toml poetry.lock ./
|
||||
|
||||
RUN poetry install --no-interaction --no-ansi -vvv
|
||||
|
||||
COPY scripts/ /usr/local/tmp-bin
|
||||
|
||||
RUN : \
|
||||
&& chmod +x /usr/local/tmp-bin/* \
|
||||
&& mv /usr/local/tmp-bin/* /usr/local/bin \
|
||||
&& rmdir /usr/local/tmp-bin \
|
||||
&& :
|
||||
|
||||
ENTRYPOINT ["entrypoint.sh"]
|
||||
CMD ["run.sh"]
|
||||
|
||||
FROM deps AS development
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ARG GID=1000
|
||||
ARG UID=1000
|
||||
|
||||
RUN : \
|
||||
&& groupmod django -g $GID \
|
||||
&& usermod django -u $UID -g $GID \
|
||||
&& :
|
||||
|
||||
COPY --chown=django . .
|
||||
|
||||
USER django
|
||||
|
||||
CMD ["run-dev.sh"]
|
||||
|
||||
FROM deps AS production
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --chown=django . .
|
||||
|
||||
USER django
|
||||
|
||||
RUN : \
|
||||
&& ./manage.py compilemessages \
|
||||
&& ./manage.py collectstatic --noinput \
|
||||
&& :
|
7
docker-compose.build.yml
Normal file
7
docker-compose.build.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
services:
|
||||
api:
|
||||
image: ${CI_REGISTRY_IMAGE}/facturio:${CI_COMMIT_REF_NAME}
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
target: production
|
14
docker-compose.yml
Normal file
14
docker-compose.yml
Normal file
|
@ -0,0 +1,14 @@
|
|||
services:
|
||||
api:
|
||||
image: facturio
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
GID: ${GID:-1000}
|
||||
UID: ${UID:-1000}
|
||||
target: development
|
||||
ports:
|
||||
- "8000:8000"
|
||||
volumes:
|
||||
- .:/app:Z
|
88
poetry.lock
generated
88
poetry.lock
generated
|
@ -138,6 +138,31 @@ files = [
|
|||
{file = "charset_normalizer-3.3.2-py3-none-any.whl", hash = "sha256:3e4d1f6587322d2788836a99c69062fbb091331ec940e02d12d179c1d53e25fc"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "click"
|
||||
version = "8.1.7"
|
||||
description = "Composable command line interface toolkit"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"},
|
||||
{file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
colorama = {version = "*", markers = "platform_system == \"Windows\""}
|
||||
|
||||
[[package]]
|
||||
name = "colorama"
|
||||
version = "0.4.6"
|
||||
description = "Cross-platform colored terminal text."
|
||||
optional = false
|
||||
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
|
||||
files = [
|
||||
{file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
|
||||
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crispy-bootstrap5"
|
||||
version = "2023.10"
|
||||
|
@ -206,6 +231,38 @@ develop = ["coverage[toml] (>=5.0a4)", "furo (>=2021.8.17b43,<2021.9.dev0)", "py
|
|||
docs = ["furo (>=2021.8.17b43,<2021.9.dev0)", "sphinx (>=3.5.0)", "sphinx-notfound-page"]
|
||||
testing = ["coverage[toml] (>=5.0a4)", "pytest (>=4.6.11)"]
|
||||
|
||||
[[package]]
|
||||
name = "gunicorn"
|
||||
version = "23.0.0"
|
||||
description = "WSGI HTTP Server for UNIX"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "gunicorn-23.0.0-py3-none-any.whl", hash = "sha256:ec400d38950de4dfd418cff8328b2c8faed0edb0d517d3394e457c317908ca4d"},
|
||||
{file = "gunicorn-23.0.0.tar.gz", hash = "sha256:f014447a0101dc57e294f6c18ca6b40227a4c90e9bdb586042628030cba004ec"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
packaging = "*"
|
||||
|
||||
[package.extras]
|
||||
eventlet = ["eventlet (>=0.24.1,!=0.36.0)"]
|
||||
gevent = ["gevent (>=1.4.0)"]
|
||||
setproctitle = ["setproctitle"]
|
||||
testing = ["coverage", "eventlet", "gevent", "pytest", "pytest-cov"]
|
||||
tornado = ["tornado (>=0.2)"]
|
||||
|
||||
[[package]]
|
||||
name = "h11"
|
||||
version = "0.14.0"
|
||||
description = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761"},
|
||||
{file = "h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "3.7"
|
||||
|
@ -217,6 +274,17 @@ files = [
|
|||
{file = "idna-3.7.tar.gz", hash = "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "packaging"
|
||||
version = "24.1"
|
||||
description = "Core utilities for Python packages"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "packaging-24.1-py3-none-any.whl", hash = "sha256:5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124"},
|
||||
{file = "packaging-24.1.tar.gz", hash = "sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "requests"
|
||||
version = "2.32.3"
|
||||
|
@ -281,7 +349,25 @@ h2 = ["h2 (>=4,<5)"]
|
|||
socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"]
|
||||
zstd = ["zstandard (>=0.18.0)"]
|
||||
|
||||
[[package]]
|
||||
name = "uvicorn"
|
||||
version = "0.30.6"
|
||||
description = "The lightning-fast ASGI server."
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "uvicorn-0.30.6-py3-none-any.whl", hash = "sha256:65fd46fe3fda5bdc1b03b94eb634923ff18cd35b2f084813ea79d1f103f711b5"},
|
||||
{file = "uvicorn-0.30.6.tar.gz", hash = "sha256:4b15decdda1e72be08209e860a1e10e92439ad5b97cf44cc945fcbee66fc5788"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
click = ">=7.0"
|
||||
h11 = ">=0.8"
|
||||
|
||||
[package.extras]
|
||||
standard = ["colorama (>=0.4)", "httptools (>=0.5.0)", "python-dotenv (>=0.13)", "pyyaml (>=5.1)", "uvloop (>=0.14.0,!=0.15.0,!=0.15.1)", "watchfiles (>=0.13)", "websockets (>=10.4)"]
|
||||
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.12"
|
||||
content-hash = "fc91f96209fbdf439cf9da459e6b98e3897b9672d0250bc97a7622a190006ff4"
|
||||
content-hash = "b23715e240b100e65d717f81ec69f1f9fa5ef542cdba6e3c97841789625bc13b"
|
||||
|
|
|
@ -5,6 +5,7 @@ description = ""
|
|||
authors = ["Jakub Kropáček <kropikuba@gmail.com>"]
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
package-mode = false
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.12"
|
||||
|
@ -13,6 +14,8 @@ crispy-bootstrap5 = "^2023.10"
|
|||
django-crispy-forms = "^2.1"
|
||||
ares-util = "^0.3.0"
|
||||
django-environ = "^0.11.2"
|
||||
gunicorn = "^23.0.0"
|
||||
uvicorn = "^0.30.6"
|
||||
|
||||
|
||||
[build-system]
|
||||
|
|
5
scripts/entrypoint.sh
Normal file
5
scripts/entrypoint.sh
Normal file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
#wait-for-it --service db:5432 -- echo "database is running"
|
||||
|
||||
exec "$@"
|
4
scripts/run-dev.sh
Normal file
4
scripts/run-dev.sh
Normal file
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
|
||||
./manage.py migrate
|
||||
./manage.py runserver 0.0.0.0:8000
|
11
scripts/run.sh
Normal file
11
scripts/run.sh
Normal file
|
@ -0,0 +1,11 @@
|
|||
#/bin/sh
|
||||
|
||||
echo "Migrating..."
|
||||
./manage.py migrate >/dev/null
|
||||
|
||||
|
||||
gunicorn \
|
||||
--threads 2 \
|
||||
--workers 4 \
|
||||
--worker-class uvicorn.workers.UvicornWorker \
|
||||
facturio.asgi
|
Reference in a new issue