Skip to content

Commit 7f2cbaf

Browse files
authored
Update devcontainer setup (#246)
* Update devcontainer setup * using ruff instead of black extension
1 parent b23114d commit 7f2cbaf

File tree

4 files changed

+74
-43
lines changed

4 files changed

+74
-43
lines changed

.devcontainer/Dockerfile

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
11
ARG VARIANT=3.8
22
FROM mcr.microsoft.com/vscode/devcontainers/python:${VARIANT}
33

4+
5+
# Install Poetry and pre-commit
46
RUN pip3 install poetry pre-commit
5-
RUN poetry config virtualenvs.in-project true
7+
68
ARG PGVERSION=14
9+
ARG TARGETPLATFORM
710

8-
# Setup apt repo for Postgres
9-
RUN if [ "${PGVERSION}" != "none" ]; then \
10-
echo "deb [signed-by=/usr/share/keyrings/postgresql.gpg] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" \
11-
| tee /etc/apt/sources.list.d/pgdg.list \
12-
&& curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc \
11+
# Setup Postgres repo and install packages
12+
13+
# Add PostgreSQL APT repository and key (only if PGVERSION is not "none")
14+
RUN if [ "${PGVERSION}" != "none" ]; then \
15+
echo "deb [signed-by=/usr/share/keyrings/postgresql.gpg] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" \
16+
> /etc/apt/sources.list.d/pgdg.list && \
17+
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc \
1318
| gpg --dearmor --yes -o /usr/share/keyrings/postgresql.gpg; \
1419
fi
1520

16-
# Install Postgres packages
17-
ARG TARGETPLATFORM
21+
# Install PostgreSQL packages using APT cache mount
1822
RUN --mount=type=cache,target=/var/cache/apt,id=apt-${TARGETPLATFORM} \
19-
export DEBIAN_FRONTEND=noninteractive \
20-
&& export PGPACKAGES=$(if [ "${PGVERSION}" != "none" ]; then echo "postgresql-${PGVERSION} postgresql-client-${PGVERSION} postgresql-server-dev-${PGVERSION}"; fi) \
21-
&& apt-get remove man-db --purge -y \
22-
&& apt-get update \
23-
&& apt-get -y install --no-install-recommends ${PGPACKAGES}
23+
if [ "${PGVERSION}" != "none" ]; then \
24+
apt-get update && \
25+
apt-get -y install --no-install-recommends \
26+
postgresql-${PGVERSION} \
27+
postgresql-client-${PGVERSION} \
28+
postgresql-server-dev-${PGVERSION} && \
29+
apt-get clean && rm -rf /var/lib/apt/lists/*; \
30+
fi
2431

25-
# Trust postgres connections from localhost and local port.
26-
RUN if [ "$PGVERSION" != "none" ]; then \
27-
sed -i -E 's/local(\s+)all(\s+)postgres(\s+)peer/local\1all\2all\3trust/g' /etc/postgresql/${PGVERSION}/main/pg_hba.conf && \
28-
sed -i -E 's/host(\s+)all(\s+)all(\s+)(\S+)(\s+)(\S+)/host\1all\2all\3\4\5trust/g' /etc/postgresql/${PGVERSION}/main/pg_hba.conf; \
32+
# Configure Postgres to trust local connections
33+
RUN if [ "${PGVERSION}" != "none" ]; then \
34+
sed -i -E 's/local(\s+)all(\s+)postgres(\s+)peer/local\1all\2all\3trust/g' \
35+
/etc/postgresql/${PGVERSION}/main/pg_hba.conf && \
36+
sed -i -E 's/host(\s+)all(\s+)all(\s+)(\S+)(\s+)(\S+)/host\1all\2all\3\4\5trust/g' \
37+
/etc/postgresql/${PGVERSION}/main/pg_hba.conf; \
2938
fi

.devcontainer/devcontainer.json

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
{
22
"name": "Strawberry Sqlalchemy Mapper",
3-
"context": "..",
43
"build": {
5-
"dockerfile": "Dockerfile"
4+
"dockerfile": "Dockerfile",
5+
"context": ".."
66
},
7-
8-
"settings": {
9-
"terminal.integrated.shell.linux": "/bin/bash",
10-
"python.pythonPath": "/usr/local/bin/python",
11-
"python.linting.enabled": true,
12-
"python.linting.pylintEnabled": true,
13-
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
14-
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
15-
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
16-
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
17-
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
18-
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
19-
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
20-
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
21-
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
7+
"customizations": {
8+
"vscode": {
9+
"settings": {
10+
"terminal.integrated.shell.linux": "/bin/bash",
11+
"python.terminal.activateEnvironment": true,
12+
"python.pythonPath": "${workspaceFolder}/.venv/bin/python",
13+
"python.linting.enabled": true,
14+
"python.linting.pylintEnabled": false,
15+
"python.linting.mypyEnabled": true,
16+
"[python]": {
17+
"editor.defaultFormatter": "charliermarsh.ruff"
18+
},
19+
"python.formatting.provider": "black",
20+
"python.formatting.blackPath": "${workspaceFolder}/.venv/bin/black",
21+
"python.linting.mypyPath": "${workspaceFolder}/.venv/bin/mypy"
22+
},
23+
"extensions": [
24+
"ms-python.python",
25+
"ms-python.vscode-pylance",
26+
"ms-azuretools.vscode-docker",
27+
"eamodio.gitlens",
28+
"charliermarsh.ruff",
29+
// Dont install these extensions because they conflict with black lint
30+
"-dbaeumer.vscode-eslint",
31+
"-ms-python.autopep8"
32+
]
33+
}
2234
},
23-
24-
"extensions": ["ms-python.python", "ms-python.vscode-pylance", "eamodio.gitlens"],
25-
"postCreateCommand": "sh ./.devcontainer/post-install.sh",
26-
"postStartCommand": "sh ./.devcontainer/post-start.sh",
35+
"postCreateCommand": "chmod +x ./.devcontainer/post-install.sh && ./.devcontainer/post-install.sh",
36+
"postStartCommand": "chmod +x ./.devcontainer/post-start.sh && ./.devcontainer/post-start.sh"
2737
}

.devcontainer/post-install.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1-
poetry install
1+
#!/bin/bash
2+
set -e # Exit on error
3+
4+
echo "📦 Installing Python dependencies with Poetry..."
5+
poetry config virtualenvs.in-project true
6+
poetry install --no-cache
7+
8+
echo "🔧 Setting up pre-commit hooks..."
9+
210
pre-commit install --install-hooks

.devcontainer/post-start.sh

100644100755
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
service postgresql status
2-
if [ "$?" -eq "1" ]; then
3-
echo "Postgres not installed. Postgres integration tests will fail for now."
4-
else
1+
#!/bin/bash
2+
3+
echo "🔍 Checking PostgreSQL service status..."
4+
if ! pg_isready > /dev/null 2>&1; then
5+
echo "⚠️ PostgreSQL is not ready. Starting the service..."
56
sudo service postgresql start
7+
echo "✅ PostgreSQL running."
8+
else
9+
echo "✅ PostgreSQL is already running."
610
fi

0 commit comments

Comments
 (0)