Skip to content

Commit 7054a27

Browse files
committed
docker
1 parent 88e6174 commit 7054a27

File tree

5 files changed

+43
-13
lines changed

5 files changed

+43
-13
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ A production-ready template for modern web applications using **The Modern Go St
7878
git clone https://github.com/dunamismax/go-web-server.git
7979
cd go-web-server
8080

81+
# Create your environment file
82+
cp .env.example .env
83+
# Edit .env with your database credentials (DATABASE_USER, DATABASE_PASSWORD, etc.)
84+
8185
# Start all services (PostgreSQL + App + Caddy)
8286
docker compose up --build
8387

@@ -95,6 +99,10 @@ git clone https://github.com/dunamismax/go-web-server.git
9599
cd go-web-server
96100
go mod tidy
97101

102+
# Create your environment file
103+
cp .env.example .env
104+
# Edit .env with your database credentials (DATABASE_USER, DATABASE_PASSWORD, etc.)
105+
98106
# Install development tools and dependencies
99107
mage setup
100108

docker-compose.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ services:
55
container_name: gowebserver-postgres
66
restart: unless-stopped
77
environment:
8-
POSTGRES_USER: user
9-
POSTGRES_PASSWORD: password
10-
POSTGRES_DB: gowebserver
8+
POSTGRES_USER: ${DATABASE_USER}
9+
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
10+
POSTGRES_DB: ${DATABASE_NAME}
1111
POSTGRES_HOST_AUTH_METHOD: md5
1212
volumes:
1313
- postgres_data:/var/lib/postgresql/data
1414
- ./internal/store/migrations:/docker-entrypoint-initdb.d
1515
healthcheck:
16-
test: ["CMD-SHELL", "pg_isready -U user -d gowebserver"]
16+
test: ["CMD-SHELL", "pg_isready -U ${DATABASE_USER} -d ${DATABASE_NAME}"]
1717
interval: 10s
1818
timeout: 5s
1919
retries: 5
@@ -34,7 +34,7 @@ services:
3434
environment:
3535
# Database configuration
3636
DATABASE_DRIVER: postgres
37-
DATABASE_URL: postgres://user:password@postgres:5432/gowebserver?sslmode=disable
37+
DATABASE_URL: postgres://${DATABASE_USER}:${DATABASE_PASSWORD}@postgres:5432/${DATABASE_NAME}?sslmode=disable
3838

3939
# Server configuration
4040
HTTP_HOST: 0.0.0.0

docs/architecture.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,11 @@ Build → Single binary with embedded assets
152152
## Monitoring Architecture
153153

154154
**Request Tracing:**
155+
155156
- Unique ID per request with structured logging
156157

157158
**Metrics Collection:**
159+
158160
- HTTP request metrics (duration, status, method)
159161
- Database connection and query metrics
160162
- Business metrics (user operations)

docs/development.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Local development setup and workflow for the Modern Go Stack.
99
git clone https://github.com/dunamismax/go-web-server.git
1010
cd go-web-server
1111

12+
# Create your environment file
13+
cp .env.example .env
14+
# Edit .env with your database credentials (DATABASE_USER, DATABASE_PASSWORD, etc.)
15+
1216
# Install tools and dependencies
1317
mage setup
1418

@@ -129,13 +133,16 @@ func (h *UserHandler) CreateUser(c echo.Context) error {
129133

130134
## Configuration
131135

132-
**Development environment variables:**
136+
**Development environment variables (.env file):**
133137

134138
```bash
135139
APP_ENVIRONMENT=development
136140
APP_DEBUG=true
137141
SERVER_PORT=8080
138-
DATABASE_URL=postgres://user:password@localhost:5432/gowebserver?sslmode=disable
142+
DATABASE_USER=your_username
143+
DATABASE_PASSWORD=your_password
144+
DATABASE_NAME=gowebserver
145+
DATABASE_URL=postgres://your_username:your_password@localhost:5432/gowebserver?sslmode=disable
139146
FEATURES_ENABLE_METRICS=true
140147
```
141148

@@ -144,11 +151,11 @@ FEATURES_ENABLE_METRICS=true
144151
**Database:**
145152

146153
```bash
147-
# Connect to PostgreSQL in Docker
148-
docker exec -it gowebserver-postgres psql -U user -d gowebserver
154+
# Connect to PostgreSQL in Docker (replace with your credentials)
155+
docker exec -it gowebserver-postgres psql -U ${DATABASE_USER} -d ${DATABASE_NAME}
149156

150-
# Or using local psql client
151-
psql postgres://user:password@localhost:5432/gowebserver
157+
# Or using local psql client with your credentials from .env
158+
psql postgres://${DATABASE_USER}:${DATABASE_PASSWORD}@localhost:5432/${DATABASE_NAME}
152159

153160
# Common commands
154161
\dt # List tables

docs/docker.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ The application uses a multi-service Docker architecture:
1717
git clone https://github.com/dunamismax/go-web-server.git
1818
cd go-web-server
1919

20+
# Create your environment file
21+
cp .env.example .env
22+
# Edit .env with your database credentials (DATABASE_USER, DATABASE_PASSWORD, etc.)
23+
2024
# Start all services
2125
docker compose up --build
2226

@@ -31,7 +35,7 @@ open http://localhost:8080 # Direct application access
3135

3236
- **Image**: `postgres:16-alpine`
3337
- **Port**: 5432 (exposed in development)
34-
- **Credentials**: user/password (change in production)
38+
- **Credentials**: Configured via .env file environment variables
3539
- **Volume**: `postgres_data` for data persistence
3640
- **Migrations**: Auto-applied on container startup
3741

@@ -102,6 +106,10 @@ docker compose --env-file .env.production up -d
102106
### Local Development
103107

104108
```bash
109+
# Create your environment file
110+
cp .env.example .env
111+
# Edit .env with your database credentials
112+
105113
# Start database only
106114
docker compose up postgres -d
107115

@@ -202,6 +210,7 @@ docker network inspect gowebserver-network
202210
### Common Issues
203211

204212
**Application won't start:**
213+
205214
```bash
206215
# Check dependencies
207216
docker compose ps
@@ -212,6 +221,7 @@ docker exec gowebserver-postgres pg_isready -U user
212221
```
213222

214223
**Caddy SSL issues:**
224+
215225
```bash
216226
# Check domain DNS
217227
nslookup yourdomain.com
@@ -224,6 +234,7 @@ curl -I http://yourdomain.com
224234
```
225235

226236
**Database connection issues:**
237+
227238
```bash
228239
# Check PostgreSQL logs
229240
docker compose logs postgres
@@ -235,6 +246,7 @@ docker exec -it gowebserver-postgres psql -U user -d gowebserver -c "SELECT 1;"
235246
### Performance Optimization
236247

237248
**Database tuning in docker-compose.yml:**
249+
238250
```yaml
239251
postgres:
240252
environment:
@@ -244,6 +256,7 @@ postgres:
244256
```
245257
246258
**Application scaling:**
259+
247260
```bash
248261
docker compose up -d --scale app=3
249262
```
@@ -330,4 +343,4 @@ gunzip -c backup_20240101_120000.sql.gz | docker exec -i gowebserver-postgres ps
330343
docker compose up -d app caddy
331344
```
332345

333-
This Docker-first architecture provides a robust, scalable, and secure foundation for deploying the Go Web Server in any environment.
346+
This Docker-first architecture provides a robust, scalable, and secure foundation for deploying the Go Web Server in any environment.

0 commit comments

Comments
 (0)