Drop Python, more efficient dev container build, doutd

This commit is contained in:
Sandra Modzelewska 2025-01-25 07:25:12 +00:00
parent 2f17b84449
commit 6adea0efbb
No known key found for this signature in database
21 changed files with 150 additions and 318 deletions

View File

@ -0,0 +1,51 @@
{
"name": "Kredens Dev Container",
"build": {
"dockerfile": "../../dockerfiles/devcontainer.dockerfile",
"context": "../.."
},
"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker": {
"installDockerComposeSwitch": false
},
"ghcr.io/devcontainers/features/node:1": {
"nodeGypDependencies": true,
"installYarnUsingApt": true,
"version": "lts",
"pnpmVersion": "latest",
"nvmVersion": "latest"
}
},
"onCreateCommand": "onCreate.sh",
"postAttachCommand": "postAttach.sh",
"remoteEnv": {
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}",
"WORKSPACE_FOLDER": "${containerWorkspaceFolder}",
"UV_LINK_MODE": "copy"
},
"mounts": [
{
"type": "volume",
"source": "${devcontainerId}-venv",
"target": "${containerWorkspaceFolder}/.venv"
},
{
"type": "volume",
"source": "${devcontainerId}-node-modules",
"target": "${containerWorkspaceFolder}/node_modules"
},
{
"type": "volume",
"source": "${devcontainerId}-bashhistory",
"target": "/commandhistory"
}
],
"customizations": {
"vscode": {
"extensions": [
"ms-azuretools.vscode-docker"
]
}
}
}

77
.devcontainer/devcontainer.json Executable file → Normal file
View File

@ -1,76 +1,3 @@
{
"name": "Kredens Dev Container",
"build": {
"dockerfile": "../dockerfiles/devcontainer.dockerfile",
"context": ".."
},
"forwardPorts": [
80, 443, 2019
],
"portsAttributes": {
"80": {
"label": "Plaintext",
"protocol": "http",
"elevateIfNeeded": true
},
"443": {
"label": "Encrypted",
"protocol": "https",
"elevateIfNeeded": true
},
"2019": {
"label": "Admin API",
"protocol": "http",
}
},
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"installDockerComposeSwitch": false
},
"ghcr.io/devcontainers/features/node:1": {
"nodeGypDependencies": true,
"installYarnUsingApt": true,
"version": "lts",
"pnpmVersion": "latest",
"nvmVersion": "latest"
},
"ghcr.io/va-h/devcontainers-features/uv:1": {
"shellautocompletion": true,
"version": "latest"
}
},
"onCreateCommand": "${containerWorkspaceFolder}/.devcontainer/onCreate.sh",
"postAttachCommand": "${containerWorkspaceFolder}/.devcontainer/postAttach.sh",
"remoteEnv": {
"WORKSPACE_FOLDER": "${containerWorkspaceFolder}",
"UV_LINK_MODE": "copy"
},
"mounts": [
{
"type": "volume",
"source": "${devcontainerId}-venv",
"target": "${containerWorkspaceFolder}/.venv"
},
{
"type": "volume",
"source": "${devcontainerId}-node-modules",
"target": "${containerWorkspaceFolder}/node_modules"
},
{
"type": "volume",
"source": "${devcontainerId}-bashhistory",
"target": "/commandhistory"
}
],
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.debugpy",
"ms-azuretools.vscode-docker"
]
}
}
}
"image": "fullspectrumconfidence.modzero.xyz/modzero/kredens-devcontainer"
}

View File

@ -1,25 +0,0 @@
#!/bin/bash
sudo apt update -y
sudo apt upgrade -y
sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
sudo apt upgrade -y
sudo apt install -y postgresql-client
git config --global --add safe.directory ${WORKSPACE_FOLDER}
sudo chown $(id -u):$(id -g) -fR \
${WORKSPACE_FOLDER} \
${WORKSPACE_FOLDER}/.venv \
${WORKSPACE_FOLDER}/node_modules \
/commandhistory
cd ${WORKSPACE_FOLDER}
uv python install
uv venv --allow-existing
uv tool install rust-just
uv tool install ruff

