Skip to content

Commit bb7cbf6

Browse files
committed
feat: [KAN-102] user_profile & user_address
1 parent c2e6344 commit bb7cbf6

36 files changed

+2304
-50
lines changed

.github/ci/docker-compose.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,26 @@ services:
1010
networks:
1111
ci-net:
1212
aliases:
13-
- mysql-container # 别名,Go 通过这个名字连接 MySQL
13+
- mysql-container
1414

15+
kafka:
16+
image: confluentinc/cp-kafka:7.5.0
17+
container_name: kafka-container
18+
ports:
19+
- "9092:9092"
20+
environment:
21+
CLUSTER_ID: ohAxBaI7QUuIq7lQBYzRYA
22+
command: >
23+
bash -c "
24+
if [ ! -f /var/lib/kafka/data/meta.properties ]; then
25+
kafka-storage format -t $$CLUSTER_ID -c /etc/kafka/kraft/server.properties;
26+
fi &&
27+
kafka-server-start /etc/kafka/kraft/server.properties
28+
"
29+
networks:
30+
ci-net:
31+
aliases:
32+
- kafka-container
1533
ceramicraft-user-mservice:
1634
build:
1735
context: ../../server
@@ -24,11 +42,12 @@ services:
2442
- JWT_SECRET=${JWT_SECRET}
2543
depends_on:
2644
- mysql
45+
- kafka
2746
networks:
2847
- ci-net
2948
ports:
3049
- "8080:8080" # 只给宿主机(ZAP)用
31-
command: ["sh", "-c", "apt-get update && apt-get install -y netcat-openbsd && chmod +x /app/wait-for.sh && ./wait-for.sh mysql-container 3306 ./main"]
50+
command: ["sh", "-c", "apk add --no-cache netcat-openbsd && chmod +x /app/wait-for.sh && ./wait-for.sh mysql-container 3306 ./main"]
3251
volumes:
3352
- ./wait-for.sh:/app/wait-for.sh # CI 专用配置
3453
user: root

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
name: env-file
3838
path: env-file
3939
build:
40-
if: ${{ github.event.inputs.command == 'deploy' }} # ← 仅在 deploy 时构建
40+
if: ${{ github.event.inputs.command == 'deploy' }}
4141
runs-on: ubuntu-latest
4242
env:
4343
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}

.github/workflows/zap.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ jobs:
4242
- name: Build and run Docker Compose
4343
run: |
4444
docker compose -f .github/ci/docker-compose.yml --env-file env-file up --build -d
45-
timeout 180 bash -c 'until [ "$(docker compose -f .github/ci/docker-compose.yml ps ceramicraft-user-mservice --format json | jq -r .Health)" = "healthy" ]; do sleep 2; done'
45+
timeout 180 bash -c 'until curl -f http://localhost:8080/user-ms/v1/ping; do sleep 2; done'
4646
- name: Check Docker Compose Logs
47-
if: failure()
47+
if: always()
4848
run: |
49-
docker compose -f .github/ci/docker-compose.yml logs
49+
docker compose -f .github/ci/docker-compose.yml ps ceramicraft-user-mservice
50+
docker compose -f .github/ci/docker-compose.yml logs ceramicraft-user-mservice
5051
- name: Run ZAP Scan
5152
uses: zaproxy/action-full-scan@75ee1686750ab1511a73b26b77a2aedd295053ed
5253
with:

server/Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use the official Go image with version 1.24
2-
FROM golang:1.24.0
2+
FROM golang:1.24.0-alpine AS builder
33

44
# Set the working directory inside the container
55
WORKDIR /app
@@ -14,10 +14,12 @@ RUN go mod tidy
1414
COPY . .
1515

1616
# Build the Go application
17-
RUN go build -ldflags="-s -w" -o main main.go
17+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
18+
go build -a -ldflags="-w -s" -o main main.go && \
19+
go clean -cache -modcache
1820

1921
# Create a non-root user and set permissions
20-
RUN useradd -m appuser && \
22+
RUN adduser -D -h /home/appuser appuser && \
2123
mkdir -p logs && \
2224
chown -R appuser:appuser config/ && \
2325
chown -R appuser:appuser logs/ && \

server/config/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Conf struct {
1616
HttpConfig *HttpConfig `mapstructure:"http"`
1717
MySQLConfig *MySQL `mapstructure:"mysql"`
1818
EmailConfig *EmailConfig `mapstructure:"email"`
19+
KafkaConfig *KafkaConfig `mapstructure:"kafka"`
1920
}
2021

2122
type EmailConfig struct {
@@ -49,6 +50,16 @@ type MySQL struct {
4950
DBName string `mapstructure:"dbName"`
5051
}
5152

53+
type KafkaConfig struct {
54+
Brokers []string `mapstructure:"brokers"`
55+
UserActivatedTopic string `mapstructure:"user_activated_topic"`
56+
MaxBytes int `mapstructure:"max_bytes"`
57+
Acks int `mapstructure:"acks"`
58+
Retries int `mapstructure:"retries"`
59+
BatchSize int `mapstructure:"batch_size"`
60+
BatchTimeoutMillis int `mapstructure:"batch_timeout_millis"`
61+
}
62+
5263
func Init() {
5364
workDir, _ := os.Getwd()
5465
viper.SetConfigName("config")

0 commit comments

Comments
 (0)