From 171c6b7d12d26ab27303a08148a27590f2210f46 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Wed, 10 Sep 2025 14:36:48 +0000 Subject: [PATCH] dev container to make standardised asset list to work --- .devcontainer/Dockerfile | 33 ++++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 30 +++++++++++++++++++++++++++++ .devcontainer/docker-compose.yml | 18 +++++++++++++++++ .devcontainer/post-install.sh | 27 ++++++++++++++++++++++++++ .vscode/settings.json | 19 ++++++++++++++++++ asset_list/app.py | 3 ++- 6 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100644 .devcontainer/post-install.sh create mode 100644 .vscode/settings.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..e176832b --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,33 @@ +FROM python:3.12-bullseye + +ARG USER=vscode +ARG DEBIAN_FRONTEND=noninteractive + +# 1) Toolchain + utilities for building libpostal +RUN apt-get update && apt-get install -y --no-install-recommends \ + sudo jq vim curl git ca-certificates \ + build-essential pkg-config automake autoconf libtool \ + && rm -rf /var/lib/apt/lists/* + +# 2) Build and install libpostal from source +RUN git clone --depth 1 https://github.com/openvenues/libpostal /tmp/libpostal \ + && cd /tmp/libpostal \ + && ./bootstrap.sh \ + && ./configure --datadir=/usr/local/share/libpostal \ + && make -j"$(nproc)" \ + && make install \ + && ldconfig \ + && rm -rf /tmp/libpostal + +# 3) Create the user and grant sudo privileges +RUN useradd -m -s /usr/bin/bash ${USER} \ + && echo "${USER} ALL=(ALL) NOPASSWD: ALL" >/etc/sudoers.d/${USER} \ + && chmod 0440 /etc/sudoers.d/${USER} + +# 4) Python deps +ENV PIP_NO_CACHE_DIR=1 PIP_DISABLE_PIP_VERSION_CHECK=1 +ADD asset_list/requirements.txt requirements.txt +RUN pip install -r requirements.txt + +# 5) Workdir +WORKDIR /workspaces/model diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..49bd6f83 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,30 @@ +{ + "name": "Basic Python", + "dockerComposeFile": "docker-compose.yml", + "service": "model", + "remoteUser": "vscode", + "workspaceFolder": "/workspaces/model", + "postStartCommand": "bash .devcontainer/post-install.sh", + "mounts": [ + // Optional, just makes getting from Downloads (local env) easier + "source=${localEnv:HOME},target=/workspaces/home,type=bind" + ], + "customizations": { + "vscode": { + "settings": { + "files.defaultWorkspace": "/workspaces/model" + }, + "extensions": [ + "ms-python.python", + "ms-toolsai.jupyter", + "mechatroner.rainbow-csv", + "ms-toolsai.datawrangler", + "lindacong.vscode-book-reader", + "4ops.terraform", + "fabiospampinato.vscode-todo-plus", + "jgclark.vscode-todo-highlight", + "corentinartaud.pdfpreview" + ] + } + } +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 00000000..7f60d34d --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,18 @@ +version: '3.8' + +services: + model: + user: "${UID}:${GID}" + build: + context: .. + dockerfile: .devcontainer/Dockerfile + command: sleep infinity + volumes: + - ..:/workspaces/model + networks: + - model-net + +networks: + model-net: + driver: bridge + diff --git a/.devcontainer/post-install.sh b/.devcontainer/post-install.sh new file mode 100644 index 00000000..d9fc3a9e --- /dev/null +++ b/.devcontainer/post-install.sh @@ -0,0 +1,27 @@ +# #!/bin/bash +# poetry install; + +# # Get the Poetry virtual environment path +# VENV_PATH=$(poetry env info --path 2>/dev/null) + +# if [ -z "$VENV_PATH" ]; then +# echo "No Poetry environment found. Did you run 'poetry install'?" +# exit 1 +# fi + +# # Ensure VS Code settings directory exists +# SETTINGS_DIR="/home/vscode/.vscode-server/data/Machine" +# SETTINGS_FILE="$SETTINGS_DIR/settings.json" + +# mkdir -p "$SETTINGS_DIR" + +# # If settings.json doesn't exist, create a default one +# if [ ! -f "$SETTINGS_FILE" ]; then +# echo "{}" > "$SETTINGS_FILE" +# fi + +# # Update VS Code settings to use the Poetry virtual environment +# jq --arg venv "$VENV_PATH/bin/python" '.["python.defaultInterpreterPath"] = $venv' \ +# "$SETTINGS_FILE" > "$SETTINGS_FILE.tmp" && mv "$SETTINGS_FILE.tmp" "$SETTINGS_FILE" + +# echo "✅ Updated VS Code to use Poetry environment: $VENV_PATH" diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..27782c10 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,19 @@ +{ + "jupyter.interactiveWindow.textEditor.executeSelection": true, + "python.REPL.sendToNativeREPL": true, + "notebook.output.scrolling": true, + "terminal.integrated.defaultProfile.linux": "bash", + "editor.rulers": [67], + "terminal.integrated.profiles.linux": { + "bash": { + "path": "/bin/bash" + } + }, + + // Hot reload setting that needs to be in user settings + // "jupyter.runStartupCommands": [ + // "%load_ext autoreload", "%autoreload 2" + // ] + + +} \ No newline at end of file diff --git a/asset_list/app.py b/asset_list/app.py index 01c31f0f..3aaa3462 100644 --- a/asset_list/app.py +++ b/asset_list/app.py @@ -12,10 +12,11 @@ from asset_list.utils import get_data from dotenv import load_dotenv from backend.SearchEpc import SearchEpc - load_dotenv(dotenv_path="backend/.env") EPC_AUTH_TOKEN = os.getenv("EPC_AUTH_TOKEN") +print("hello world") + def extract_address1(asset_list, full_address_col, postcode_col, method="first_two_words"): if method == "first_two_words":