Skip to content

Commit cdd9da6

Browse files
author
chendelin1982
committed
dev for story1
1 parent c239576 commit cdd9da6

File tree

23 files changed

+1091
-272
lines changed

23 files changed

+1091
-272
lines changed

.env.dev

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Development Environment Configuration
2+
# Used with: make dev-up && go run core/cmd/server/main.go
3+
4+
SERVER_ENV=development
5+
APP_PROFILE=default
6+
7+
# Database Configuration (connects to Docker postgres)
8+
POSTGRES_HOST=localhost
9+
POSTGRES_PORT=5432
10+
POSTGRES_USER=apprun
11+
POSTGRES_PASSWORD=dev_password_123
12+
POSTGRES_DB=apprun_dev
13+
14+
# Redis Configuration (connects to Docker redis)
15+
REDIS_HOST=localhost
16+
REDIS_PORT=6379
17+
REDIS_PASSWORD=
18+
19+
# Server Configuration
20+
SERVER_PORT=8080
21+
SERVER_HOST=0.0.0.0
22+
23+
# TLS Configuration (optional for dev)
24+
SSL_CERT_FILE=
25+
SSL_KEY_FILE=
26+
27+
# JWT Configuration
28+
JWT_SECRET=dev-jwt-secret-change-in-production
29+
JWT_EXPIRY=24h
30+
31+
# Encryption Key (for sensitive data)
32+
ENCRYPTION_KEY=dev-encryption-key-32-chars!!
33+
34+
# Logging
35+
LOG_LEVEL=debug
36+
LOG_FORMAT=text
37+
38+
# CORS
39+
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://localhost:8080

.env.prod.example

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Production Environment Configuration Template
2+
# Copy this file to .env.prod and update all <CHANGE_ME> values
3+
# Usage: docker-compose -f docker-compose.prod.yml up -d
4+
5+
SERVER_ENV=production
6+
APP_PROFILE=production
7+
8+
# Database Configuration (internal Docker network)
9+
POSTGRES_HOST=postgres
10+
POSTGRES_PORT=5432
11+
POSTGRES_USER=apprun
12+
POSTGRES_PASSWORD=<CHANGE_ME_STRONG_PASSWORD>
13+
POSTGRES_DB=apprun_prod
14+
15+
# Redis Configuration (internal Docker network)
16+
REDIS_HOST=redis
17+
REDIS_PORT=6379
18+
REDIS_PASSWORD=<CHANGE_ME_REDIS_PASSWORD>
19+
20+
# Server Configuration
21+
SERVER_PORT=8080
22+
SERVER_HOST=0.0.0.0
23+
24+
# External Port Mapping
25+
APP_HTTP_PORT=8080
26+
APP_HTTPS_PORT=8443
27+
28+
# TLS Configuration (required for HTTPS)
29+
SSL_CERT_FILE=/etc/ssl/certs/server.crt
30+
SSL_KEY_FILE=/etc/ssl/private/server.key
31+
SSL_CERT_PATH=./ssl/server.crt
32+
SSL_KEY_PATH=./ssl/server.key
33+
34+
# JWT Configuration
35+
JWT_SECRET=<CHANGE_ME_RANDOM_64_CHAR_STRING>
36+
JWT_EXPIRY=24h
37+
38+
# Encryption Key (must be 32 characters)
39+
ENCRYPTION_KEY=<CHANGE_ME_EXACTLY_32_CHARACTERS>
40+
41+
# Logging
42+
LOG_LEVEL=info
43+
LOG_FORMAT=json
44+
45+
# CORS (comma-separated domains)
46+
CORS_ALLOWED_ORIGINS=https://yourdomain.com
47+
48+
# Health Check
49+
HEALTH_CHECK_PATH=/health
50+
51+
# Database Pool
52+
DB_MAX_OPEN_CONNS=25
53+
DB_MAX_IDLE_CONNS=5
54+
DB_CONN_MAX_LIFETIME=5m
55+
56+
# Redis Pool
57+
REDIS_POOL_SIZE=10
58+
REDIS_MIN_IDLE_CONNS=5