View File

@ -1,4 +1,3 @@
.git
node_modules
.venv
__pycache__
.pnpm-store

3
.gitignore vendored
View File

@ -1,4 +1,3 @@
.venv
.env
node_modules
__pycache__
.pnpm-store

View File

@ -1 +0,0 @@
3.13

View File

@ -7,7 +7,9 @@ Where I keep my spoons.
Create a .env file:
```sh
DATABASE_PASSWORD=TOTALMESSREPLACE
DATABASE_URL=postgres://postgres:${DATABASE_PASSWORD}@host.docker.internal/kredens
SUPERUSER_EMAIL=bla@example.com
SUPERUSER_PASSWORD=OHNONONO
```
Then, to start the thing:

View File

@ -1,25 +1,4 @@
services:
backend:
image: modzero.xyz/kredens/backend
build:
dockerfile: dockerfiles/backend.dockerfile
context: .
pull_policy: build
develop:
watch:
- path: ./kredens
action: sync
target: /app/kredens
- path: ./pyproject.toml
action: rebuild
- path: ./manage.py
action: rebuild
- path: ./uv.lock
action: rebuild
environment:
- DATABASE_URL=postgres://postgres:${DATABASE_PASSWORD:?Database password required}@database/kredens
depends_on:
- database
database:
image: postgres:17
restart: unless-stopped
@ -43,7 +22,7 @@ services:
cap_add:
- NET_ADMIN
volumes:
- ./configs/caddy/:/etc/caddy/
- ${LOCAL_WORKSPACE_FOLDER:-./}configs/caddy/:/etc/caddy/
- caddy_data:/data
- caddy_config:/config
ports:

View File

@ -0,0 +1,21 @@
#!/bin/bash
git config --global --add safe.directory ${WORKSPACE_FOLDER}
sudo chown $(id -u):$(id -g) -fR \
${WORKSPACE_FOLDER} \
${WORKSPACE_FOLDER}/.venv \
${WORKSPACE_FOLDER}/node_modules \
/commandhistory
cd ${WORKSPACE_FOLDER}
if [ ! -f .env ]; then
DATABASE_PASSWORD=$(pwgen 16 1)
SUPERUSER_PASSWORD=$(pwgen 8 1)
cat << EOF > .env
DATABASE_PASSWORD=${DATABASE_PASSWORD}
SUPERUSER_EMAIL=super@example.org
SUPERUSER_PASSWORD=${SUPERUSER_PASSWORD}
EOF
fi

View File

@ -4,5 +4,3 @@ sudo apt update -y
sudo apt upgrade -y
cd ${WORKSPACE_FOLDER}
uv sync --frozen

View File

@ -1,21 +0,0 @@
FROM python:3.12-slim-bookworm
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
WORKDIR /app
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project
COPY ./kredens/ /app/kredens
COPY \
manage.py \
pyproject.toml \
uv.lock \
/app/
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen
ENTRYPOINT [ "uv", "run", "python", "./manage.py" ]
CMD [ "runserver", "0.0.0.0:8000"]

View File

