Skip to content

Commit 4ebf3a2

Browse files
committed
feat: add production Dockerfile and CI/CD workflow for automated image builds
1 parent 3c55f57 commit 4ebf3a2

File tree

4 files changed

+96
-17
lines changed

4 files changed

+96
-17
lines changed
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name: Docker Build and Push
1+
name: Docker Build and Push Base
22

33
on:
44
push:
5-
tags: ["v*.*.*"]
5+
tags: ["base-*"]
66

77
env:
88
# Use docker.io for Docker Hub if empty
@@ -53,20 +53,19 @@ jobs:
5353
with:
5454
images: ${{ env.IMAGE_NAME }}
5555
tags: |
56-
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
57-
type=semver,pattern={{version}}
58-
type=sha
56+
type=raw,value=base-latest
57+
type=ref,event=tag
5958
6059
- name: Build and push Docker image
6160
id: build-and-push
6261
uses: docker/build-push-action@v5
6362
with:
6463
context: .
65-
# Ensure the downloaded file is included in the context
64+
file: ./Dockerfile.base
6665
push: ${{ github.event_name != 'pull_request' }}
6766
tags: ${{ steps.meta.outputs.tags }}
6867
labels: ${{ steps.meta.outputs.labels }}
69-
cache-from: type=gha
70-
cache-to: type=gha,mode=max
68+
cache-from: type=gha,scope=base
69+
cache-to: type=gha,mode=max,scope=base
7170
# Important: we found this platform works best
7271
platforms: linux/amd64
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Docker Build and Push Prod
2+
3+
on:
4+
push:
5+
tags: ["prod-*"]
6+
7+
env:
8+
# Use docker.io for Docker Hub if empty
9+
REGISTRY: docker.io
10+
# github.repository as <account>/<repo>
11+
IMAGE_NAME: enzii/deepseek-ocr2-service
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
# The image is ~16GB, so we need to free up space on the runner
25+
- name: Free Disk Space (Ubuntu)
26+
uses: jlumbroso/free-disk-space@main
27+
with:
28+
# This might take a few minutes to run, but is necessary for large images
29+
tool-cache: false
30+
android: true
31+
dotnet: true
32+
haskell: true
33+
large-packages: true
34+
docker-images: true
35+
swap-storage: true
36+
37+
- name: Set up QEMU
38+
uses: docker/setup-qemu-action@v3
39+
40+
- name: Set up Docker Buildx
41+
uses: docker/setup-buildx-action@v3
42+
43+
- name: Log into Docker Hub
44+
if: github.event_name != 'pull_request'
45+
uses: docker/login-action@v3
46+
with:
47+
username: ${{ secrets.DOCKER_USERNAME }}
48+
password: ${{ secrets.DOCKER_PASSWORD }}
49+
50+
- name: Extract Docker metadata
51+
id: meta
52+
uses: docker/metadata-action@v5
53+
with:
54+
images: ${{ env.IMAGE_NAME }}
55+
tags: |
56+
type=raw,value=latest
57+
type=match,pattern=prod-(.*),group=1
58+
type=sha
59+
60+
- name: Build and push Docker image
61+
id: build-and-push
62+
uses: docker/build-push-action@v5
63+
with:
64+
context: .
65+
file: ./Dockerfile.prod
66+
build-args: |
67+
BASE_IMAGE=${{ env.IMAGE_NAME }}:base-latest
68+
push: ${{ github.event_name != 'pull_request' }}
69+
tags: ${{ steps.meta.outputs.tags }}
70+
labels: ${{ steps.meta.outputs.labels }}
71+
cache-from: type=gha,scope=prod
72+
cache-to: type=gha,mode=max,scope=prod
73+
# Important: we found this platform works best
74+
platforms: linux/amd64

Dockerfile renamed to Dockerfile.base

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,3 @@ COPY requirements.txt install.sh ./
3838
# Make install script executable and run it
3939
# This script installs PyTorch, vLLM, and other requirements
4040
RUN chmod +x install.sh && ./install.sh
41-
42-
# Copy the rest of the application code
43-
COPY . .
44-
45-
# Expose the API port
46-
EXPOSE 8000
47-
48-
# Default command to run the FastAPI server
49-
CMD ["python3", "serve_pdf.py"]

Dockerfile.prod

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Use the base image that contains all dependencies
2+
# Build the base image first with: docker build -t dpsk-ocr2-base -f Dockerfile.base .
3+
ARG BASE_IMAGE=dpsk-ocr2-base:latest
4+
FROM ${BASE_IMAGE}
5+
6+
WORKDIR /app
7+
8+
# Copy the rest of the application code
9+
COPY . .
10+
11+
# Expose the API port
12+
EXPOSE 8000
13+
14+
# Default command to run the FastAPI server
15+
CMD ["python3", "serve_pdf.py"]

0 commit comments

Comments
 (0)