.github/copilot-instructions.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ You can also mention agents directly in your messages:
4040
- Workflow configurations: `.bmad/bmm/workflows/`
4141
- Project documentation: `docs/`
4242
- Sprint artifacts: `docs/sprint-artifacts/`
43+
- Coding standards: `docs/standards/coding-standards.md`
44+
- Testing standards: `docs/standards/testing-standards.md`
45+
- API design standards: `docs/standards/api-design.md`

.github/workflows/docker-build.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Docker Build and Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop
8+
tags:
9+
- 'v*'
10+
pull_request:
11+
branches:
12+
- main
13+
14+
env:
15+
REGISTRY: ghcr.io
16+
IMAGE_NAME: ${{ github.repository }}
17+
18+
jobs:
19+
build-and-push:
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
packages: write
24+
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3
31+
32+
- name: Log in to GitHub Container Registry
33+
if: github.event_name != 'pull_request'
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Extract metadata
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
45+
tags: |
46+
type=ref,event=branch
47+
type=ref,event=pr
48+
type=semver,pattern={{version}}
49+
type=semver,pattern={{major}}.{{minor}}
50+
type=semver,pattern={{major}}
51+
type=sha,prefix={{branch}}-
52+
type=raw,value=latest,enable={{is_default_branch}}
53+
54+
- name: Build and push Docker image
55+
uses: docker/build-push-action@v5
56+
with:
57+
context: .
58+
file: ./docker/Dockerfile
59+
push: ${{ github.event_name != 'pull_request' }}
60+
tags: ${{ steps.meta.outputs.tags }}
61+
labels: ${{ steps.meta.outputs.labels }}
62+
cache-from: type=gha
63+
cache-to: type=gha,mode=max
64+
platforms: linux/amd64,linux/arm64
65+
66+
- name: Image digest
67+
if: github.event_name != 'pull_request'
68+
run: echo "Image digest: ${{ steps.build.outputs.digest }}"
69+
70+
- name: Create release summary
71+
if: startsWith(github.ref, 'refs/tags/v')
72+
run: |
73+
echo "## 🚀 Docker Image Published" >> $GITHUB_STEP_SUMMARY
74+
echo "" >> $GITHUB_STEP_SUMMARY
75+
echo "**Tag:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
76+
echo "**Registry:** ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" >> $GITHUB_STEP_SUMMARY
77+
echo "" >> $GITHUB_STEP_SUMMARY
78+
echo "### 📦 Pull the image:" >> $GITHUB_STEP_SUMMARY
79+
echo '```bash' >> $GITHUB_STEP_SUMMARY
80+
echo "docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
81+
echo '```' >> $GITHUB_STEP_SUMMARY

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ go.work.sum
2626

2727
# env file
2828
.env
29+
.env.prod
30+
31+
# SSL certificates
32+
ssl/
33+
*.key
34+
*.crt
35+
*.pem
36+
*.csr
2937

3038
# Editor/IDE
3139
# .idea/

Makefile

Lines changed: 96 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
11
# apprun Makefile
22

3-
.PHONY: help build test test-all test-unit test-integration test-e2e clean docker-build docker-up docker-down validate-stories sync-index
3+
.PHONY: help build test test-all test-unit test-integration test-e2e clean docker-build docker-up docker-down validate-stories sync-index dev-up dev-down run-local build-local test-local prod-up-local prod-down-local
44

55
# 默认目标
66
help:
77
@echo "Available targets:"
8+
@echo ""
9+
@echo "Build & Test:"
810
@echo " build - Build the application"
911
@echo " test-all - Run all tests"
1012
@echo " test-unit - Run unit tests"
11-
@echo " test-unit-html - Run unit tests with HTML coverage report"
12-
@echo " test-unit-setup- Setup unit test environment"
13-
@echo " test-unit-run - Run unit tests via script"
1413
@echo " test-integration - Run integration tests"
1514
@echo " test-e2e - Run end-to-end tests"
15+
@echo ""
16+
@echo "Development Environment (Story 1):"
17+
@echo " dev-up - Start dev dependencies (postgres + redis)"
18+
@echo " dev-down - Stop dev dependencies"
19+
@echo " run-local - Run app locally with go run"
20+
@echo " build-local - Build Docker image locally"
21+
@echo " test-local - Run integration tests with local image"
22+
@echo " prod-up-local - Start production-like environment locally"
23+
@echo " prod-down-local- Stop local production environment"
24+
@echo ""
25+
@echo "Docker:"
1626
@echo " docker-build - Build Docker images"
1727
@echo " docker-up - Start Docker services"
1828
@echo " docker-down - Stop Docker services"
29+
@echo ""
30+
@echo "Documentation:"
1931
@echo " validate-stories - Validate all Story documents"
2032
@echo " sync-index - Sync global Stories index"
33+
@echo ""
2134
@echo " clean - Clean build artifacts"
2235

