Skip to content

Commit a509de9

Browse files
committed
use docker-compose
1 parent e9040e0 commit a509de9

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ DB_PORT=5432
66
USERNAME="piccolo"
77
PASSWORD="piccolo123"
88
9+
TABLES_TO_SHOW=""

Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,3 @@ COPY ./requirements.txt /code/requirements.txt
77
RUN pip install --no-cache-dir -r /code/requirements.txt
88

99
COPY ./app /code/app
10-
11-
CMD ["python", "app/main.py"]

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ Creating an `.env` file.
1414
cp .env.example .env && rm .env.example
1515
```
1616

17-
Creating a Docker image.
17+
Run the Docker container.
1818

1919
```bash
20-
docker build -t piccolo_admin .
20+
docker-compose up -d
2121
```
2222

23-
Running a Docker image (use the `--network=host` flag for an existing database from the local machine).
23+
After site is running log in as admin user on [localhost:8000](http://localhost:8000) and use legacy database.
2424

25-
```bash
26-
docker run --env-file .env -d --network=host --name admin_container piccolo_admin
27-
```
25+
Stop the Docker container.
2826

29-
After site is running log in as admin user on [localhost:8000](http://localhost:8000/admin/) and use legacy database.
27+
```bash
28+
docker-compose down
29+
```

app/main.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,23 @@ async def main():
6060
extensions=tuple(),
6161
)
6262

63+
tables_to_show = [
64+
table_to_show.lower().strip()
65+
for table_to_show in os.environ["TABLES_TO_SHOW"].split(",")
66+
]
67+
6368
storage = TableStorage(engine=db)
6469
await storage.reflect(schema_name="public")
6570

66-
# This tuple IS unique
67-
# however auto_include_related within
68-
# create_admin makes it non unique TableConfigs
69-
found_tables = storage.tables.values()
71+
# tables to show in admin
72+
if len(tables_to_show) == 1:
73+
found_tables = storage.tables.values()
74+
else:
75+
found_tables = [
76+
table
77+
for table in storage.tables.values()
78+
if table._meta.tablename in tables_to_show
79+
]
7080

7181
for table_class in found_tables:
7282
table_class._meta._db = db

docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
web:
3+
build: .
4+
command: python app/main.py
5+
volumes:
6+
- .:/app
7+
env_file:
8+
- .env
9+
network_mode: "host"

0 commit comments

Comments
 (0)