ci: publish docker image to ghcr
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
STEAM_CHAT_IMAGE=steam-chat:latest
|
||||
STEAM_CHAT_IMAGE=ghcr.io/tursom/steam-chat:latest
|
||||
STEAM_CHAT_CONTAINER_NAME=steam-chat
|
||||
STEAM_CHAT_BIND=0.0.0.0
|
||||
STEAM_CHAT_PORT=3000
|
||||
|
||||
67
.github/workflows/docker-publish.yml
vendored
Normal file
67
.github/workflows/docker-publish.yml
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
name: Docker image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
tags:
|
||||
- "v*.*.*"
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build and publish
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: Normalize image name
|
||||
id: image
|
||||
shell: bash
|
||||
run: |
|
||||
image="${REGISTRY}/${GITHUB_REPOSITORY}"
|
||||
echo "name=${image,,}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Extract Docker metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v6
|
||||
with:
|
||||
images: ${{ steps.image.outputs.name }}
|
||||
tags: |
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
type=ref,event=branch
|
||||
type=ref,event=tag
|
||||
type=sha,prefix=sha-
|
||||
|
||||
- name: Log in to GitHub Container Registry
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Build and publish image
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
@@ -1,6 +1,6 @@
|
||||
services:
|
||||
steam-chat:
|
||||
image: ${STEAM_CHAT_IMAGE:-steam-chat:latest}
|
||||
image: ${STEAM_CHAT_IMAGE:-ghcr.io/tursom/steam-chat:latest}
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
|
||||
@@ -16,23 +16,32 @@ docker compose up -d --build
|
||||
|
||||
需要新增或调整:
|
||||
|
||||
- `compose.yaml`
|
||||
- `docker-compose.yaml`
|
||||
- `.env.example`
|
||||
- `Dockerfile`
|
||||
- `.dockerignore`
|
||||
- `.gitignore`
|
||||
- `.github/workflows/docker-publish.yml`
|
||||
- 后台改造文档中约定的数据目录和健康检查接口
|
||||
|
||||
Compose 文件使用本地源码构建镜像,同时设置固定镜像名,避免只有 `image` 而没有 `build` 时 `docker compose up --build` 仍尝试拉取远端镜像。
|
||||
GitHub Actions 在 `master` 分支、`v*.*.*` 标签和手动触发时构建 Docker 镜像;非 PR 事件会推送到 GitHub Container Registry。
|
||||
|
||||
默认镜像名:
|
||||
|
||||
```text
|
||||
ghcr.io/tursom/steam-chat:latest
|
||||
```
|
||||
|
||||
Compose 文件保留本地源码构建能力,同时设置固定 GHCR 镜像名,避免只有 `image` 而没有 `build` 时 `docker compose up --build` 仍尝试拉取远端镜像。
|
||||
|
||||
## Compose 服务定义
|
||||
|
||||
目标 `compose.yaml`:
|
||||
目标 `docker-compose.yaml`:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
steam-chat:
|
||||
image: ${STEAM_CHAT_IMAGE:-steam-chat:latest}
|
||||
image: ${STEAM_CHAT_IMAGE:-ghcr.io/tursom/steam-chat:latest}
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
@@ -85,7 +94,7 @@ sudo chown -R 1000:1000 data
|
||||
`.env.example`:
|
||||
|
||||
```dotenv
|
||||
STEAM_CHAT_IMAGE=steam-chat:latest
|
||||
STEAM_CHAT_IMAGE=ghcr.io/tursom/steam-chat:latest
|
||||
STEAM_CHAT_CONTAINER_NAME=steam-chat
|
||||
STEAM_CHAT_BIND=0.0.0.0
|
||||
STEAM_CHAT_PORT=3000
|
||||
@@ -207,10 +216,17 @@ http://服务器地址:3000
|
||||
|
||||
```bash
|
||||
git pull
|
||||
docker compose up -d --build
|
||||
docker compose pull
|
||||
docker compose up -d
|
||||
docker compose ps
|
||||
```
|
||||
|
||||
如果要在服务器上用当前源码重新构建,而不是拉取 GHCR 镜像,继续使用:
|
||||
|
||||
```bash
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
查看日志:
|
||||
|
||||
```bash
|
||||
@@ -309,4 +325,3 @@ curl -fsS http://127.0.0.1:${STEAM_CHAT_PORT:-3000}/healthz
|
||||
npm run typecheck
|
||||
npm test
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user