File tree Expand file tree Collapse file tree 5 files changed +34
-9
lines changed Expand file tree Collapse file tree 5 files changed +34
-9
lines changed Original file line number Diff line number Diff line change 1- FROM golang:1.22.0 as builder
1+ # Step 1: Build Stage
2+ FROM golang:1.23.0 AS builder
23
34WORKDIR /app
45
@@ -8,14 +9,29 @@ RUN go mod download
89
910COPY . .
1011
11- RUN CGO_ENABLED=0 GOOS=linux go build -o /api ./cmd/main.go
12+ RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /api ./cmd/main.go
13+ RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /migrate ./cmd/migrate/main.go
1214
15+ COPY cmd/migrate/migrations /app/migrations
16+
17+ # Step 2: Runtime Stage
1318FROM alpine:3.14
1419
1520WORKDIR /
1621
22+ # ✅ Install required runtime dependencies
23+ RUN apk --no-cache add ca-certificates
24+
25+ # Copy binaries from build stage
1726COPY --from=builder /api /api
27+ COPY --from=builder /migrate /migrate
28+ RUN mkdir -p /cmd/migrate/migrations
29+ COPY --from=builder /app/cmd/migrate/migrations /cmd/migrate/migrations
30+
31+ # Copy entrypoint script and make executable
32+ COPY entrypoint.sh /entrypoint.sh
33+ RUN chmod +x /entrypoint.sh
1834
1935EXPOSE 8080
2036
21- CMD ["/api " ]
37+ ENTRYPOINT ["/entrypoint.sh " ]
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ This repository demonstrates the implementation of a RESTful API in Go with inte
77
88## Prerequisites
99
10- - ** Go Version** : Requires [ Go 1.22 .0] ( https://golang.org/dl/ ) or higher.
10+ - ** Go Version** : Requires [ Go 1.23 .0] ( https://golang.org/dl/ ) or higher.
1111
1212## Dependencies
1313
Original file line number Diff line number Diff line change @@ -2,14 +2,15 @@ version: '3.8'
22
33services :
44 postgres :
5- image : postgres:latest
5+ image : postgres:14
6+ platform : linux/amd64
67 container_name : postgres_db
78 ports :
89 - " 5432:5432"
910 environment :
10- POSTGRES_USER : ${DB_USER}
11- POSTGRES_PASSWORD : ${DB_PASSWORD}
12- POSTGRES_DB : ${DB_NAME}
11+ POSTGRES_USER : user
12+ POSTGRES_PASSWORD : password
13+ POSTGRES_DB : app
1314 volumes :
1415 - postgres_data:/var/lib/postgresql/data
1516 restart : always
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+
3+ echo " Running database migrations..."
4+ /migrate up # ✅ Use the prebuilt migrate binary
5+
6+ echo " Starting API..."
7+ exec /api # ✅ Ensure API runs as the main process
Original file line number Diff line number Diff line change 11module go-sample-rest-api
22
3- go 1.22.0
3+ go 1.23.0
4+
45toolchain go1.24.1
56
67require (
You can’t perform that action at this time.
0 commit comments