2336
# 构建
@@ -62,10 +75,10 @@ docker-build:
6275
cd docker && docker compose build
6376

6477
docker-up:
65-
cd docker && docker compose up -d
78+
docker compose up -d
6679

6780
docker-down:
68-
cd docker && docker compose down
81+
docker compose down
6982

7083
# 清理
7184
clean:
@@ -100,4 +113,80 @@ validate-stories:
100113
sync-index:
101114
@echo "🔄 Syncing global Stories index..."
102115
@./scripts/sync-story-index.sh
103-
@echo "✅ Global Stories index synced"
116+
@echo "✅ Global Stories index synced"
117+
118+
# ============================================
119+
# Story 1: Development Environment Commands
120+
# ============================================
121+
122+
# Start development dependencies only (postgres + redis)
123+
dev-up:
124+
@echo "🚀 Starting development dependencies..."
125+
@docker compose -f docker-compose.dev.yml up -d
126+
@echo "✅ Development dependencies ready!"
127+
@echo ""
128+
@echo "📊 Services:"
129+
@echo " PostgreSQL: localhost:5432 (user: apprun, password: dev_password_123)"
130+
@echo " Redis: localhost:6379"
131+
@echo ""
132+
@echo "💡 Next step: Run your app locally"
133+
@echo " go run core/cmd/server/main.go"
134+
135+
# Stop development dependencies
136+
dev-down:
137+
@echo "🛑 Stopping development dependencies..."
138+
@docker compose -f docker-compose.dev.yml down
139+
@echo "✅ Development dependencies stopped"
140+
141+
# Run app locally (assumes dev-up is running)
142+
run-local:
143+
@echo "🏃 Running app locally..."
144+
@echo "📌 Make sure dependencies are running: make dev-up"
145+
@echo ""
146+
cd core && go run ./cmd/server/main.go
147+
148+
# Build Docker image locally
149+
build-local:
150+
@echo "🔨 Building Docker image locally..."
151+
@docker build -t apprun:local -f docker/Dockerfile .
152+
@echo "✅ Docker image built: apprun:local"
153+
@echo ""
154+
@docker images apprun:local
155+
156+
# Run integration tests with local build
157+
test-local: build-local
158+
@echo "🧪 Running integration tests..."
159+
@docker compose -f docker-compose.local.yml up -d
160+
@echo "⏳ Waiting for services to be ready..."
161+
@sleep 15
162+
@echo "🔍 Checking health..."
163+
@docker exec apprun-app-local wget -q -O- http://localhost:8080/health || (echo "❌ Health check failed" && docker compose -f docker-compose.local.yml down && exit 1)
164+
@echo "✅ Integration tests passed!"
165+
@docker compose -f docker-compose.local.yml down
166+
167+
# Start production-like environment locally
168+
prod-up-local:
169+
@echo "🚀 Starting production-like environment locally..."
170+
@docker compose -f docker-compose.local.yml up -d
171+
@echo "✅ Local production environment started!"
172+
@echo ""
173+
@echo "🔗 Access:"
174+
@echo " HTTP: http://localhost:8080"
175+
@echo " HTTPS: https://localhost:8443"
176+
@echo ""
177+
@echo "📊 View logs:"
178+
@echo " docker compose -f docker-compose.local.yml logs -f"
179+
180+
# Stop local production environment
181+
prod-down-local:
182+
@echo "🛑 Stopping local production environment..."
183+
@docker compose -f docker-compose.local.yml down
184+
@echo "✅ Local production environment stopped"
185+
186+
# Clean all Docker resources
187+
clean-docker:
188+
@echo "🧹 Cleaning Docker resources..."
189+
@docker compose -f docker-compose.dev.yml down -v
190+
@docker compose -f docker-compose.local.yml down -v
191+
@docker rmi apprun:local 2>/dev/null || true
192+
@echo "✅ Docker resources cleaned"

0 commit comments

Comments
 (0)