Skip to content

Commit 4b3dd58

Browse files
committed
update docker config and update redis opts for local
1 parent ddda977 commit 4b3dd58

8 files changed

+90
-32
lines changed

.env.example

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
11
POSTGRES_USER=zygdev
2-
POSTGRES_PASSWORD=secure
2+
POSTGRES_PASSWORD=VeryS3cure
33
POSTGRES_DB=zygdb
44
DATABASE_HOST=database:5432
55
DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DATABASE_HOST}/${POSTGRES_DB}
66

7-
REDIS_ADDR=
8-
REDIS_PASS=
7+
REDIS_ADDR=redis:6379
8+
REDIS_USERNAME=zygdev
9+
REDIS_PASSWORD=redispass
10+
REDIS_TLS_ENABLED=0
911

1012
# Get these from Supabase console.
1113
SUPABASE_JWT_SECRET=
1214

1315
# Resend for Email APIs.
1416
RESEND_API_KEY=
1517

16-
# Set this to 1 if you want db queries in logs.
17-
ZYG_DB_QUERY_DEBUG=0
18-
19-
# Main API server port
20-
ZYG_SRV_PORT=8000
21-
22-
# External API server port
23-
ZYG_XSRV_PORT=8080
24-
25-
# Set this to '0' if you don't want db queries in logs.
26-
ZYG_DB_QUERY_DEBUG=0
27-
2818
# Cloudflare AccountID
2919
CF_ACCOUNT_ID=
3020

@@ -33,3 +23,13 @@ R2_ACCESS_KEY_ID=
3323

3424
# Access secret for S3 compat R2 storage
3525
R2_ACCESS_SECRET_KEY=
26+
27+
# Set this to 1 if you want db queries in logs.
28+
ZYG_DB_QUERY_DEBUG=0
29+
30+
# Main API server port
31+
ZYG_SRV_PORT=8080
32+
33+
# External API server port
34+
ZYG_XSRV_PORT=8000
35+

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ go.work
2424
# Secrets or Envs
2525
*.env
2626
*.env.local
27-
.env.yaml
2827
env.sh
28+
env.local.sh
2929

3030

3131
# Python files and directories

