Skip to content

Commit 425a8e4

Browse files
committed
feat: 添加 Docker 健康检查,创建 Docker 发布工作流
1 parent 880da35 commit 425a8e4

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ images
88
public/images/**
99
!public/images/.gitkeep
1010
!public/images/**/.gitkeep
11+
.tmp-uploads/
12+
.playwright-mcp/
13+
*.png
14+
!public/images/**/*.png
15+
.github
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
jobs:
9+
build-and-push:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Docker Buildx
17+
uses: docker/setup-buildx-action@v3
18+
19+
- name: Log in to Docker Hub
20+
uses: docker/login-action@v3
21+
with:
22+
username: ${{ secrets.DOCKERHUB_USERNAME }}
23+
password: ${{ secrets.DOCKERHUB_TOKEN }}
24+
25+
- name: Build and push Docker image
26+
uses: docker/build-push-action@v6
27+
with:
28+
context: .
29+
push: true
30+
tags: |
31+
${{ secrets.DOCKERHUB_USERNAME }}/nyaovo-random-image-api:latest
32+
cache-from: type=gha
33+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ RUN mkdir -p /app/public/images && chown -R node:node /app
1212
USER node
1313

1414
EXPOSE 3000
15+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
16+
CMD wget -qO- http://localhost:3000/image/health || exit 1
1517
CMD ["npm", "start"]

0 commit comments

Comments
 (0)