Skip to content

Commit 17760b4

Browse files
Merge pull request #18 from DoWithLogic/cicd/build-on-docker
chore: add docker to build apps on docker compose
2 parents b613d98 + 5b4e4ab commit 17760b4

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

Dockerfile

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

config/config-local.yaml.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Server:
99
WriteTimeOut: 5s
1010

1111
Database:
12-
Host: localhost
12+
Host: mysql-db
1313
Port: 3306
1414
Name: users
1515
User: mysql

docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,14 @@ services:
1717
interval: 0.5s
1818
timeout: 10s
1919
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

makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ wait-for-mysql:
2424
@echo "MySQL is up and running!"
2525

2626
database-up:
27-
docker compose up -d
27+
docker compose up mysql-db -d
2828

29-
database-down:
29+
service-up:
30+
docker compose up golang-clean-architecture -d
31+
32+
docker-down:
3033
docker compose down
3134

3235
migration-up: wait-for-mysql
@@ -36,12 +39,9 @@ migration-down:
3639
GOOSE_DRIVER=mysql GOOSE_DBSTRING="mysql:pwd@tcp(localhost:3306)/users?parseTime=true" goose -dir=$(MIGRATION_DIR) down
3740

3841

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
4343

44-
down : migration-down database-down
44+
down : migration-down docker-down
4545

4646
mock-repository:
4747
mockgen -source internal/users/repository/repository.go -destination internal/users/mock/repository_mock.go -package=mocks

0 commit comments

Comments
 (0)