-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
166 lines (141 loc) · 6.26 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# -----------------------------------------------------------------------------
# MAKEFILE RUNNING COMMAND
# -----------------------------------------------------------------------------
# Author : DevOps Engineer (support@devopscorner.id)
# License : Apache v2
# -----------------------------------------------------------------------------
# Notes:
# use [TAB] instead [SPACE]
export PATH_DOCKER="."
export PROJECT_NAME="bookstore"
export AWS_DEFAULT_REGION="ap-southeast-1"
export CI_REGISTRY ?= $(ARGS).dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com
export CI_PROJECT_PATH ?= devopscorner
export CI_PROJECT_NAME ?= bookstore
IMAGE = $(CI_REGISTRY)/${CI_PROJECT_PATH}/${CI_PROJECT_NAME}
DIR = $(shell pwd)
VERSION ?= 1.7.0
export BASE_IMAGE=alpine
export BASE_VERSION=3.17
export ALPINE_VERSION=3.17
GO_APP ?= bookstore
SOURCES = $(shell find . -name '*.go' | grep -v /vendor/)
VERSION ?= $(shell git describe --tags --always --dirty)
GOPKGS = $(shell go list ./ | grep -v /vendor/)
BUILD_FLAGS ?=
LDFLAGS ?= -X github.com/devopscorner/golang-deployment/src/config.Version=$(VERSION) -w -s
TAG ?= "v0.3.0"
GOARCH ?= amd64
GOOS ?= linux
GO111MODULE ?= on
export PATH_APP=`pwd`
# ========================= #
# BUILD GO APP (Binary) #
# ========================= #
.PHONY: build
default: build
test.race:
go test -v -race -count=1 `go list ./...`
test:
go test -v -count=1 `go list ./...`
fmt:
go fmt $(GOPKGS)
check:
golint $(GOPKGS)
go vet $(GOPKGS)
# build: build/$(BINARY)
# build/$(BINARY): $(SOURCES)
# GO111MODULE=$(GO111MODULE) GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -o build/$(BINARY) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" .
tag:
git tag $(TAG)
build:
@echo "============================================"
@echo " Task : Build Binary GO APP "
@echo " Date/Time : `date`"
@echo "============================================"
@echo ">> Build GO Apps... "
@echo ">> GO111MODULE=$(GO111MODULE) GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -o build/$(GO_APP) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" ./main.go"
@cd src && GO111MODULE=$(GO111MODULE) GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -o build/$(GO_APP) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" ./main.go
@echo '- DONE -'
build-mac-amd:
@echo "============================================"
@echo " Task : Build Binary GO APP "
@echo " Date/Time : `date`"
@echo "============================================"
@echo ">> Build GO Apps... "
@echo ">> GO111MODULE=$(GO111MODULE) GOOS=darwin GOARCH=amd64 go build -o build/$(GO_APP) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" ./main.go"
@cd src && GO111MODULE=$(GO111MODULE) GOOS=darwin GOARCH=amd64 go build -o build/$(GO_APP) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" ./main.go
@echo '- DONE -'
build-mac-arm:
@echo "============================================"
@echo " Task : Build Binary GO APP "
@echo " Date/Time : `date`"
@echo "============================================"
@echo ">> Build GO Apps... "
@echo ">> GO111MODULE=$(GO111MODULE) GOOS=darwin GOARCH=arm64 go build -o build/$(GO_APP) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" ./main.go"
@cd src && GO111MODULE=$(GO111MODULE) GOOS=darwin GOARCH=arm64 go build -o build/$(GO_APP) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" ./main.go
@echo '- DONE -'
# ==================== #
# CLONE REPOSITORY #
# ==================== #
.PHONY: git-clone
git-clone:
@echo "================================================="
@echo " Task : Clone Repository Sources "
@echo " Date/Time : `date`"
@echo "================================================="
@sh ./git-clone.sh $(SOURCE) $(TARGET)
@echo '- DONE -'
# ========================== #
# BUILD CONTAINER GO-APP #
# ========================== #
.PHONY: dockerhub-build-alpine ecr-build-alpine
# ./dockerhub-build.sh Dockerfile [DOCKERHUB_IMAGE_PATH] [alpine] [version|latest|tags] [custom-tags]
dockerhub-build-alpine:
@echo "========================================================"
@echo " Task : Create Container GO-APP Alpine Image "
@echo " Date/Time : `date`"
@echo "========================================================"
@sh ./dockerhub-build.sh Dockerfile $(CI_PATH) alpine ${ALPINE_VERSION}
# ./ecr-build.sh [AWS_ACCOUNT] Dockerfile [ECR_PATH] [alpine] [version|latest|tags] [custom-tags]
ecr-build-alpine:
@echo "========================================================"
@echo " Task : Create Container GO-APP Alpine Image "
@echo " Date/Time : `date`"
@echo "========================================================"
@sh ./ecr-build.sh $(ARGS) Dockerfile $(CI_PATH) alpine ${ALPINE_VERSION}
# ========================= #
# TAGS CONTAINER GO-APP #
# ========================= #
.PHONY: tag-dockerhub-alpine tag-ecr-alpine
# ./dockerhub-tag.sh [DOCKERHUB_IMAGE_PATH] [alpine] [version|latest|tags] [custom-tags]
dockerhub-tag-alpine:
@echo "========================================================"
@echo " Task : Set Tags Image Alpine to DockerHub"
@echo " Date/Time : `date`"
@echo "========================================================"
@sh ./dockerhub-tag.sh $(CI_PATH) alpine ${ALPINE_VERSION}
# ./ecr-tag.sh [AWS_ACCOUNT] [ECR_PATH] [alpine|codebuild] [version|latest|tags] [custom-tags]
ecr-tag-alpine:
@echo "========================================================"
@echo " Task : Set Tags Image Alpine to ECR"
@echo " Date/Time : `date`"
@echo "========================================================"
@sh ./ecr-tag.sh $(ARGS) $(CI_PATH) alpine ${ALPINE_VERSION}
# ========================= #
# PUSH CONTAINER GO-APP #
# ========================= #
.PHONY: dockerhub-push-alpine ecr-push-alpine
# ./dockerhub-push.sh [DOCKERHUB_IMAGE_PATH] [alpine|version|latest|tags|custom-tags]
dockerhub-push-alpine:
@echo "========================================================"
@echo " Task : Push Image Alpine to DockerHub"
@echo " Date/Time : `date`"
@echo "========================================================"
@sh ./dockerhub-push.sh $(CI_PATH) alpine
ecr-push-alpine:
@echo "========================================================"
@echo " Task : Push Image Alpine to ECR"
@echo " Date/Time : `date`"
@echo "========================================================"
@sh ./ecr-push.sh $(ARGS) $(CI_PATH) alpine