Pamela Fox commited on
Commit
20c47af
·
1 Parent(s): f28be2b

postgres devcontainer

Browse files
.devcontainer/Dockerfile CHANGED
@@ -1,8 +1,9 @@
1
- # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/python-3/.devcontainer/base.Dockerfile
 
2
 
3
- # [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster
4
- ARG VARIANT=bullseye
5
- FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}
6
  RUN curl -fsSL https://aka.ms/install-azd.sh | bash
7
- RUN apt update
8
- RUN apt-get install --yes libpq-dev
 
 
 
 
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 CHANGED
@@ -1,18 +1,23 @@
1
  // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2
  // https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/python-3
3
  {
4
- "name": "Python 3",
5
- "forwardPorts": [8000],
6
- "build": {
7
- "dockerfile": "Dockerfile",
8
- "context": "..",
9
- "args": {
10
- // Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6
11
- // Append -bullseye or -buster to pin to an OS version.
12
- // Use -bullseye variants on local on arm64/Apple Silicon.
13
- "VARIANT": "bullseye"
14
- }
15
- },
 
 
 
 
 
16
 
17
  // Configure tool-specific properties.
18
  "customizations": {
@@ -20,6 +25,18 @@
20
  "vscode": {
21
  // Set *default* container specific settings.json values on container create.
22
  "settings": {
 
 
 
 
 
 
 
 
 
 
 
 
23
  "python.defaultInterpreterPath": "/usr/local/bin/python",
24
  "python.linting.enabled": true,
25
  "python.linting.pylintEnabled": true,
@@ -42,24 +59,19 @@
42
 
43
  // Add the IDs of extensions you want installed when the container is created.
44
  "extensions": [
 
45
  "ms-python.python",
46
- "ms-python.vscode-pylance"
 
 
47
  ]
48
  }
49
  },
50
 
 
51
  // Use 'postCreateCommand' to run commands after the container is created.
52
  "postCreateCommand": "pip install -r requirements-dev.txt && pre-commit install",
53
 
54
  // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
55
- "remoteUser": "vscode",
56
-
57
- "features": {
58
- "ghcr.io/devcontainers/features/azure-cli:1": {
59
- "version": "latest"
60
- },
61
- "ghcr.io/devcontainers/features/python:1": {
62
- "version": "os-provided"
63
- }
64
- }
65
  }
 
1
  // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2
  // https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/python-3
3
  {
4
+ "name": "Python 3 & PostgreSQL",
5
+ "dockerComposeFile": "docker-compose.yml",
6
+ "service": "app",
7
+ "workspaceFolder": "/workspace",
8
+ "forwardPorts": [8000, 5432],
9
+
10
+ "features": {
11
+ "ghcr.io/devcontainers/features/azure-cli:1": {
12
+ "version": "latest"
13
+ },
14
+ "ghcr.io/devcontainers/features/github-cli:1": {
15
+ "version": "latest"
16
+ },
17
+ "ghcr.io/devcontainers/features/python:1": {
18
+ "version": "os-provided"
19
+ }
20
+ },
21
 
22
  // Configure tool-specific properties.
23
  "customizations": {
 
25
  "vscode": {
26
  // Set *default* container specific settings.json values on container create.
27
  "settings": {
28
+ "sqltools.connections": [
29
+ {
30
+ "name": "Container database",
31
+ "driver": "PostgreSQL",
32
+ "previewLimit": 50,
33
+ "server": "localhost",
34
+ "port": 5432,
35
+ "database": "app",
36
+ "username": "app_user",
37
+ "password": "app_password"
38
+ }
39
+ ],
40
  "python.defaultInterpreterPath": "/usr/local/bin/python",
41
  "python.linting.enabled": true,
42
  "python.linting.pylintEnabled": true,
 
59
 
60
  // Add the IDs of extensions you want installed when the container is created.
61
  "extensions": [
62
+ "ms-azuretools.azure-dev",
63
  "ms-python.python",
64
+ "ms-python.vscode-pylance",
65
+ "mtxr.sqltools",
66
+ "mtxr.sqltools-driver-pg"
67
  ]
68
  }
69
  },
70
 
71
+
72
  // Use 'postCreateCommand' to run commands after the container is created.
73
  "postCreateCommand": "pip install -r requirements-dev.txt && pre-commit install",
74
 
75
  // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
76
+ "remoteUser": "vscode"
 
 
 
 
 
 
 
 
 
77
  }
.devcontainer/docker-compose.yml ADDED
@@ -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_DB: app
31
+ POSTGRES_USER: app_user
32
+ POSTGRES_PASSWORD: app_password
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:
.env.sample ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ DBHOST=localhost
2
+ DBNAME=app
3
+ DBUSER=app_user
4
+ DBPASS=app_password
.gitignore CHANGED
@@ -2,5 +2,5 @@
2
  __pycache__/
3
  staticfiles/
4
  .coverage
5
-
6
  .azure
 
2
  __pycache__/
3
  staticfiles/
4
  .coverage
5
+ .env
6
  .azure