Skip to content

Commit 1fb6fdf

Browse files
merge pull request #1 from felipeversiane/concurrency
dev
2 parents 14529ee + a985e8e commit 1fb6fdf

File tree

7 files changed

+66
-39
lines changed

7 files changed

+66
-39
lines changed

build/api/Dockerfile

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
FROM golang:1.22-alpine3.20 as builder
1+
FROM golang:1.22-alpine3.20 AS builder
2+
3+
RUN apk add --no-cache upx
24

35
WORKDIR /app
46

7+
COPY go.mod go.sum ./
8+
RUN go mod download
9+
510
COPY . .
611

7-
RUN go get -d -v ./...
12+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o /app/api ./cmd/api/main.go
813

9-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o api ./cmd/api/main.go
14+
RUN upx --ultra-brute -qq /app/api && upx -t /app/api
1015

1116
FROM scratch
1217

13-
WORKDIR /
18+
COPY --from=builder /app/api /api
1419

15-
COPY --from=builder /app/api ./
20+
ENTRYPOINT ["/api"]
1621

17-
ENTRYPOINT ["./api"]

build/db/Dockerfile

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
FROM postgres:13.14-alpine
2-
3-
COPY ./build/db/init.sh /docker-entrypoint-initdb.d/
4-
5-
RUN chmod +x /docker-entrypoint-initdb.d/init.sh
1+
FROM postgres:13.14-alpine

build/db/init.sh

-21
This file was deleted.

nginx.conf conf/nginx/nginx.conf

File renamed without changes.

conf/postgres/postgresql.conf

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
listen_addresses = '*'
2+
max_connections = 300
3+
superuser_reserved_connections = 3
4+
unix_socket_directories = '/var/run/postgresql'
5+
shared_buffers = 512MB
6+
work_mem = 8MB
7+
maintenance_work_mem = 256MB
8+
effective_cache_size = 1GB
9+
wal_buffers = 64MB
10+
synchronous_commit = on
11+
fsync = on
12+
full_page_writes = on
13+
checkpoint_timeout = 10min
14+
checkpoint_completion_target = 0.9
15+
random_page_cost = 4.0
16+
effective_io_concurrency = 2
17+
autovacuum = on
18+
log_statement = 'mod'
19+
log_duration = off
20+
log_lock_waits = on
21+
log_error_verbosity = terse
22+
log_min_messages = error
23+
log_min_error_statement = error
24+
log_min_duration_statement = 1000ms

conf/redis/redis.conf

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
save ""
2+
3+
appendonly no
4+
appendfsync no
5+
stop-writes-on-bgsave-error no
6+
rdbcompression no
7+
rdbchecksum no
8+
rdb-save-incremental-fsync no
9+
aof-rewrite-incremental-fsync no
10+
bind 0.0.0.0
11+
maxmemory-samples 2
12+
activerehashing no
13+
dynamic-hz yes
14+
tcp-keepalive 300
15+
always-show-logo yes
16+
rdb-save-incremental-fsync no

docker-compose.yaml

+15-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ services:
1414
dockerfile: build/db/Dockerfile
1515
volumes:
1616
- local_postgres_data:/var/lib/postgresql/data
17+
- ./conf/postgres/:/docker-entrypoint-initdb.d/
1718
ports:
1819
- "5432:5432"
1920
networks:
@@ -24,11 +25,16 @@ services:
2425
timeout: 5s
2526
retries: 3
2627
start_period: 20s
28+
command:
29+
[
30+
"postgres",
31+
"-c","config_file=/docker-entrypoint-initdb.d/postgresql.conf",
32+
]
2733
deploy:
2834
resources:
2935
limits:
30-
cpus: '0.4'
31-
memory: '0.4GB'
36+
cpus: '1.0'
37+
memory: '1GB'
3238

3339
migrate:
3440
image: migrate/migrate
@@ -50,19 +56,21 @@ services:
5056
cache:
5157
container_name: rd02
5258
image: redis:latest
53-
command: redis-server --save "" --appendonly no
5459
environment:
5560
REDIS_HOST: cache
5661
REDIS_PORT: 6379
5762
REDIS_PASSWORD: ""
5863
ports:
5964
- "6379:6379"
65+
volumes:
66+
- ./conf/redis/:/etc/redis/
67+
command: ["redis-server", "/etc/redis/redis.conf"]
6068
networks:
6169
- golangnetwork
6270
deploy:
6371
resources:
6472
limits:
65-
cpus: '0.1'
73+
cpus: '0.3'
6674
memory: '0.5GB'
6775

6876
api:
@@ -88,16 +96,16 @@ services:
8896
deploy:
8997
resources:
9098
limits:
91-
cpus: '0.1'
92-
memory: '0.1GB'
99+
cpus: '0.3'
100+
memory: '0.15GB'
93101

94102
nginx:
95103
image: nginx:latest
96104
container_name: nx02
97105
ports:
98106
- "80:80"
99107
volumes:
100-
- ./nginx.conf:/etc/nginx/nginx.conf:ro
108+
- ./conf/nginx/:/etc/nginx/
101109
depends_on:
102110
- api
103111
networks:

0 commit comments

Comments
 (0)