Skip to content

Commit 9d786cc

Browse files
committed
Add Docker Compose and Dev Containers
Can now develop without having to set up postgres yourself
1 parent 518bd29 commit 9d786cc

File tree

4 files changed

+73
-16
lines changed

4 files changed

+73
-16
lines changed

.devcontainer.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "OC4IDS Datastore Pipeline Dev Container",
3+
"dockerComposeFile": "docker-compose.dev.yml",
4+
"service": "app",
5+
"workspaceFolder": "/oc4ids_datastore_pipeline",
6+
"forwardPorts": [5432],
7+
"customizations": {
8+
"vscode": {
9+
"extensions":["ms-python.python"]
10+
}
11+
}
12+
}

Dockerfile.dev

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM python:3.12-slim
2+
3+
RUN apt-get update \
4+
&& apt-get install -y libpq-dev gcc postgresql-client
5+
6+
WORKDIR /oc4ids_datastore_pipeline
7+
8+
COPY requirements.txt .
9+
10+
RUN pip install -r requirements.txt
11+
12+
COPY . .
13+
14+
RUN pip install -e .
15+
16+
ENTRYPOINT ["sleep", "infinity"]

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,16 @@
22

33
A Python application to validate and store published OC4IDS datasets.
44

5-
## Local Development
5+
## Local Development via Dev Containers or Docker Compose
66

7-
### Prerequisites
7+
You can open this repository in a dev container to get an environment complete with Postgres database.
88

9-
- Python 3.12
10-
- Postgres
11-
12-
### Install Python requirements
13-
14-
```
15-
python -m venv .venv
16-
source .venv/bin/activate
17-
pip install -r requirements_dev.txt
18-
```
19-
20-
### Set database enrivonment variable
9+
If you prefer to use Docker Compose, you can instead run:
2110

2211
```
23-
export DATABASE_URL="postgresql://oc4ids_datastore@localhost/oc4ids_datastore"
12+
docker compose -f docker-compose.dev.yml up -d
13+
docker compose -f docker-compose.dev.yml exec app bash
14+
docker compose -f docker-compose.dev.yml stop
2415
```
2516

2617
### Run database migrations
@@ -89,9 +80,19 @@ To send failure notifications by email, the following environment variables must
8980
### Run app
9081

9182
```
92-
pip install -e .
9383
oc4ids-datastore-pipeline
9484
```
85+
### Access Database
86+
87+
From inside the dev container or Docker container:
88+
89+
```
90+
psql postgresql://postgres:postgres@localhost:5432/postgres
91+
```
92+
93+
Connecting from outside:
94+
* If using a dev container or Docker Compose locally the same command should work
95+
* In GitHub Codespaces, we're not sure how to access the port
9596

9697
### Run linting and type checking
9798

docker-compose.dev.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile.dev
6+
volumes:
7+
- .:/oc4ids_datastore_pipeline:cached
8+
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
9+
network_mode: service:db
10+
environment:
11+
- DATABASE_URL=postgresql://postgres:postgres@localhost/postgres
12+
entrypoint: sleep infinity
13+
14+
db:
15+
image: postgres:latest
16+
restart: unless-stopped
17+
volumes:
18+
- postgres-data:/var/lib/postgresql/data
19+
environment:
20+
POSTGRES_USER: postgres
21+
POSTGRES_DB: postgres
22+
POSTGRES_PASSWORD: postgres
23+
# Forwarding this port so people can access the DB when run via Docker Compose without dev containers.
24+
ports:
25+
- 5432:5432
26+
27+
volumes:
28+
postgres-data:

0 commit comments

Comments
 (0)