feat: docker buildx.
Some checks failed
Build and Push Docker Image / buildx (push) Has been cancelled
Some checks failed
Build and Push Docker Image / buildx (push) Has been cancelled
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
.DS_Store
|
||||
|
||||
node_modules/
|
||||
.git/
|
||||
node_modules
|
||||
.git
|
||||
.github
|
||||
|
||||
Dockerfile
|
||||
.gitignore
|
||||
.dockerignore
|
||||
|
||||
*.md
|
||||
|
||||
data.db
|
||||
|
||||
52
.github/workflows/docker-buildx.yml
vendored
Normal file
52
.github/workflows/docker-buildx.yml
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
name: Build and Push Docker Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- 'v*'
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
buildx:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to DockerHub
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Extract metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
${{ secrets.DOCKERHUB_USERNAME || 'username' }}/timeline-calendar
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=ref,event=pr
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
14
Dockerfile
14
Dockerfile
@@ -1,12 +1,22 @@
|
||||
FROM node:25-alpine
|
||||
|
||||
FROM node:25-alpine AS base
|
||||
WORKDIR /app
|
||||
|
||||
# Dependencies stage
|
||||
FROM base AS deps
|
||||
COPY package*.json ./
|
||||
RUN npm install --production
|
||||
|
||||
# Production stage
|
||||
FROM base AS production
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
# Create a non-root user
|
||||
RUN addgroup -g 1001 -S nodejs
|
||||
RUN adduser -S nextjs -u 1001
|
||||
|
||||
USER nextjs
|
||||
|
||||
CMD ["node", "server.js"]
|
||||
|
||||
23
README.md
23
README.md
@@ -26,6 +26,29 @@ npm start
|
||||
|
||||
> 如需自定义端口,运行前设定 `PORT=xxxx` 即可。
|
||||
|
||||
## 🚀 Docker Buildx 支持
|
||||
|
||||
本项目现在支持使用 Docker Buildx 构建多平台镜像,并可推送至 Docker Hub。
|
||||
|
||||
### 使用 GitHub Actions 自动构建和推送
|
||||
|
||||
1. 在 GitHub 仓库中设置以下 secrets:
|
||||
- `DOCKERHUB_USERNAME` - 你的 Docker Hub 用户名
|
||||
- `DOCKERHUB_TOKEN` - 你的 Docker Hub 访问令牌
|
||||
|
||||
2. 推送代码到 main 分支或创建版本标签,GitHub Actions 将自动构建并推送镜像。
|
||||
|
||||
### 手动构建和推送
|
||||
|
||||
```bash
|
||||
# 设置 buildx
|
||||
docker buildx create --name mybuilder --use
|
||||
docker buildx inspect --bootstrap
|
||||
|
||||
# 构建并推送多平台镜像
|
||||
docker buildx build --platform linux/amd64,linux/arm64 -t yourusername/timeline-calendar:latest --push .
|
||||
```
|
||||
|
||||
## 🧭 使用指南
|
||||
1. **添加服务器**:页面底部输入想连接的后端地址,点击「添加」,并从下拉框选择它
|
||||
2. **注册 / 登录**:按提示填写信息,完成后即可自动加载个人日历
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
services:
|
||||
Timeline:
|
||||
build: .
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
platforms:
|
||||
- linux/amd64
|
||||
- linux/arm64
|
||||
image: registry.cn-beijing.aliyuncs.com/licsber/timeline:latest
|
||||
ports:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
@@ -8,5 +14,4 @@ services:
|
||||
- JWT_SECRET=${JWT_SECRET:-change-this-secret-key-in-production}
|
||||
volumes:
|
||||
- ./data.db:/app/data.db
|
||||
- ./public:/app/public
|
||||
restart: unless-stopped
|
||||
|
||||
Reference in New Issue
Block a user