utarn commited on
Commit
a613a86
·
1 Parent(s): 790a062

Add docker compose

Browse files
Files changed (6) hide show
  1. .dockerignore +50 -0
  2. .gitlab-ci.yml +81 -0
  3. Dockerfile +31 -0
  4. Dockerfile.podman +31 -0
  5. app.py +1 -1
  6. docker-compose.yml +15 -0
.dockerignore ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Git
2
+ .git
3
+ .gitignore
4
+
5
+ # Python cache
6
+ __pycache__/
7
+ *.py[cod]
8
+ *$py.class
9
+ *.so
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ *.egg-info/
24
+ .installed.cfg
25
+ *.egg
26
+
27
+ # Virtual environments
28
+ venv/
29
+ env/
30
+ ENV/
31
+
32
+ # IDE
33
+ .vscode/
34
+ .idea/
35
+ *.swp
36
+ *.swo
37
+
38
+ # OS
39
+ .DS_Store
40
+ Thumbs.db
41
+
42
+ # Documentation
43
+ *.md
44
+ docs/
45
+
46
+ # Logs
47
+ *.log
48
+
49
+ # CI/CD
50
+ .gitlab-ci.yml
.gitlab-ci.yml ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ image: docker:latest
2
+
3
+ variables:
4
+ DOCKER_DRIVER: overlay2
5
+
6
+ services:
7
+ - docker:dind
8
+
9
+ stages:
10
+ - build
11
+ - notify
12
+
13
+ # Docker build job (existing)
14
+ build-docker:
15
+ stage: build
16
+ retry: 2
17
+ only:
18
+ - main
19
+ before_script:
20
+ - docker login -u $DOCKER_USER -p $DOCKER_PASSWORD registry2.zarimpun.com
21
+ script:
22
+ - NEWTAG=$(date +%Y%m%d-%H%M)
23
+ - docker build -t registry2.zarimpun.com/utarn/maze-generator:$NEWTAG -t registry2.zarimpun.com/utarn/maze-generator:latest -f Dockerfile .
24
+ - docker push registry2.zarimpun.com/utarn/maze-generator:$NEWTAG
25
+ - docker push registry2.zarimpun.com/utarn/maze-generator:latest
26
+ after_script:
27
+ - docker system prune -f
28
+
29
+ # Podman build job (new)
30
+ build-podman:
31
+ stage: build
32
+ image: quay.io/podman/stable:latest
33
+ retry: 2
34
+ only:
35
+ - main
36
+ before_script:
37
+ - podman login -u $DOCKER_USER -p $DOCKER_PASSWORD registry2.zarimpun.com
38
+ script:
39
+ - NEWTAG=$(date +%Y%m%d-%H%M)
40
+ - |
41
+ podman build \
42
+ --tag registry2.zarimpun.com/utarn/maze-generator:$NEWTAG-podman \
43
+ --tag registry2.zarimpun.com/utarn/maze-generator:latest-podman \
44
+ --file Dockerfile.podman \
45
+ --format=oci \
46
+ .
47
+ - podman push registry2.zarimpun.com/utarn/maze-generator:$NEWTAG-podman
48
+ - podman push registry2.zarimpun.com/utarn/maze-generator:latest-podman
49
+ after_script:
50
+ - podman system prune -f
51
+
52
+ # Notification job (updated to include both builds)
53
+ notify:
54
+ stage: notify
55
+ image: alpine:latest
56
+ dependencies:
57
+ - build-docker
58
+ - build-podman
59
+ only:
60
+ - main
61
+ before_script:
62
+ - apk add --no-cache curl jq
63
+ script:
64
+ - |
65
+ # Authenticate and get token
66
+ echo "Authenticating with LINE API..."
67
+ AUTH_RESPONSE=$(curl -s -X POST "https://lineoa.scigrad.com/api/auth/login" \
68
+ -H "Content-Type: application/json" \
69
+ -d "{\"username\": \"$LINE_API_USER\", \"password\": \"$LINE_API_PASSWORD\"}")
70
+ TOKEN=$(echo "$AUTH_RESPONSE" | jq -r '.token')
71
+
72
+ if [ -z "$TOKEN" ]; then
73
+ echo "Failed to extract token from the authentication response."
74
+ exit 1
75
+ fi
76
+
77
+ echo "Sending message via LINE OA API..."
78
+ curl -X POST "https://lineoa.scigrad.com/api/registration/send" \
79
+ -H "Authorization: Bearer $TOKEN" \
80
+ -H "Content-Type: application/json" \
81
+ -d "{\"code\": \"REGIS:utharn.b@rmutsb.ac.th\", \"messages\": [{\"type\": \"text\", \"text\": \"✅ Maze Generator CI Complete\n\nBranch: $CI_COMMIT_BRANCH\nDocker: ✅ Built\nPodman: ✅ Built\nCommit: ${CI_COMMIT_SHORT_SHA}\"}]}"
Dockerfile ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use Python 3.11 slim image
2
+ FROM python:3.11-slim
3
+
4
+ # Set working directory
5
+ WORKDIR /app
6
+
7
+ # Install system dependencies
8
+ RUN apt-get update && apt-get install -y \
9
+ build-essential \
10
+ && rm -rf /var/lib/apt/lists/*
11
+
12
+ # Copy requirements and install Python dependencies
13
+ COPY requirements.txt .
14
+ RUN pip install --no-cache-dir -r requirements.txt
15
+
16
+ # Copy application code
17
+ COPY . .
18
+
19
+ # Create pdfs directory
20
+ RUN mkdir -p pdfs
21
+
22
+ # Expose the Gradio port
23
+ EXPOSE 7860
24
+
25
+ # Set environment variables
26
+ ENV PYTHONUNBUFFERED=1
27
+ ENV GRADIO_SERVER_NAME=0.0.0.0
28
+ ENV GRADIO_SERVER_PORT=7860
29
+
30
+ # Run the application
31
+ CMD ["python", "app.py"]
Dockerfile.podman ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use Python 3.11 slim image
2
+ FROM python:3.11-slim
3
+
4
+ # Set working directory
5
+ WORKDIR /app
6
+
7
+ # Install system dependencies
8
+ RUN apt-get update && apt-get install -y \
9
+ build-essential \
10
+ && rm -rf /var/lib/apt/lists/*
11
+
12
+ # Copy requirements and install Python dependencies
13
+ COPY requirements.txt .
14
+ RUN pip install --no-cache-dir -r requirements.txt
15
+
16
+ # Copy application code
17
+ COPY . .
18
+
19
+ # Create pdfs directory
20
+ RUN mkdir -p pdfs
21
+
22
+ # Expose the Gradio port
23
+ EXPOSE 7860
24
+
25
+ # Set environment variables
26
+ ENV PYTHONUNBUFFERED=1
27
+ ENV GRADIO_SERVER_NAME=0.0.0.0
28
+ ENV GRADIO_SERVER_PORT=7860
29
+
30
+ # Run the application
31
+ CMD ["python", "app.py"]
app.py CHANGED
@@ -265,4 +265,4 @@ if __name__ == "__main__":
265
  )
266
 
267
  print("✅ Maze Generator is ready and running!")
268
- print("🎯 Open your browser and navigate to http://localhost:7861")
 
265
  )
266
 
267
  print("✅ Maze Generator is ready and running!")
268
+ print("🎯 Open your browser and navigate to http://localhost:7860")
docker-compose.yml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: '3.8'
2
+
3
+ services:
4
+ maze-generator:
5
+ build: .
6
+ container_name: maze-generator
7
+ ports:
8
+ - "127.0.0.1:5111:7860"
9
+ volumes:
10
+ - ./pdfs:/app/pdfs
11
+ environment:
12
+ - PYTHONUNBUFFERED=1
13
+ - GRADIO_SERVER_NAME=0.0.0.0
14
+ - GRADIO_SERVER_PORT=7860
15
+ restart: unless-stopped