backend/cmd/srv/main.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,21 @@ func run(ctx context.Context) error {
5252

5353
slog.Info("database", slog.Any("db time", tm.Format(time.RFC1123)))
5454

55-
rdb := redis.NewClient(&redis.Options{
55+
// Redis options
56+
opts := &redis.Options{
5657
Addr: zyg.RedisAddr(),
5758
Username: zyg.RedisUsername(),
5859
Password: zyg.RedisPassword(),
59-
TLSConfig: &tls.Config{
60+
DB: 0,
61+
}
62+
63+
if zyg.RedisTLSEnabled() {
64+
opts.TLSConfig = &tls.Config{
6065
InsecureSkipVerify: true,
61-
},
62-
DB: 0,
63-
})
66+
}
67+
}
68+
69+
rdb := redis.NewClient(opts)
6470

6571
defer func(rdb *redis.Client) {
6672
err := rdb.Close()

backend/cmd/xsrv/main.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,21 @@ func run(ctx context.Context) error {
5252

5353
slog.Info("database", slog.Any("db time", tm.Format(time.RFC1123)))
5454

55-
rdb := redis.NewClient(&redis.Options{
55+
// Redis options
56+
opts := &redis.Options{
5657
Addr: zyg.RedisAddr(),
5758
Username: zyg.RedisUsername(),
5859
Password: zyg.RedisPassword(),
59-
TLSConfig: &tls.Config{
60+
DB: 0,
61+
}
62+
63+
if zyg.RedisTLSEnabled() {
64+
opts.TLSConfig = &tls.Config{
6065
InsecureSkipVerify: true,
61-
},
62-
DB: 0,
63-
})
66+
}
67+
}
68+
69+
rdb := redis.NewClient(opts)
6470

6571
defer func(rdb *redis.Client) {
6672
err := rdb.Close()

backend/config.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,25 @@ func RedisAddr() string {
9797
}
9898

9999
func RedisUsername() string {
100-
value, ok := os.LookupEnv("REDIS_USER")
100+
value, ok := os.LookupEnv("REDIS_USERNAME")
101101
if !ok {
102102
return "zygdev"
103103
}
104104
return value
105105
}
106106

107107
func RedisPassword() string {
108-
value, ok := os.LookupEnv("REDIS_PASS")
108+
value, ok := os.LookupEnv("REDIS_PASSWORD")
109109
if !ok {
110110
return ""
111111
}
112112
return value
113113
}
114+
115+
func RedisTLSEnabled() bool {
116+
enabled, err := strconv.ParseBool(os.Getenv("REDIS_TLS_ENABLED"))
117+
if err != nil {
118+
return false
119+
}
120+
return enabled
121+
}

backend/srv.DockerFile

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
FROM golang:1.23 AS builder
22

3-
ARG ZYG_SRV_PORT=5000
3+
ARG ZYG_SRV_PORT=8080
44
ARG DATABASE_URL
5+
ARG REDIS_ADDR
6+
ARG REDIS_PASSWORD
7+
ARG REDIS_TLS_ENABLED=0
58
ARG SUPABASE_JWT_SECRET
69
ARG RESEND_API_KEY
10+
ARG CF_ACCOUNT_ID
11+
ARG R2_ACCESS_KEY_ID
12+
ARG R2_ACCESS_SECRET_KEY
713
ARG ZYG_DB_QUERY_DEBUG=0
814

915
WORKDIR /usr/src/app
@@ -19,15 +25,21 @@ COPY . .
1925
RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o server ./cmd/srv/main.go
2026

2127
# Build the runtime container image from scratch, copying what is needed from the previous stage.
22-
FROM alpine
28+
FROM alpine:3.21
2329

2430
# Copy the binary to the production image from the builder stage.
2531
COPY --from=builder /usr/src/app/server /usr/local/bin/server
2632

2733
ENV ZYG_SRV_PORT=${ZYG_SRV_PORT}
2834
ENV DATABASE_URL=${DATABASE_URL}
35+
ENV REDIS_ADDR=${REDIS_ADDR}
36+
ENV REDIS_USERNAME=${REDIS_USERNAME}
37+
ENV REDIS_TLS_ENABLED=${REDIS_TLS_ENABLED}
2938
ENV SUPABASE_JWT_SECRET=${SUPABASE_JWT_SECRET}
3039
ENV RESEND_API_KEY=${RESEND_API_KEY}
40+
ENV CF_ACCOUNT_ID=${CF_ACCOUNT_ID}
41+
ENV R2_ACCESS_KEY_ID=${R2_ACCESS_KEY_ID}
42+
ENV R2_ACCESS_SECRET_KEY=${R2_ACCESS_SECRET_KEY}
3143
ENV ZYG_DB_QUERY_DEBUG=${ZYG_DB_QUERY_DEBUG}
3244

3345
EXPOSE ${ZYG_SRV_PORT}

backend/xsrv.DockerFile

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ FROM golang:1.23 AS builder
22

33
ARG ZYG_XSRV_PORT=8000
44
ARG DATABASE_URL
5+
ARG REDIS_ADDR
6+
ARG REDIS_PASSWORD
7+
ARG REDIS_TLS_ENABLED=0
58
ARG SUPABASE_JWT_SECRET
69
ARG RESEND_API_KEY
10+
ARG CF_ACCOUNT_ID
11+
ARG R2_ACCESS_KEY_ID
12+
ARG R2_ACCESS_SECRET_KEY
713
ARG ZYG_DB_QUERY_DEBUG=0
814

915
WORKDIR /usr/src/app
@@ -19,15 +25,21 @@ COPY . .
1925
RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o server ./cmd/xsrv/main.go
2026

2127
# Build the runtime container image from scratch, copying what is needed from the previous stage.
22-
FROM alpine
28+
FROM alpine:3.21
2329

2430
# Copy the binary to the production image from the builder stage.
2531
COPY --from=builder /usr/src/app/server /usr/local/bin/server
2632

27-
ENV ZYG_XSRV_PORT=${ZYG_XSRV_PORT}
33+
ENV ZYG_SRV_PORT=${ZYG_SRV_PORT}
2834
ENV DATABASE_URL=${DATABASE_URL}
35+
ENV REDIS_ADDR=${REDIS_ADDR}
36+
ENV REDIS_USERNAME=${REDIS_USERNAME}
37+
ENV REDIS_TLS_ENABLED=${REDIS_TLS_ENABLED}
2938
ENV SUPABASE_JWT_SECRET=${SUPABASE_JWT_SECRET}
3039
ENV RESEND_API_KEY=${RESEND_API_KEY}
40+
ENV CF_ACCOUNT_ID=${CF_ACCOUNT_ID}
41+
ENV R2_ACCESS_KEY_ID=${R2_ACCESS_KEY_ID}
42+
ENV R2_ACCESS_SECRET_KEY=${R2_ACCESS_SECRET_KEY}
3143
ENV ZYG_DB_QUERY_DEBUG=${ZYG_DB_QUERY_DEBUG}
3244

3345
EXPOSE ${ZYG_XSRV_PORT}

docker-compose.yml

+14
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ services:
1919
ports:
2020
- "5432:5432"
2121

22+
redis:
23+
container_name: redis
24+
image: redis
25+
restart: always
26+
command: redis-server --requirepass ${REDIS_PASSWORD} --user ${REDIS_USERNAME} on '>${REDIS_PASSWORD}' '~*' allcommands
27+
env_file: .env
28+
networks:
29+
- stack
30+
ports:
31+
- "6379:6379"
32+
2233
srv:
2334
container_name: srv
2435
build:
@@ -33,6 +44,7 @@ services:
3344
restart: always
3445
depends_on:
3546
- database
47+
- redis
3648
env_file: .env
3749
networks:
3850
- stack
@@ -53,8 +65,10 @@ services:
5365
restart: always
5466
depends_on:
5567
- database
68+
- redis
5669
env_file: .env
5770
networks:
5871
- stack
5972
ports:
6073
- "${ZYG_XSRV_PORT}:${ZYG_XSRV_PORT}"
74+

0 commit comments

Comments
 (0)