Skip to content

Commit f6e932f

Browse files
committed
rework directory structure
1 parent 66bc193 commit f6e932f

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

.goreleaser.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ builds:
66
env:
77
- CGO_ENABLED=0
88
ldflags:
9-
- -s -w -X main.build={{ .Version }} -X main.commit={{ .ShortCommit }} -X main.date={{ .Date }}
9+
- -s -w
1010
goos:
1111
- darwin
1212
- linux

Dockerfile

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ WORKDIR /usr/src/app
77
COPY . ./
88

99
RUN go mod download \
10-
&& CGO_ENABLED=0 GOOS=linux go build -a -o main cmd/main/main.go
10+
&& CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -a -o main cmd/main/main.go
1111

1212

1313
# Final Image
@@ -16,9 +16,10 @@ FROM dimaskiddo/alpine:base
1616
MAINTAINER Dimas Restu Hidayanto <[email protected]>
1717

1818
ARG SERVICE_NAME="codebase-go-rest"
19-
ENV CONFIG_ENV="production"
19+
ENV PATH="$PATH:/usr/app/${SERVICE_NAME}" \
20+
CONFIG_ENV="production"
2021

21-
WORKDIR /usr/app
22+
WORKDIR /usr/app/${SERVICE_NAME}
2223

2324
COPY --from=go-builder /usr/src/app/config/ ./config
2425
COPY --from=go-builder /usr/src/app/main ./main
@@ -28,5 +29,5 @@ RUN chmod 777 config/stores config/uploads
2829
EXPOSE 3000
2930
HEALTHCHECK --interval=5s --timeout=3s CMD ["curl", "http://127.0.0.1:3000/health"] || exit 1
3031

31-
VOLUME ["/usr/src/app/config/stores","/usr/src/app/config/uploads"]
32-
CMD ["./main"]
32+
VOLUME ["/usr/app/config/stores","/usr/app/config/uploads"]
33+
CMD ["main"]

Makefile

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
BUILD_CGO_ENABLED := 0
12
SERVICE_NAME := codebase-go-rest
23
SERVICE_PORT := 3000
34
IMAGE_NAME := codebase-go-rest
@@ -24,12 +25,18 @@ release:
2425
make vendor
2526
make clean-dist
2627
goreleaser --snapshot --skip-publish --rm-dist
27-
echo "Release complete please check dist directory."
28+
echo "Release '$(SERVICE_NAME)' complete, please check dist directory."
2829

2930
publish:
31+
make vendor
3032
make clean-dist
3133
GITHUB_TOKEN=$(GITHUB_TOKEN) goreleaser --rm-dist
32-
echo "Publish complete please check your repository releases."
34+
echo "Publish '$(SERVICE_NAME)' complete, please check your repository releases."
35+
36+
build:
37+
make vendor
38+
CGO_ENABLED=$(BUILD_CGO_ENABLED) go build -ldflags="-s -w" -a -o $(SERVICE_NAME) cmd/main/main.go
39+
echo "Build '$(SERVICE_NAME)' complete."
3340

3441
run:
3542
go run cmd/main/*.go

0 commit comments

Comments
 (0)