forked from zephinzer/cloudshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
145 lines (122 loc) · 4.25 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
changes ?= $(shell git status --porcelain --untracked-files=no | wc -l)
version ?= $(shell git rev-parse HEAD | head -c 8)
ifeq ($(shell test $(changes) -gt 0; echo $$?),0)
version := $(version)-dev
endif
export_path ?= ./images
# use this to override/set settings
-include Makefile.properties
# image_namespace specifies THIS_PART/namespace/image:tag of the Docker image path
image_registry ?= docker.io
# image_namespace specifies docker.io/THIS_PART/image:tag of the Docker image path
image_namespace ?= zephinzer
# image_name specifies docker.io/namespace/THIS_PART:tag of the Docker image path
image_name ?= cloudshell
# image_name specifies docker.io/namespace/image:THIS_PART of the Docker image path
image_tag ?= $(version)
image_url := $(image_registry)/$(image_namespace)/$(image_name)
binary_name := $(image_name)-${GOOS}-${GOARCH}${BIN_EXT}
# initialises the project (run this before all else)
init:
npm install
go mod vendor
# start the application (use this in development)
start:
go run ./cmd/cloudshell
# runs the application in packaged form
run: package
docker run -it -p 8376:8376 $(image_url):latest
# builds the application binary
build:
CGO_ENABLED=0 \
go build -a -v \
-ldflags " \
-s -w \
-extldflags 'static' \
-X main.VersionInfo='$(version)' \
" \
-o ./bin/$(binary_name) ./cmd/cloudshell
# compresses the application binary
compress:
ls -lah ./bin/$(binary_name)
upx -9 -v -o ./bin/.$(binary_name) \
./bin/$(binary_name)
upx -t ./bin/.$(binary_name)
rm -rf ./bin/$(binary_name)
mv ./bin/.$(binary_name) \
./bin/$(binary_name)
sha256sum -b ./bin/$(binary_name) \
| cut -f 1 -d ' ' > ./bin/$(binary_name).sha256
ls -lah ./bin/$(binary_name)
# lints this image for best-practices
lint:
hadolint ./Dockerfile
# tests this iamge for structure integrity
test: package
container-structure-test test --config ./.Dockerfile.yaml --image $(image_url):latest
# scans this image for known vulnerabilities
scan: package
trivy image \
--output trivy.json \
--format json \
$(image_url):$(version)
trivy image $(image_url):$(version)
# packages project into a docker image
package:
docker build ${build_args} \
--build-arg VERSION_INFO=$(version) \
--tag $(image_url):latest \
.
docker tag $(image_url):latest \
$(image_url):$(version)
# packages example project in this project into a docker image using the docker build cache
package-example: package
if [ "${id}" = "" ]; then \
printf -- '\033[1m\033[31m$${id} was not specified\033[0m\n'; \
exit 1; \
fi
docker build \
--build-arg IMAGE_NAMESPACE=$(image_registry)/$(image_namespace) \
--build-arg IMAGE_NAME=$(image_name) \
--build-arg IMAGE_TAG=$(version) \
--tag $(image_url)-${id}:latest \
--file ./examples/${id}/Dockerfile \
.
docker tag $(image_url)-${id}:latest \
$(image_url)-${id}:$(version)
# publishes primary docker image of this project
publish:
@$(MAKE) package
@$(MAKE) publish-ci
# publishes primary docker image of this project without running package
publish-ci:
-docker push $(image_url):latest
docker push $(image_url):$(version)
# publishes example docker image of this project
publish-example:
@$(MAKE) package-example id=${id}
@$(MAKE) publish-example-ci id=${id}
# publishes example docker image of this project without running package
publish-example-ci:
-docker push $(image_url)-${id}:latest
docker push $(image_url)-${id}:$(version)
# exports this image into a tarball (use in ci cache)
export: package
mkdir -p $(export_path)
docker save $(image_namespace)/$(image_name):latest -o $(export_path)/$(image_namespace)-$(image_name).tar.gz
# exports the example image into a tarball (use in ci cache)
export-example: package-example
mkdir -p $(export_path)
docker save $(image_namespace)/$(image_name)-${id}:latest -o $(export_path)/$(image_namespace)-$(image_name)-${id}.tar.gz
# import this image from a tarball (use in ci cache)
import:
mkdir -p $(export_path)
-docker load -i $(export_path)/$(image_namespace)-$(image_name).tar.gz
# import the example image into a tarball (use in ci cache)
import-example:
mkdir -p $(export_path)
-docker load -i $(export_path)/$(image_namespace)-$(image_name)-${id}.tar.gz
.ssh:
mkdir -p ./.ssh
ssh-keygen -t rsa -b 8192 -f ./.ssh/id_rsa -q -N ""
cat ./.ssh/id_rsa | base64 -w 0 > ./.ssh/id_rsa.base64