@ -12,28 +12,50 @@ RUN \
/etc/apt/apt.conf.d/docker-no-languages \
&& apt-get update -y && apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
debian-keyring \
debian-archive-keyring \
apt-transport-https \
gnupg
debian-archive-keyring \
debian-keyring \
gnupg \
postgresql-common \
pwgen
RUN --mount=type=bind,target=/tmp/caddy.key,source=./configs/keys/caddy.key \
# Add Caddy repo
RUN --mount=type=bind,target=/tmp/caddy.key,source=./dockerfiles/assets/keys/caddy.key \
gpg -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg --dearmor /tmp/caddy.key
COPY ./configs/apt/sources.list.d/caddy-stable.list /etc/apt/sources.list
COPY ./dockerfiles/assets/apt-sources/caddy-stable.list /etc/apt/sources.list
# Add Postgresql repo
RUN /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
RUN \
--mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update -y \
apt-get update -y && apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
caddy
caddy \
postgresql-client
RUN mkdir -p /workspaces/kredens && chown vscode:vscode /workspaces
WORKDIR /workspaces/kredens
# Persist history
RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhistory/.bash_history" \
RUN \
SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhistory/.bash_history" \
&& mkdir /commandhistory \
&& touch /commandhistory/.bash_history \
&& chown -R $USERNAME /commandhistory \
&& echo "$SNIPPET" >> "/home/$USERNAME/.bashrc"
&& echo "$SNIPPET" >> "/home/$USERNAME/.bashrc"
RUN \
mkdir -p /home/${USERNAME}/.local/bin/ \
&& chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}/.local/
COPY --chown=${USERNAME}:${USERNAME} \
dockerfiles/assets/scripts/onCreate.sh \
dockerfiles/assets/scripts/postAttach.sh \
/home/${USERNAME}/.local/bin/
USER ${USERNAME}

View File

@ -1,8 +0,0 @@
watch:
docker compose up --watch
migrate:
uv run ./manage.py migrate
bootstrap:
uv run ./manage.py bootstrap

View File

@ -1,22 +0,0 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'kredens.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

15
package.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "kredens",
"version": "1.0.0",
"description": "",
"scripts": {
"devContainerBuild": "devcontainer build --config .devcontainer/build/devcontainer.json --workspace-folder . --image-name fullspectrumconfidence.modzero.xyz/modzero/kredens-devcontainer",
"devContainerBuildAndPush": "npm run devContainerBuild -- --push"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@devcontainers/cli": "^0.72.0"
}
}

24
pnpm-lock.yaml generated Normal file
View File

@ -0,0 +1,24 @@
lockfileVersion: '9.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
importers:
.:
devDependencies:
'@devcontainers/cli':
specifier: ^0.72.0
version: 0.72.0
packages:
'@devcontainers/cli@0.72.0':
resolution: {integrity: sha512-vDv33/I5POw1wDJmcMbOCTWd3xTk4bbVruJ9Qgr5eiLSl1OsfufN5WfeTZqgK1HeqrNqtH/xPyCKB2LXDNIv3w==}
engines: {node: ^16.13.0 || >=18.0.0}
hasBin: true
snapshots:
'@devcontainers/cli@0.72.0': {}

View File

@ -1,11 +0,0 @@
[project]
name = "kredens"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"dj-database-url>=2.3.0",
"django>=5.1.5",
"psycopg[binary]>=3.2.4",
]

117
uv.lock generated
View File

