Skip to content

Commit b8174ff

Browse files
author
Pascal Debus
committed
fix: adjust docker configuration to be compatible with images generated by github actions, fix health checks with respect to app base directory, create additional docker compose configs for development
1 parent f9b5261 commit b8174ff

File tree

9 files changed

+114
-29
lines changed

9 files changed

+114
-29
lines changed

.dockerignore

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
.git
22
.gitignore
3+
.github
34
__pycache__
45
*.pyc
56
.env
6-
*.log
7+
*.log
8+
.vscode
9+
.idea
10+
*.md
11+
README.md
12+
docker-compose.yml
13+
*.png
14+
*.jpg
15+
*.jpeg
16+
node_modules
17+
.pytest_cache
18+
.coverage
19+
htmlcov

.github/workflows/docker-publish.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
name: Build and publish Docker image to GHCR
32

43
on:
@@ -10,7 +9,6 @@ on:
109
- 'docker-compose.yml'
1110
- 'nginx.conf'
1211
- 'requirements.txt'
13-
- 'requirements_docker.txt'
1412
release:
1513
types: [published]
1614

@@ -44,6 +42,10 @@ jobs:
4442
uses: docker/metadata-action@v5
4543
with:
4644
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
45+
tags: |
46+
type=ref,event=branch
47+
type=ref,event=tag
48+
type=raw,value=latest,enable={{is_default_branch}}
4749
4850
- name: Build and push Docker image
4951
id: push

Dockerfile

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,42 @@ FROM pytorch/pytorch:2.7.0-cuda11.8-cudnn9-runtime
22

33
LABEL maintainer="Pascal Debus" \
44
description="QML Playground" \
5-
version="1.0"
5+
version="1.0" \
6+
org.opencontainers.image.source="https://github.com/fraunhofer-aisec/qml-playground"
67

78
# Set working directory inside the container
89
WORKDIR /app
910

10-
# Install curl and dependencies
11+
# Install curl and dependencies in one layer
1112
RUN apt-get update && \
12-
apt-get install -y curl && \
13+
apt-get install -y --no-install-recommends curl && \
14+
apt-get clean && \
1315
rm -rf /var/lib/apt/lists/*
1416

15-
# Copy requirements and install (skip torch)
17+
# Copy requirements first for better layer caching
1618
COPY requirements.txt /app/requirements.txt
17-
RUN pip install --no-cache-dir $(grep -v "torch" /app/requirements.txt)
1819

19-
# Copy the app code from ./app in host into /app in container
20+
# Install Python dependencies (skip torch as it's in base image)
21+
RUN pip install --no-cache-dir --upgrade pip && \
22+
pip install --no-cache-dir $(grep -v "torch" /app/requirements.txt)
23+
24+
# Copy the app code
2025
COPY app/ /app/
2126

2227
# Create and use non-root user
2328
RUN groupadd -r appuser && \
24-
useradd -r -g appuser appuser && \
29+
useradd -r -g appuser -d /app -s /sbin/nologin appuser && \
2530
chown -R appuser:appuser /app
31+
2632
USER appuser
2733

28-
# Healthcheck
29-
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
30-
CMD curl --fail http://localhost:8050/ || exit 1
34+
# Healthcheck - Updated to use the correct path
35+
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
36+
CMD curl --fail http://localhost:8050/qml-playground/ || exit 1
3137

3238
ENV PYTHONPATH="${PYTHONPATH}:/app"
3339

3440
EXPOSE 8050
3541

3642
# Start the Dash app using gunicorn
37-
CMD ["gunicorn", "app:server", "--bind", "0.0.0.0:8050"]
43+
CMD ["gunicorn", "app:server", "--bind", "0.0.0.0:8050", "--workers", "1", "--timeout", "120"]

app/app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
from logic import qml_app
33

44
logging.basicConfig(encoding='utf-8', level=logging.INFO)
5-
qml_app.run(host="0.0.0.0")
5+
6+
server = qml_app.server
7+
8+
if __name__ == '__main__':
9+
qml_app.run(host="0.0.0.0")

docker-compose.build-test.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
version: '3.8'
2+
3+
services:
4+
dash-app:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
image: qml-playground:local-test
9+
container_name: dash_app_build_test
10+
restart: unless-stopped
11+
expose:
12+
- "8050"
13+
healthcheck:
14+
test: ["CMD", "curl", "-f", "http://localhost:8050/qml-playground/"]
15+
interval: 30s
16+
timeout: 10s
17+
retries: 3
18+
start_period: 40s
19+
environment:
20+
- PYTHONUNBUFFERED=1
21+
networks:
22+
- dash-build-test-network
23+
24+
nginx:
25+
image: nginx:alpine
26+
container_name: dash_nginx_build_test
27+
restart: unless-stopped
28+
ports:
29+
- "80:80"
30+
volumes:
31+
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
32+
depends_on:
33+
dash-app:
34+
condition: service_healthy
35+
healthcheck:
36+
test: ["CMD", "nginx", "-t"]
37+
interval: 30s
38+
timeout: 10s
39+
retries: 3
40+
networks:
41+
- dash-build-test-network
42+
43+
networks:
44+
dash-build-test-network:
45+
driver: bridge

docker-compose.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ version: '3.8'
22

33
services:
44
dash-app:
5-
build: .
5+
image: ghcr.io/fraunhofer-aisec/qml-playground:latest
66
container_name: dash_app
77
restart: unless-stopped
88
expose:
99
- "8050"
1010
healthcheck:
11-
test: ["CMD", "curl", "-f", "http://localhost:8050/"]
11+
test: ["CMD", "curl", "-f", "http://localhost:8050/qml-playground/"]
1212
interval: 30s
1313
timeout: 10s
1414
retries: 3
15+
start_period: 40s
1516
environment:
1617
- PYTHONUNBUFFERED=1
1718
networks:

docker_compose.dev.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: '3.8'
2+
services:
3+
dash-app:
4+
build: .
5+
volumes:
6+
- ./app:/app
7+
environment:
8+
- DEBUG=1

nginx.conf

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ server {
1212
proxy_buffers 16 16k;
1313
proxy_buffer_size 16k;
1414

15-
location / {
16-
proxy_pass http://dash-app:8050;
15+
# Root redirect to qml-playground
16+
location = / {
17+
return 301 /qml-playground/;
18+
}
19+
20+
# Main app location
21+
location /qml-playground/ {
22+
proxy_pass http://dash-app:8050/qml-playground/;
1723
proxy_set_header Host $host;
1824
proxy_set_header X-Real-IP $remote_addr;
1925
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -30,11 +36,16 @@ server {
3036
proxy_read_timeout 60s;
3137
}
3238

33-
#location /assets/ {
34-
# add_header Access-Control-Allow-Origin "*";
35-
# proxy_pass http://dash-app:8050/assets/;
36-
# proxy_set_header Host $host;
37-
#}
39+
# Handle static assets
40+
location /qml-playground/_dash-component-suites/ {
41+
proxy_pass http://dash-app:8050/qml-playground/_dash-component-suites/;
42+
proxy_set_header Host $host;
43+
}
44+
45+
location /qml-playground/assets/ {
46+
proxy_pass http://dash-app:8050/qml-playground/assets/;
47+
proxy_set_header Host $host;
48+
}
3849

3950
# Gzip compression
4051
gzip on;

requirements_docker.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)