Skip to content

Commit 3f40977

Browse files
authored
Merge pull request #77 from ozgen/fix_ci_pipieline
Fix ci pipeline
2 parents dd17aeb + a93bc00 commit 3f40977

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

Dockerfile

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM golang:1.22.0 as builder
1+
# Step 1: Build Stage
2+
FROM golang:1.23.0 AS builder
23

34
WORKDIR /app
45

@@ -8,14 +9,29 @@ RUN go mod download
89

910
COPY . .
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
1318
FROM alpine:3.14
1419

1520
WORKDIR /
1621

22+
# ✅ Install required runtime dependencies
23+
RUN apk --no-cache add ca-certificates
24+
25+
# Copy binaries from build stage
1726
COPY --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

1935
EXPOSE 8080
2036

21-
CMD ["/api"]
37+
ENTRYPOINT ["/entrypoint.sh"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

docker/docker-compose.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ version: '3.8'
22

33
services:
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

entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module go-sample-rest-api
22

3-
go 1.22.0
3+
go 1.23.0
4+
45
toolchain go1.24.1
56

67
require (

0 commit comments

Comments
 (0)