Skip to content

Commit 1ca3039

Browse files
committed
Adding devcontainer files
1 parent 9e45cb3 commit 1ca3039

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ARG VARIANT=3
2+
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}
3+
4+
RUN curl -fsSL https://aka.ms/install-azd.sh | bash
5+
6+
ENV PYTHONUNBUFFERED 1
7+
8+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
9+
&& apt-get -y install --no-install-recommends postgresql-client

.devcontainer/devcontainer.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "Python 3 & PostgreSQL",
3+
"dockerComposeFile": "docker-compose.yml",
4+
"service": "app",
5+
"workspaceFolder": "/workspace",
6+
"settings": {
7+
"sqltools.connections": [
8+
{
9+
"name": "Container database",
10+
"driver": "PostgreSQL",
11+
"previewLimit": 50,
12+
"server": "localhost",
13+
"port": 5432,
14+
"database": "app",
15+
"username": "app_user",
16+
"password": "app_password"
17+
}
18+
],
19+
"python.pythonPath": "/usr/local/bin/python",
20+
"python.languageServer": "Pylance",
21+
"python.linting.enabled": true,
22+
"python.linting.mypyEnabled": true,
23+
"python.testing.pytestEnabled": true,
24+
"python.formatting.provider": "black",
25+
"python.formatting.blackArgs": [
26+
"--line-length=80"
27+
],
28+
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
29+
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
30+
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
31+
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
32+
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
33+
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
34+
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
35+
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
36+
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
37+
"python.testing.pytestPath": "/usr/local/py-utils/bin/pytest"
38+
},
39+
"features": {
40+
"ghcr.io/devcontainers/features/azure-cli:1": {
41+
"version": "latest"
42+
},
43+
"ghcr.io/devcontainers/features/github-cli:1": {
44+
"version": "latest"
45+
}
46+
},
47+
// Add the IDs of extensions you want installed when the container is created.
48+
"extensions": [
49+
"ms-azuretools.azure-dev",
50+
"ms-python.python",
51+
"ms-python.vscode-pylance",
52+
"mtxr.sqltools",
53+
"mtxr.sqltools-driver-pg"
54+
],
55+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
56+
"forwardPorts": [
57+
5000, 5432
58+
]
59+
// Use 'postCreateCommand' to run commands after the container is created.
60+
// "postCreateCommand": "",
61+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
62+
// "remoteUser": "vscode"
63+
}

.devcontainer/docker-compose.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version: "3"
2+
3+
services:
4+
app:
5+
build:
6+
context: ..
7+
dockerfile: .devcontainer/Dockerfile
8+
args:
9+
# [Choice] Python version: 3, 3.8, 3.7, 3.6
10+
VARIANT: 3.9
11+
# On Linux, you may need to update USER_UID and USER_GID below if not your local UID is not 1000.
12+
USER_UID: 1000
13+
USER_GID: 1000
14+
15+
volumes:
16+
- ..:/workspace:cached
17+
18+
# Overrides default command so things don't shut down after the process ends.
19+
command: sleep infinity
20+
21+
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
22+
network_mode: service:db
23+
24+
db:
25+
image: postgres:latest
26+
restart: unless-stopped
27+
volumes:
28+
- postgres-data:/var/lib/postgresql/data
29+
environment:
30+
POSTGRES_USER: "${DBUSER}"
31+
POSTGRES_DB: "${DBNAME}"
32+
POSTGRES_PASSWORD: "${DBPASS}"
33+
34+
# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
35+
# (Adding the "ports" property to this file will not forward from a Codespace.)
36+
37+
volumes:
38+
postgres-data:

0 commit comments

Comments
 (0)