update to python3.12

This commit is contained in:
Aarni Halinen
2025-02-09 19:47:10 +02:00
parent 8fc3ee534d
commit f0a5b6e8e7
8 changed files with 1151 additions and 944 deletions
+165 -165
View File
@@ -1,188 +1,188 @@
stages: stages:
- setup - setup
- audit - audit
- lint - lint
- test - test
- publish - publish
- deploy - deploy
- cleanup - cleanup
install: install:
image: node:14 image: node:14
stage: setup stage: setup
only: only:
- pushes - pushes
script: script:
- npm ci - npm ci
artifacts: artifacts:
paths: paths:
- node_modules - node_modules
expire_in: 1 week expire_in: 1 week
audit: audit:
image: python:3.9 image: python:3.12.9
stage: audit stage: audit
only: only:
- pushes - pushes
needs: [] needs: []
before_script: before_script:
- pip install poetry==1.3.1 - pip install poetry==2.0.1
- poetry config virtualenvs.create false - poetry config virtualenvs.create false
- poetry install --no-interaction --no-ansi - poetry install --no-interaction --no-ansi
script: script:
- safety check - safety check
test: test:
image: python:3.9 image: python:3.12.9
stage: test stage: test
only: only:
- pushes - pushes
needs: [] needs: []
services: services:
- postgres:12 - postgres:12
variables: variables:
POSTGRES_DB: ci POSTGRES_DB: ci
POSTGRES_USER: postgres POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres POSTGRES_PASSWORD: postgres
DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB" DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB"
DB_HOST: postgres DB_HOST: postgres
before_script: before_script:
- pip install poetry==1.3.1 - pip install poetry==2.0.1
- poetry config virtualenvs.create false - poetry config virtualenvs.create false
- poetry install --no-interaction --no-ansi - poetry install --no-interaction --no-ansi
script: script:
- python manage.py migrate --noinput - python manage.py migrate --noinput
- python manage.py createdefaultadmin - python manage.py createdefaultadmin
- python manage.py test - python manage.py test
lint:py: lint:py:
image: python:3.9 image: python:3.12.9
stage: lint stage: lint
only: only:
- pushes - pushes
needs: [] needs: []
script: script:
- pip install black==22.3.0 - pip install black==22.3.0
- black --check . - black --check .
lint:js: lint:js:
image: node:14 image: node:14
stage: lint stage: lint
only: only:
- pushes - pushes
needs: ["install"] needs: ["install"]
script: script:
- npm run lint:js - npm run lint:js
lint:md: lint:md:
image: node:14 image: node:14
stage: lint stage: lint
only: only:
- pushes - pushes
needs: ["install"] needs: ["install"]
script: script:
- npm run lint:md - npm run lint:md
publish: publish:
image: docker:25-cli image: docker:25-cli
stage: publish stage: publish
needs: ["test", "lint:py", "lint:js", "lint:md"] needs: ["test", "lint:py", "lint:js", "lint:md"]
services: services:
- docker:25-dind - docker:25-dind
only: only:
- develop - develop
- master - master
script: script:
- docker info - docker info
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker build . -t "$IMAGE_NAME" - docker build . -t "$IMAGE_NAME"
- docker push "$IMAGE_NAME" - docker push "$IMAGE_NAME"
deploy:dev: deploy:dev:
image: docker:25-cli image: docker:25-cli
stage: deploy stage: deploy
only: only:
- develop - develop
environment: environment:
name: dev name: dev
url: http://api.dev.sahkoinsinoorikilta.fi url: http://api.dev.sahkoinsinoorikilta.fi
variables: variables:
DOCKER_HOST: $DEV_CI_DOCKER_HOST DOCKER_HOST: $DEV_CI_DOCKER_HOST
DOCKER_TLS_VERIFY: 1 DOCKER_TLS_VERIFY: 1
before_script: before_script:
- mkdir -p ~/.docker - mkdir -p ~/.docker
- echo "$DEV_TLSCACERT" > ~/.docker/ca.pem - echo "$DEV_TLSCACERT" > ~/.docker/ca.pem
- echo "$DEV_TLSCERT" > ~/.docker/cert.pem - echo "$DEV_TLSCERT" > ~/.docker/cert.pem
- echo "$DEV_TLSKEY" > ~/.docker/key.pem - echo "$DEV_TLSKEY" > ~/.docker/key.pem
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
script: script:
- docker stack deploy --with-registry-auth -c stack-compose-dev.yml "$SERVICE_NAME" - docker stack deploy --with-registry-auth -c stack-compose-dev.yml "$SERVICE_NAME"
after_script: after_script:
- docker logout "$CI_REGISTRY" - docker logout "$CI_REGISTRY"
deploy:production: deploy:production:
stage: deploy stage: deploy
image: docker:25-cli image: docker:25-cli
only: only:
- master - master
environment: environment:
name: production name: production
url: https://api.sahkoinsinoorikilta.fi url: https://api.sahkoinsinoorikilta.fi
when: manual when: manual
variables: variables:
DOCKER_HOST: $CI_DOCKER_HOST DOCKER_HOST: $CI_DOCKER_HOST
DOCKER_TLS_VERIFY: 1 DOCKER_TLS_VERIFY: 1
before_script: before_script:
- mkdir -p ~/.docker - mkdir -p ~/.docker
- echo "$TLSCACERT" > ~/.docker/ca.pem - echo "$TLSCACERT" > ~/.docker/ca.pem
- echo "$TLSCERT" > ~/.docker/cert.pem - echo "$TLSCERT" > ~/.docker/cert.pem
- echo "$TLSKEY" > ~/.docker/key.pem - echo "$TLSKEY" > ~/.docker/key.pem
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
script: script:
- docker stack deploy --with-registry-auth -c stack-compose.yml "$SERVICE_NAME" - docker stack deploy --with-registry-auth -c stack-compose.yml "$SERVICE_NAME"
after_script: after_script:
- docker logout "$CI_REGISTRY" - docker logout "$CI_REGISTRY"
docker_prune:dev: docker_prune:dev:
image: docker:stable image: docker:stable
stage: cleanup stage: cleanup
only: only:
- schedules - schedules
environment: environment:
name: dev name: dev
url: http://api.dev.sahkoinsinoorikilta.fi url: http://api.dev.sahkoinsinoorikilta.fi
variables: variables:
DOCKER_HOST: $DEV_CI_DOCKER_HOST DOCKER_HOST: $DEV_CI_DOCKER_HOST
DOCKER_TLS_VERIFY: 1 DOCKER_TLS_VERIFY: 1
before_script: before_script:
- mkdir -p ~/.docker - mkdir -p ~/.docker
- echo "$DEV_TLSCACERT" > ~/.docker/ca.pem - echo "$DEV_TLSCACERT" > ~/.docker/ca.pem
- echo "$DEV_TLSCERT" > ~/.docker/cert.pem - echo "$DEV_TLSCERT" > ~/.docker/cert.pem
- echo "$DEV_TLSKEY" > ~/.docker/key.pem - echo "$DEV_TLSKEY" > ~/.docker/key.pem
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
script: script:
- docker system prune - docker system prune
after_script: after_script:
- docker logout "$CI_REGISTRY" - docker logout "$CI_REGISTRY"
docker_prune:prod: docker_prune:prod:
image: docker:stable image: docker:stable
stage: cleanup stage: cleanup
only: only:
- schedules - schedules
environment: environment:
name: production name: production
url: https://api.sahkoinsinoorikilta.fi url: https://api.sahkoinsinoorikilta.fi
variables: variables:
DOCKER_HOST: $CI_DOCKER_HOST DOCKER_HOST: $CI_DOCKER_HOST
DOCKER_TLS_VERIFY: 1 DOCKER_TLS_VERIFY: 1
before_script: before_script:
- mkdir -p ~/.docker - mkdir -p ~/.docker
- echo "$TLSCACERT" > ~/.docker/ca.pem - echo "$TLSCACERT" > ~/.docker/ca.pem
- echo "$TLSCERT" > ~/.docker/cert.pem - echo "$TLSCERT" > ~/.docker/cert.pem
- echo "$TLSKEY" > ~/.docker/key.pem - echo "$TLSKEY" > ~/.docker/key.pem
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
script: script:
- docker system prune - docker system prune
after_script: after_script:
- docker logout "$CI_REGISTRY" - docker logout "$CI_REGISTRY"
+1
View File
@@ -0,0 +1 @@
20.15.0
+1 -1
View File
@@ -1 +1 @@
3.9 3.12.9
+4 -3
View File
@@ -1,13 +1,14 @@
FROM python:3.9-slim-buster AS builder FROM python:3.12.9-slim-bullseye AS builder
ENV PYTHONUNBUFFERED 1 ENV PYTHONUNBUFFERED 1
COPY . ./ COPY . ./
ENV POETRY_VERSION=1.3.1 ENV POETRY_VERSION=2.0.1
RUN pip install "poetry==$POETRY_VERSION" RUN pip install "poetry==$POETRY_VERSION"
RUN poetry self add poetry-plugin-export
RUN poetry export --without-hashes > requirements.txt RUN poetry export --without-hashes > requirements.txt
FROM python:3.9-slim-buster AS server FROM python:3.12.9-slim-bullseye AS server
WORKDIR /app WORKDIR /app
COPY . ./ COPY . ./
+3 -3
View File
@@ -31,13 +31,13 @@ For depedencies and virtual environment, we use [poetry](https://python-poetry.o
First install [python](https://wiki.python.org/moin/BeginnersGuide/Download). Then install poetry: First install [python](https://wiki.python.org/moin/BeginnersGuide/Download). Then install poetry:
```bash ```bash
python3 -m pip install poetry==1.3.1 python -m pip install poetry==2.0.1
``` ```
The easiest integration with VSCode is to have poetry install virtual environment in project folder, configured with CMD The easiest integration with VSCode is to have poetry install virtual environment in project folder, configured with CMD
```bash ```bash
python3 -m poetry config virtualenvs.in-project true python -m poetry config virtualenvs.in-project true
``` ```
### Node ### Node
@@ -65,7 +65,7 @@ docker run --name sik.web.db -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postg
Activate virtual environment in shell Activate virtual environment in shell
```bash ```bash
python3 -m poetry shell eval $(python -m poetry env activate)
``` ```
Install dependencies Install dependencies
Generated
+961 -767
View File
File diff suppressed because it is too large Load Diff
+15 -4
View File
@@ -1,11 +1,22 @@
[tool.poetry] [project]
name = "web2.0-backend" name = "web2.0-backend"
version = "0.1.0" version = "0.1.0"
description = "Backend for sahkoinsinoorikilta.fi" description = "Backend for sahkoinsinoorikilta.fi"
authors = ["Aarni Halinen aarni.halinen@sahkoinsinoorikilta.fi"] authors = [
{ name="Aarni Halinen", email="aarni.halinen@sahkoinsinoorikilta.fi"}
]
readme = "README.md"
requires-python = ">=3.12"
[tool.poetry]
package-mode = false
[tool.poetry.requires-plugins]
poetry-plugin-export = "^1.9"
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^3.9" python = "^3.12"
decorator = "^4.0.9" decorator = "^4.0.9"
Django = "^4.1" Django = "^4.1"
requests = "^2.28.1" requests = "^2.28.1"
@@ -28,7 +39,7 @@ django-filter = "^22.1"
whitenoise = "^6.2.0" whitenoise = "^6.2.0"
jsonschema = "^4.9.0" jsonschema = "^4.9.0"
Markdown = "^3.2.2" Markdown = "^3.2.2"
uWSGI = "^2.0.18" uWSGI = "^2.0.28"
gunicorn = "^20.1.0" gunicorn = "^20.1.0"
Pillow = "^10.0.0" Pillow = "^10.0.0"
sendgrid = "^6.7.0" sendgrid = "^6.7.0"
+1 -1
View File
@@ -12,5 +12,5 @@
"reportMissingImports": true, "reportMissingImports": true,
"reportMissingTypeStubs": false, "reportMissingTypeStubs": false,
"pythonVersion": "3.9" "pythonVersion": "3.12.9"
} }