Skip to content

Commit 281fb39

Browse files
committed
Add Docker support with Dockerfile, .dockerignore, and GitHub Actions workflow
1 parent ab68553 commit 281fb39

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

.dockerignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Version control
2+
.git
3+
.gitignore
4+
5+
# Environment variables
6+
.env
7+
8+
# Python
9+
__pycache__/
10+
*.py[cod]
11+
*$py.class
12+
*.so
13+
.Python
14+
env/
15+
venv/
16+
ENV/
17+
18+
# IDE
19+
.idea/
20+
.vscode/
21+
*.swp
22+
*.swo
23+
24+
# Project-specific
25+
uploads/*
26+
*.db
27+
*.sqlite3
28+
29+
# Logs
30+
*.log
31+
32+
# Docker
33+
Dockerfile
34+
.dockerignore
35+
36+
# GitHub
37+
.github/

.github/workflows/docker-build.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v2
15+
16+
- name: Set up Docker Buildx
17+
uses: docker/setup-buildx-action@v1
18+
19+
- name: Login to GitHub Container Registry
20+
uses: docker/login-action@v1
21+
with:
22+
registry: ghcr.io
23+
username: ${{ github.actor }}
24+
password: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Build and push
27+
uses: docker/build-push-action@v2
28+
with:
29+
context: .
30+
push: true
31+
build-args: |
32+
HOST=${{ secrets.HOST || '0.0.0.0' }}
33+
PORT=${{ secrets.PORT || '8000' }}
34+
RELOAD=${{ secrets.RELOAD || 'false' }}
35+
tags: |
36+
ghcr.io/${{ github.repository }}:latest
37+
ghcr.io/${{ github.repository }}:${{ github.sha }}
38+
labels: |
39+
org.opencontainers.image.source=${{ github.event.repository.html_url }}
40+
org.opencontainers.image.revision=${{ github.sha }}

Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Use Python 3.9 slim image as base
2+
FROM python:3.9-slim
3+
4+
# Set working directory
5+
WORKDIR /app
6+
7+
# Copy requirements first to leverage Docker cache
8+
COPY requirements.txt .
9+
10+
# Install dependencies
11+
RUN pip install --no-cache-dir -r requirements.txt
12+
13+
# Copy the rest of the application
14+
COPY . .
15+
16+
# Create uploads directory
17+
RUN mkdir -p uploads
18+
19+
# Set default environment variables
20+
ENV HOST=0.0.0.0
21+
ENV PORT=8000
22+
ENV RELOAD=false
23+
ENV FLASK_APP=main.py
24+
ENV FLASK_ENV=production
25+
26+
# Expose the port from .env
27+
EXPOSE 8000
28+
29+
# Run the application
30+
CMD ["python", "main.py"]

0 commit comments

Comments
 (0)