mirror of
https://ids-dev.idsbuybuybuy.com/ids-ecommerce/ids-svc-product.git
synced 2026-11-29 16:57:41 +08:00
feat(docker): add Dockerfile and CI workflow for building and deploying ids-svc-product
This commit is contained in:
parent
1573e7393b
commit
d088ef2d75
14
.dockerignore
Normal file
14
.dockerignore
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
.git
|
||||||
|
**/.git
|
||||||
|
**/.DS_Store
|
||||||
|
**/.env
|
||||||
|
**/.env.*
|
||||||
|
!**/.env.example
|
||||||
|
|
||||||
|
ids-svc-product/docs
|
||||||
|
ids-svc-product/.gitea
|
||||||
|
ids-svc-product/docker-compose.yaml
|
||||||
|
ids-svc-product/**/*_test.go
|
||||||
|
|
||||||
|
ids-proto/docs
|
||||||
|
ids-proto/.git
|
||||||
84
.gitea/workflows/ci.yml
Normal file
84
.gitea/workflows/ci.yml
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
name: Build & Deploy
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- multi-tenant
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
IMAGE: ids-dev.idsbuybuybuy.com/ids-ecommerce/ids-svc-product
|
||||||
|
IMAGE_TAG: ${{ gitea.sha }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout Product
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
path: ids-svc-product
|
||||||
|
|
||||||
|
- name: Checkout Proto
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: ids-ecommerce/ids-proto
|
||||||
|
ref: multi-tenant
|
||||||
|
path: ids-proto
|
||||||
|
token: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
- name: Prepare Docker ignorefile
|
||||||
|
run: cp ids-svc-product/.dockerignore .dockerignore
|
||||||
|
|
||||||
|
- name: Login Registry
|
||||||
|
run: |
|
||||||
|
echo "${{ secrets.REGISTRY_TOKEN }}" | \
|
||||||
|
docker login ids-dev.idsbuybuybuy.com \
|
||||||
|
-u "${{ secrets.REGISTRY_USER }}" \
|
||||||
|
--password-stdin
|
||||||
|
|
||||||
|
- name: Build Image
|
||||||
|
run: |
|
||||||
|
docker build \
|
||||||
|
-f ids-svc-product/Dockerfile \
|
||||||
|
-t "${IMAGE}:${IMAGE_TAG}" \
|
||||||
|
.
|
||||||
|
|
||||||
|
- name: Push Image
|
||||||
|
run: |
|
||||||
|
docker push "${IMAGE}:${IMAGE_TAG}"
|
||||||
|
|
||||||
|
- name: Configure SSH
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
chmod 700 ~/.ssh
|
||||||
|
|
||||||
|
printf '%s\n' "${{ secrets.DEPLOY_SSH_KEY }}" \
|
||||||
|
> ~/.ssh/ids_deploy
|
||||||
|
|
||||||
|
chmod 600 ~/.ssh/ids_deploy
|
||||||
|
|
||||||
|
ssh-keyscan -H "${{ secrets.DEPLOY_HOST }}" \
|
||||||
|
>> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
- name: Deploy
|
||||||
|
run: |
|
||||||
|
ssh \
|
||||||
|
-i ~/.ssh/ids_deploy \
|
||||||
|
"${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \
|
||||||
|
"
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd /opt/ids-ecommerce
|
||||||
|
|
||||||
|
sed -i \
|
||||||
|
's/^IDS_SVC_PRODUCT_TAG=.*/IDS_SVC_PRODUCT_TAG=${IMAGE_TAG}/' \
|
||||||
|
.env
|
||||||
|
|
||||||
|
docker compose pull ids-svc-product
|
||||||
|
|
||||||
|
docker compose up -d ids-svc-product
|
||||||
|
|
||||||
|
docker ps \
|
||||||
|
--filter name=ids-svc-product \
|
||||||
|
--format 'table {{.Names}}\t{{.Image}}\t{{.Status}}'
|
||||||
|
"
|
||||||
33
Dockerfile
Normal file
33
Dockerfile
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
# Build from the parent directory that contains both ids-svc-product/ and ids-proto/:
|
||||||
|
# docker build -f ids-svc-product/Dockerfile -t ids-svc-product:local .
|
||||||
|
#
|
||||||
|
# go.mod replace points at ../ids-proto, so both trees must be present in the context.
|
||||||
|
|
||||||
|
FROM golang:1.26.4-alpine AS builder
|
||||||
|
|
||||||
|
RUN apk add --no-cache ca-certificates git
|
||||||
|
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
COPY ids-proto /src/ids-proto
|
||||||
|
COPY ids-svc-product/go.mod ids-svc-product/go.sum /src/ids-svc-product/
|
||||||
|
|
||||||
|
WORKDIR /src/ids-svc-product
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
COPY ids-svc-product/ /src/ids-svc-product/
|
||||||
|
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/ids-svc-product ./cmd
|
||||||
|
|
||||||
|
FROM alpine:3.21
|
||||||
|
|
||||||
|
RUN apk add --no-cache ca-certificates tzdata \
|
||||||
|
&& adduser -D -H -u 10001 appuser
|
||||||
|
|
||||||
|
COPY --from=builder /out/ids-svc-product /usr/local/bin/ids-svc-product
|
||||||
|
|
||||||
|
USER appuser
|
||||||
|
|
||||||
|
EXPOSE 50052 9102
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/local/bin/ids-svc-product"]
|
||||||
23
README.md
23
README.md
@ -190,11 +190,34 @@ ids-svc-product/
|
|||||||
├── docs/
|
├── docs/
|
||||||
│ ├── ARCHITECTURE.md # 架构白皮书
|
│ ├── ARCHITECTURE.md # 架构白皮书
|
||||||
│ └── DEVELOPMENT.md # 开发规约与 AI 生成指令
|
│ └── DEVELOPMENT.md # 开发规约与 AI 生成指令
|
||||||
|
├── Dockerfile # 生产镜像(需与 ids-proto 同级 context)
|
||||||
├── .env.example
|
├── .env.example
|
||||||
├── go.mod
|
├── go.mod
|
||||||
└── AGENTS.md
|
└── AGENTS.md
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## CI / Deploy(Gitea Actions)
|
||||||
|
|
||||||
|
`multi-tenant` 推送触发 [`.gitea/workflows/ci.yml`](.gitea/workflows/ci.yml):构建并推送镜像,再 SSH 滚动远端 compose。
|
||||||
|
|
||||||
|
本地/CI 构建(context 必须同时包含 `ids-svc-product/` 与 `ids-proto/`):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 在两仓的父目录执行
|
||||||
|
cp ids-svc-product/.dockerignore .dockerignore
|
||||||
|
docker build -f ids-svc-product/Dockerfile \
|
||||||
|
-t ids-dev.idsbuybuybuy.com/ids-ecommerce/ids-svc-product:<sha> \
|
||||||
|
.
|
||||||
|
```
|
||||||
|
|
||||||
|
**Gitea Secrets(建议配在组织级):** `REGISTRY_USER`、`REGISTRY_TOKEN`、`DEPLOY_SSH_KEY`、`DEPLOY_HOST`、`DEPLOY_USER`。
|
||||||
|
|
||||||
|
**远端 `/opt/ids-ecommerce` 前置(本仓不维护):**
|
||||||
|
|
||||||
|
- `.env` 含 `IDS_SVC_PRODUCT_TAG=` 行(流水线用 `sed` 替换为 `${{ gitea.sha }}`)
|
||||||
|
- `docker compose` 服务名 `ids-svc-product`,镜像引用该 tag
|
||||||
|
- Runner 可 `checkout` 同实例仓库 `ids-ecommerce/ids-proto`
|
||||||
|
|
||||||
## 快速开始
|
## 快速开始
|
||||||
|
|
||||||
### 前置依赖
|
### 前置依赖
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user