Skip to content

Commit 7ffa1f3

Browse files
committed
[dev] add local docker compose
1 parent b53e8c3 commit 7ffa1f3

5 files changed

Lines changed: 126 additions & 4 deletions

File tree

Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM golang:1.25-alpine AS builder
2+
3+
WORKDIR /src
4+
5+
COPY go.mod go.sum ./
6+
RUN go mod download
7+
8+
COPY . .
9+
10+
RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/server ./main.go
11+
12+
13+
FROM alpine:latest
14+
15+
# Install certificates and timezone data
16+
RUN apk add --no-cache ca-certificates tzdata
17+
18+
# Create non-root user
19+
RUN addgroup -g 1000 appuser && \
20+
adduser -D -u 1000 -G appuser --home /app appuser
21+
22+
# Set the Current Working Directory inside the container
23+
WORKDIR /app
24+
25+
# Copy the binary file from the previous stage
26+
COPY --from=builder --chown=appuser:appuser /out/server /app/server
27+
28+
USER appuser
29+
30+
# Command to run the executable
31+
ENTRYPOINT ["/app/server"]

docker-compose.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: bit-issues_backend
2+
services:
3+
backend:
4+
build:
5+
context: .
6+
dockerfile: Dockerfile
7+
restart: on-failure
8+
depends_on:
9+
mariadb:
10+
condition: service_healthy
11+
minio-init:
12+
condition: service_completed_successfully
13+
environment:
14+
TZ: ${TIMEZONE:-UTC}
15+
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID:-minioadmin}
16+
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY:-minioadmin}
17+
DATABASE__URL: mariadb://bit-issues:bit-issues@mariadb:3306/bit-issues?charset=utf8mb4&parseTime=True&loc=Local&clientFoundRows=true
18+
HTTP__ADDRESS: 0.0.0.0:3000
19+
JWT__SECRET: ${JWT__SECRET:-secret}
20+
STORAGE__URL: s3://bit-issues/uploads?endpoint=localhost:9000&region=us-east-1&insecure=true
21+
ports:
22+
- "3000:3000"
23+
extra_hosts:
24+
- "localhost:host-gateway"
25+
26+
minio:
27+
image: minio/minio:latest
28+
command: server /data
29+
environment:
30+
TZ: ${TIMEZONE:-UTC}
31+
MINIO_ROOT_USER: ${AWS_ACCESS_KEY_ID:-minioadmin}
32+
MINIO_ROOT_PASSWORD: ${AWS_SECRET_ACCESS_KEY:-minioadmin}
33+
MINIO_REGION_NAME: ${AWS_REGION:-us-east-1}
34+
MINIO_API_CORS_ALLOW_ORIGIN: "*"
35+
healthcheck:
36+
test: ["CMD", "mc", "ready", "local"]
37+
interval: 30s
38+
timeout: 5s
39+
retries: 3
40+
ports:
41+
- "9000:9000"
42+
volumes:
43+
- minio-data:/data
44+
45+
minio-init:
46+
image: minio/mc:latest
47+
depends_on:
48+
minio:
49+
condition: service_healthy
50+
entrypoint: ["/bin/sh", "-c"]
51+
command:
52+
- |
53+
set -eu
54+
echo "waiting for minio..."
55+
until (/usr/bin/mc alias set local http://minio:9000 "$${AWS_ACCESS_KEY_ID:-minioadmin}" "$${AWS_SECRET_ACCESS_KEY:-minioadmin}") >/dev/null 2>&1; do
56+
sleep 1
57+
done
58+
/usr/bin/mc mb --ignore-existing local/bit-issues
59+
echo "minio ready"
60+
environment:
61+
TZ: ${TIMEZONE:-UTC}
62+
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID:-minioadmin}
63+
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY:-minioadmin}
64+
65+
mariadb:
66+
image: mariadb:lts
67+
environment:
68+
TZ: ${TIMEZONE:-UTC}
69+
MARIADB_ROOT_PASSWORD: root
70+
MARIADB_DATABASE: bit-issues
71+
MARIADB_USER: bit-issues
72+
MARIADB_PASSWORD: bit-issues
73+
MARIADB_AUTO_UPGRADE: ON
74+
volumes:
75+
- mariadb-data:/var/lib/mysql
76+
healthcheck:
77+
test:
78+
[
79+
"CMD",
80+
"healthcheck.sh",
81+
"--su-mysql",
82+
"--connect",
83+
"--innodb_initialized",
84+
]
85+
interval: 10s
86+
timeout: 5s
87+
retries: 10
88+
89+
volumes:
90+
mariadb-data:
91+
minio-data:

internal/storage/module.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func Module() fx.Option {
2222
return miniofx.Config{
2323
Endpoint: u.Query().Get("endpoint"),
2424
Region: u.Query().Get("region"),
25+
Secure: u.Query().Get("insecure") != "true",
2526
}, nil
2627
}),
2728
fx.Provide(NewService),

pkg/miniofx/client.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ import (
88
)
99

1010
func NewClient(config Config) (*minio.Client, error) {
11-
endpoint := config.Endpoint
12-
13-
client, err := minio.New(endpoint, &minio.Options{
11+
client, err := minio.New(config.Endpoint, &minio.Options{
1412
Creds: credentials.NewEnvAWS(),
15-
Secure: true,
13+
Secure: config.Secure,
1614
Region: config.Region,
1715
})
1816
if err != nil {

pkg/miniofx/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ package miniofx
33
type Config struct {
44
Endpoint string
55
Region string
6+
Secure bool
67
}

0 commit comments

Comments
 (0)