File tree Expand file tree Collapse file tree 4 files changed +45
-8
lines changed Expand file tree Collapse file tree 4 files changed +45
-8
lines changed Original file line number Diff line number Diff line change
1
+ # Build stage
2
+ FROM golang:1.20-alpine as builder
3
+
4
+ WORKDIR /app
5
+
6
+ COPY go.mod .
7
+ COPY go.sum .
8
+ RUN go mod download
9
+
10
+ COPY . .
11
+
12
+ RUN GO111MODULE=on go mod tidy
13
+
14
+ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags musl --ldflags "-extldflags -static" -a -o golang-clean-architecture cmd/api/main.go
15
+
16
+ # deploy
17
+ FROM alpine
18
+
19
+ RUN apk add --no-cache tzdata
20
+
21
+ WORKDIR /app
22
+
23
+ COPY --from=builder /app/golang-clean-architecture .
24
+ COPY --from=builder /app/config .
25
+
26
+ CMD ["./golang-clean-architecture" ]
Original file line number Diff line number Diff line change 9
9
WriteTimeOut: 5s
10
10
11
11
Database:
12
- Host: localhost
12
+ Host: mysql-db
13
13
Port: 3306
14
14
Name: users
15
15
User: mysql
Original file line number Diff line number Diff line change @@ -17,3 +17,14 @@ services:
17
17
interval : 0.5s
18
18
timeout : 10s
19
19
retries : 10
20
+ golang-clean-architecture :
21
+ build :
22
+ context : .
23
+ dockerfile : Dockerfile # Specify the path to your Dockerfile
24
+ ports :
25
+ - 8080:8080
26
+ - 9090:9090
27
+ volumes :
28
+ - ./config/config-local.yaml:/app/config/config-local.yaml
29
+ depends_on :
30
+ - mysql-db
Original file line number Diff line number Diff line change @@ -24,9 +24,12 @@ wait-for-mysql:
24
24
@echo " MySQL is up and running!"
25
25
26
26
database-up :
27
- docker compose up -d
27
+ docker compose up mysql-db -d
28
28
29
- database-down :
29
+ service-up :
30
+ docker compose up golang-clean-architecture -d
31
+
32
+ docker-down :
30
33
docker compose down
31
34
32
35
migration-up : wait-for-mysql
@@ -36,12 +39,9 @@ migration-down:
36
39
GOOSE_DRIVER=mysql GOOSE_DBSTRING=" mysql:pwd@tcp(localhost:3306)/users?parseTime=true" goose -dir=$(MIGRATION_DIR ) down
37
40
38
41
39
- local :
40
- env=" local" go run cmd/main.go
41
-
42
- run : database-up migration-up local
42
+ run : database-up migration-up service-up
43
43
44
- down : migration-down database -down
44
+ down : migration-down docker -down
45
45
46
46
mock-repository :
47
47
mockgen -source internal/users/repository/repository.go -destination internal/users/mock/repository_mock.go -package=mocks
You can’t perform that action at this time.
0 commit comments