@ -1,117 +0,0 @@
version = 1
requires-python = ">=3.13"
[[package]]
name = "asgiref"
version = "3.8.1"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/29/38/b3395cc9ad1b56d2ddac9970bc8f4141312dbaec28bc7c218b0dfafd0f42/asgiref-3.8.1.tar.gz", hash = "sha256:c343bd80a0bec947a9860adb4c432ffa7db769836c64238fc34bdc3fec84d590", size = 35186 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/39/e3/893e8757be2612e6c266d9bb58ad2e3651524b5b40cf56761e985a28b13e/asgiref-3.8.1-py3-none-any.whl", hash = "sha256:3e1e3ecc849832fe52ccf2cb6686b7a55f82bb1d6aee72a58826471390335e47", size = 23828 },
]
[[package]]
name = "dj-database-url"
version = "2.3.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "django" },
{ name = "typing-extensions" },
]
sdist = { url = "https://files.pythonhosted.org/packages/98/9f/fc9905758256af4f68a55da94ab78a13e7775074edfdcaddd757d4921686/dj_database_url-2.3.0.tar.gz", hash = "sha256:ae52e8e634186b57e5a45e445da5dc407a819c2ceed8a53d1fac004cc5288787", size = 10980 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/e5/91/641a4e5c8903ed59f6cbcce571003bba9c5d2f731759c31db0ba83bb0bdb/dj_database_url-2.3.0-py3-none-any.whl", hash = "sha256:bb0d414ba0ac5cd62773ec7f86f8cc378a9dbb00a80884c2fc08cc570452521e", size = 7793 },
]
[[package]]
name = "django"
version = "5.1.5"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "asgiref" },
{ name = "sqlparse" },
{ name = "tzdata", marker = "sys_platform == 'win32'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/e4/17/834e3e08d590dcc27d4cc3c5cd4e2fb757b7a92bab9de8ee402455732952/Django-5.1.5.tar.gz", hash = "sha256:19bbca786df50b9eca23cee79d495facf55c8f5c54c529d9bf1fe7b5ea086af3", size = 10700031 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/11/e6/e92c8c788b83d109f34d933c5e817095d85722719cb4483472abc135f44e/Django-5.1.5-py3-none-any.whl", hash = "sha256:c46eb936111fffe6ec4bc9930035524a8be98ec2f74d8a0ff351226a3e52f459", size = 8276957 },
]
[[package]]
name = "kredens"
version = "0.1.0"
source = { virtual = "." }
dependencies = [
{ name = "dj-database-url" },
{ name = "django" },
{ name = "psycopg", extra = ["binary"] },
]
[package.metadata]
requires-dist = [
{ name = "dj-database-url", specifier = ">=2.3.0" },
{ name = "django", specifier = ">=5.1.5" },
{ name = "psycopg", extras = ["binary"], specifier = ">=3.2.4" },
]
[[package]]
name = "psycopg"
version = "3.2.4"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "tzdata", marker = "sys_platform == 'win32'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/e0/f2/954b1467b3e2ca5945b83b5e320268be1f4df486c3e8ffc90f4e4b707979/psycopg-3.2.4.tar.gz", hash = "sha256:f26f1346d6bf1ef5f5ef1714dd405c67fb365cfd1c6cea07de1792747b167b92", size = 156109 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/40/49/15114d5f7ee68983f4e1a24d47e75334568960352a07c6f0e796e912685d/psycopg-3.2.4-py3-none-any.whl", hash = "sha256:43665368ccd48180744cab26b74332f46b63b7e06e8ce0775547a3533883d381", size = 198716 },
]
[package.optional-dependencies]
binary = [
{ name = "psycopg-binary", marker = "implementation_name != 'pypy'" },
]
[[package]]
name = "psycopg-binary"
version = "3.2.4"
source = { registry = "https://pypi.org/simple" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/25/e2/f56675aada063762f08559b6969e47e1313f269fc1682c16457c13da8186/psycopg_binary-3.2.4-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:81ab801c0d35830c876bf0d1edc8e7dd2f73aa2b04fe24eb812159c0b054d149", size = 3846854 },
{ url = "https://files.pythonhosted.org/packages/7b/8b/8c4a66b2b3db494367df0299535b7d2df78f303334228c517b8d00c411d5/psycopg_binary-3.2.4-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:c09e02ce1124eb6638b3381df050a8cf88aedfad4522f939945cda49050a990c", size = 3932292 },
{ url = "https://files.pythonhosted.org/packages/84/e8/618d45f77cebce73d75497c95685a0902aea3783386d9335ce486c69e13a/psycopg_binary-3.2.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a249cdc6a5c2b5088a8677acba66b291e5237524739ab3d27498e1ef189312f5", size = 4493785 },
{ url = "https://files.pythonhosted.org/packages/c4/87/fc30318e6b97e723e017e7dc88d0f721bbfb749de1a6e414e52d4ac54c9a/psycopg_binary-3.2.4-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d2960ba8a5c0ad75e184f6d8bf76bdf023708999efe75fe4e13445136c1cd206", size = 4304874 },
{ url = "https://files.pythonhosted.org/packages/91/30/1d127e651c21cd77befaf361c7c3b9001bfff51ac38027e8fce598ba0701/psycopg_binary-3.2.4-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3dae2e50b0d3425c167eebbedc3553f7c811dbc0dbfc737b6877f68a03be7daf", size = 4541296 },
{ url = "https://files.pythonhosted.org/packages/0d/5e/22c824cb38745c1c744cec85d227190727c564afb75960ce0057ca15fd84/psycopg_binary-3.2.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:03bf7ee7e0002c2cce43ecb923ec510358056eb2e44a96afaeb0424518f35206", size = 4255756 },
{ url = "https://files.pythonhosted.org/packages/b3/83/ae8783dec3f7e39df8a4056e4d383926ffec531970c0b415d48d9fd4a2c2/psycopg_binary-3.2.4-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:5f5c85eeb63b1a8a6b026eef57f5da36ff215ce9a6a3bb8e20a409670d6cfbda", size = 3845918 },
{ url = "https://files.pythonhosted.org/packages/be/f7/fb7bffb0c4c45a5a82fe324e4f7b176075a4c5372e546a038858dd13c7ab/psycopg_binary-3.2.4-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:8c7b95899d4d6d23c5cc46cb3419e8e6ca68d867509432ee1487042564a1ea55", size = 3315429 },
{ url = "https://files.pythonhosted.org/packages/81/a3/29f4993a239d6a3fb18ef8681d9990c007f5f73bdd2e21f65f07ac55ad6f/psycopg_binary-3.2.4-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:fa4acea9ca20a567c3872a5afab2084751530bb57b8fb6b52820d5c54e7c8c3b", size = 3399388 },
{ url = "https://files.pythonhosted.org/packages/25/5b/925171cbfa2e3d1ccb7f4c005d0d5db609ba796c1d08a23c42825b09c554/psycopg_binary-3.2.4-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:5c487f35a1905bb15da927c1fc05f70f3d29f0e21fb4ba21d360a0da9c755f20", size = 3436702 },
{ url = "https://files.pythonhosted.org/packages/b6/47/25b2b85b8fcabf99bfa92b4b0d587894c01576bf0b2bf137c243d1eb1070/psycopg_binary-3.2.4-cp313-cp313-win_amd64.whl", hash = "sha256:80297c3a9f7b5a6afdb0d8f220661ccd796e5c9128c44b32c41267f7daefd37f", size = 2779196 },
]
[[package]]
name = "sqlparse"
version = "0.5.3"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/e5/40/edede8dd6977b0d3da179a342c198ed100dd2aba4be081861ee5911e4da4/sqlparse-0.5.3.tar.gz", hash = "sha256:09f67787f56a0b16ecdbde1bfc7f5d9c3371ca683cfeaa8e6ff60b4807ec9272", size = 84999 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/a9/5c/bfd6bd0bf979426d405cc6e71eceb8701b148b16c21d2dc3c261efc61c7b/sqlparse-0.5.3-py3-none-any.whl", hash = "sha256:cf2196ed3418f3ba5de6af7e82c694a9fbdbfecccdfc72e281548517081f16ca", size = 44415 },
]
[[package]]
name = "typing-extensions"
version = "4.12.2"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/df/db/f35a00659bc03fec321ba8bce9420de607a1d37f8342eee1863174c69557/typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8", size = 85321 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/26/9f/ad63fc0248c5379346306f8668cda6e2e2e9c95e01216d2b8ffd9ff037d0/typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d", size = 37438 },
]
[[package]]
name = "tzdata"
version = "2025.1"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/43/0f/fa4723f22942480be4ca9527bbde8d43f6c3f2fe8412f00e7f5f6746bc8b/tzdata-2025.1.tar.gz", hash = "sha256:24894909e88cdb28bd1636c6887801df64cb485bd593f2fd83ef29075a81d694", size = 194950 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/0f/dd/84f10e23edd882c6f968c21c2434fe67bd4a528967067515feca9e611e5e/tzdata-2025.1-py2.py3-none-any.whl", hash = "sha256:7e127113816800496f027041c570f50bcd464a020098a3b6b199517772303639", size = 346762 },
]