diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..c67b40d --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,45 @@ +name: Deploy to Mac Mini + +on: + push: + branches: + - main + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '1.25' + + - name: Run tests + run: go test ./... -race + + deploy: + name: Deploy + runs-on: ubuntu-latest + needs: test + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Deploy to Mac Mini via SSH + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.DEPLOY_HOST }} + username: ${{ secrets.DEPLOY_USER }} + key: ${{ secrets.DEPLOY_SSH_KEY }} + port: ${{ secrets.DEPLOY_PORT || 22 }} + script: | + cd ${{ secrets.DEPLOY_PATH }} + git pull origin main + docker-compose down + docker-compose up -d --build + docker-compose logs --tail=20 server diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c580529 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# Build stage +FROM golang:1.25-alpine AS builder + +WORKDIR /app + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . +RUN go build -o bin/server ./cmd/server + +# Run stage +FROM alpine:latest + +RUN apk --no-cache add ca-certificates tzdata + +WORKDIR /app + +COPY --from=builder /app/bin/server . +COPY --from=builder /app/config ./config + +EXPOSE 8080 + +CMD ["./server", "-config", "config/config.yaml"] diff --git a/bin/server.exe b/bin/server.exe new file mode 100644 index 0000000..f33dcc7 Binary files /dev/null and b/bin/server.exe differ diff --git a/config/config.go b/config/config.go index 3e766ed..1e0b6ac 100644 --- a/config/config.go +++ b/config/config.go @@ -50,12 +50,12 @@ type AOIConfig struct { } type NetworkConfig struct { - WriteBufferSize int `yaml:"write_buffer_size"` - ReadBufferSize int `yaml:"read_buffer_size"` - SendChannelSize int `yaml:"send_channel_size"` + WriteBufferSize int `yaml:"write_buffer_size"` + ReadBufferSize int `yaml:"read_buffer_size"` + SendChannelSize int `yaml:"send_channel_size"` HeartbeatInterval time.Duration `yaml:"heartbeat_interval"` HeartbeatTimeout time.Duration `yaml:"heartbeat_timeout"` - MaxMessageSize int64 `yaml:"max_message_size"` + MaxMessageSize int64 `yaml:"max_message_size"` } type LogConfig struct { @@ -81,6 +81,23 @@ func Load(path string) (*Config, error) { return nil, fmt.Errorf("parse config file: %w", err) } + // 환경변수로 DB 접속 정보 오버라이드 (Docker 환경용) + if v := os.Getenv("DB_HOST"); v != "" { + cfg.Database.Host = v + } + if v := os.Getenv("DB_PORT"); v != "" { + fmt.Sscanf(v, "%d", &cfg.Database.Port) + } + if v := os.Getenv("DB_USER"); v != "" { + cfg.Database.User = v + } + if v := os.Getenv("DB_PASSWORD"); v != "" { + cfg.Database.Password = v + } + if v := os.Getenv("DB_NAME"); v != "" { + cfg.Database.DBName = v + } + return cfg, nil } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9f206d2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,34 @@ +services: + db: + image: postgres:16-alpine + restart: always + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: mmorpg + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + + server: + build: . + restart: always + ports: + - "8080:8080" + depends_on: + db: + condition: service_healthy + environment: + - DB_HOST=db + - DB_USER=postgres + - DB_PASSWORD=postgres + - DB_NAME=mmorpg + volumes: + - ./config:/app/config + +volumes: + postgres_data: