Skip to content

Commit 7934bc0

Browse files
committed
ci cd and docker
1 parent e91fed2 commit 7934bc0

11 files changed

Lines changed: 983 additions & 72 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 128 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,128 @@
1-
# name: CI
2-
3-
# on:
4-
# pull_request:
5-
# branches:
6-
# - "*"
7-
# push:
8-
# branches:
9-
# - prod
10-
# - main
11-
# - master
12-
# - dev
13-
# env:
14-
# GO_VERSION: "1.24.x"
15-
# NODE_VERSION: "24"
16-
17-
# jobs:
18-
# test:
19-
# runs-on: ubuntu-latest
20-
# steps:
21-
# - uses: actions/checkout@v4
22-
23-
# - name: Setup Go
24-
# uses: actions/setup-go@v5
25-
# with:
26-
# go-version: ${{ env.GO_VERSION }}
27-
28-
# - name: Setup Node
29-
# uses: actions/setup-node@v4
30-
# with:
31-
# node-version: ${{ env.NODE_VERSION }}
32-
# cache: 'npm'
33-
34-
# - name: Install dependencies
35-
# run: npm install
36-
37-
# - name: Run tests
38-
# run: npm test
39-
40-
# - name: Run Go tests
41-
# run: go test ./...
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "*"
7+
push:
8+
branches:
9+
- prod
10+
- main
11+
- master
12+
- dev
13+
14+
env:
15+
GO_VERSION: "1.25.x"
16+
NODE_VERSION: "24"
17+
18+
jobs:
19+
go-server:
20+
name: Go Server CI
21+
runs-on: ubuntu-latest
22+
defaults:
23+
run:
24+
working-directory: ./apps/server
25+
26+
services:
27+
postgres:
28+
image: postgres:18
29+
env:
30+
POSTGRES_USER: coderz-space
31+
POSTGRES_PASSWORD: coderz-space
32+
POSTGRES_DB: coderz
33+
ports:
34+
- 5432:5432
35+
options: >-
36+
--health-cmd pg_isready
37+
--health-interval 10s
38+
--health-timeout 5s
39+
--health-retries 5
40+
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
45+
- name: Setup Go
46+
uses: actions/setup-go@v5
47+
with:
48+
go-version: ${{ env.GO_VERSION }}
49+
cache-dependency-path: apps/server/go.sum
50+
51+
- name: Install dependencies
52+
run: go mod download
53+
54+
- name: Verify dependencies
55+
run: go mod verify
56+
57+
- name: Run go vet
58+
run: go vet ./...
59+
60+
- name: Install staticcheck
61+
run: go install honnef.co/go/tools/cmd/staticcheck@latest
62+
63+
- name: Run staticcheck
64+
run: staticcheck ./...
65+
66+
- name: Install golangci-lint
67+
uses: golangci/golangci-lint-action@v6
68+
with:
69+
version: latest
70+
working-directory: apps/server
71+
args: --timeout=5m
72+
73+
- name: Setup test environment
74+
run: |
75+
cp .env .env.test
76+
echo "DB_URL=postgresql://coderz-space:coderz-space@localhost:5432/coderz?sslmode=disable" >> .env.test
77+
echo "DB_DSN=postgresql://coderz-space:coderz-space@localhost:5432/coderz?sslmode=disable" >> .env.test
78+
79+
- name: Run migrations
80+
run: |
81+
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
82+
migrate -path ./db/migrations -database "postgresql://coderz-space:coderz-space@localhost:5432/coderz?sslmode=disable" up
83+
84+
- name: Run tests
85+
env:
86+
DB_URL: postgresql://coderz-space:coderz-space@localhost:5432/coderz?sslmode=disable
87+
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
88+
89+
- name: Upload coverage
90+
uses: codecov/codecov-action@v5
91+
with:
92+
files: ./apps/server/coverage.out
93+
flags: go-server
94+
fail_ci_if_error: false
95+
96+
- name: Build binary
97+
run: go build -v -o bin/main ./cmd/main.go
98+
99+
- name: Install swag
100+
run: go install github.com/swaggo/swag/cmd/swag@latest
101+
102+
- name: Generate Swagger docs
103+
run: swag init -o ./swagger --parseDependency --parseInternal -g cmd/main.go
104+
105+
- name: Verify Swagger docs
106+
run: test -f swagger/swagger.json && test -f swagger/swagger.yaml
107+
108+
docker-build:
109+
name: Docker Build
110+
runs-on: ubuntu-latest
111+
needs: go-server
112+
113+
steps:
114+
- name: Checkout code
115+
uses: actions/checkout@v4
116+
117+
- name: Set up Docker Buildx
118+
uses: docker/setup-buildx-action@v3
119+
120+
- name: Build Docker image
121+
uses: docker/build-push-action@v6
122+
with:
123+
context: ./apps/server
124+
file: ./apps/server/dockerfile
125+
push: false
126+
tags: coderz-space-server:${{ github.sha }}
127+
cache-from: type=gha
128+
cache-to: type=gha,mode=max

apps/server/.dockerignore

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# Environment
6+
.env
7+
.env.*
8+
!.env.example
9+
10+
# Build artifacts
11+
bin/
12+
*.exe
13+
*.exe~
14+
*.dll
15+
*.so
16+
*.dylib
17+
*.test
18+
coverage.out
19+
*.coverprofile
20+
21+
# Documentation
22+
README.md
23+
*.md
24+
!swagger/*.md
25+
26+
# CI/CD
27+
.github/
28+
.gitlab-ci.yml
29+
30+
# IDE
31+
.vscode/
32+
.idea/
33+
*.iml
34+
35+
# Logs
36+
logs/
37+
*.log
38+
39+
# Docker
40+
dockerfile
41+
.dockerignore
42+
docker-compose.yml
43+
44+
# Temporary files
45+
*.tmp
46+
*.swp
47+
*.swo
48+
.DS_Store
49+
Thumbs.db
50+
51+
# Test files (optional - uncomment if you don't want tests in image)
52+
# *_test.go

apps/server/.env.example

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1+
# Server Configuration
12
PORT=8080
23
FRONTEND_ORIGIN=http://localhost:3000
34
ENVIRONMENT=development
4-
JWT_SECRET=j3QE2U6eBQj8EvRUnhPF2Sf2YuChgfhgfjhg0JMeSVWDNO138RYMj3QE2U6eBQj8EvRUnhPF2Sf2YuC0JMeSVWDNO138RYMj3QE2U6eBQj8EvRUnhPF2Sf2YuC0JMeSVWDNO138RYM
5-
JWT_EXPIRES=1h # 1 hour
5+
APP_NAME=Coderz_Space
6+
VERSION=0.1.0
7+
8+
# JWT Configuration
9+
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
10+
JWT_EXPIRES=1h
11+
12+
# Logging Configuration
613
LOG_LEVEL=info
714
FILE_LOG_LEVEL=info
8-
APP_NAME=Coderz_Space
915

10-
VERSION=0.1.0
16+
# Database Configuration
17+
# Local development (with Docker Compose)
18+
DB_URL=postgresql://coderz-space:coderz-space@localhost:5432/coderz?sslmode=disable
19+
DB_DSN=postgresql://coderz-space:coderz-space@postgres:5432/coderz?sslmode=disable
1120

12-
# Database config
13-
DB_URL=db_connectinon_url
21+
# Database Connection Pool
1422
MAX_DB_CONNS=10
1523
MIN_DB_CONNS=2
1624
MAX_DB_CONN_LIFETIME=1h
1725
MAX_DB_CONN_IDLE_TIME=30m
18-

apps/server/.golangci.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
run:
2+
timeout: 5m
3+
tests: true
4+
modules-download-mode: readonly
5+
6+
linters:
7+
enable:
8+
- errcheck
9+
- gosimple
10+
- govet
11+
- ineffassign
12+
- staticcheck
13+
- unused
14+
- gofmt
15+
- goimports
16+
- misspell
17+
- unconvert
18+
- unparam
19+
- gosec
20+
- gocritic
21+
22+
linters-settings:
23+
errcheck:
24+
check-type-assertions: true
25+
check-blank: true
26+
27+
govet:
28+
enable-all: true
29+
disable:
30+
- shadow
31+
32+
gofmt:
33+
simplify: true
34+
35+
gosec:
36+
excludes:
37+
- G404 # Use of weak random number generator (math/rand instead of crypto/rand)
38+
39+
gocritic:
40+
enabled-tags:
41+
- diagnostic
42+
- style
43+
- performance
44+
45+
issues:
46+
exclude-rules:
47+
- path: _test\.go
48+
linters:
49+
- errcheck
50+
- gosec
51+
- path: cmd/main\.go
52+
linters:
53+
- errcheck
54+
max-issues-per-linter: 0
55+
max-same-issues: 0

0 commit comments

Comments
 (0)