forked from aws/amazon-ecs-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_Makefile
172 lines (142 loc) · 5.9 KB
/
init_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
167
168
169
170
171
172
# Copyright 2014-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the
# "License"). You may not use this file except in compliance
# with the License. A copy of the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and
# limitations under the License.
VERSION = $(shell cat ecs-init/ECSVERSION)
.PHONY: dev generate lint static test build-mock-images sources rpm srpm govet rpm-in-docker
dev:
./scripts/gobuild.sh dev
generate:
PATH=$(PATH):$(shell pwd)/scripts go generate -v ./...
static:
./scripts/gobuild.sh
govet:
go vet ./...
test:
go test -count=1 -short -v -coverprofile cover.out ./...
go tool cover -func cover.out > coverprofile.out
.PHONY: analyze-cover-profile
analyze-cover-profile: coverprofile.out
./scripts/analyze-cover-profile
# all .go files in the ecs-init
GOFILES:=$(shell go list -f '{{$$p := .}}{{range $$f := .GoFiles}}{{$$p.Dir}}/{{$$f}} {{end}}' ./ecs-init/...)
.PHONY: gocyclo
gocyclo:
# Run gocyclo over all .go files
gocyclo -over 12 ${GOFILES}
GOFMTFILES:=$(shell find ./ecs-init -not -path './ecs-init/vendor/*' -type f -iregex '.*\.go')
.PHONY: importcheck
importcheck:
$(eval DIFFS:=$(shell goimports -l $(GOFMTFILES)))
@if [ -n "$(DIFFS)" ]; then echo "Files incorrectly formatted. Fix formatting by running goimports:"; echo "$(DIFFS)"; exit 1; fi
.PHONY: static-check
static-check: gocyclo govet importcheck
# use default checks of staticcheck tool, except style checks (-ST*)
# https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck
staticcheck -tests=false -checks "inherit,-ST*" ./ecs-init/...
test-in-docker:
docker build -f scripts/dockerfiles/test.dockerfile -t "amazon/amazon-ecs-init-test:make" .
docker run -v "$(shell pwd):/go/src/github.com/aws/amazon-ecs-agent" "amazon/amazon-ecs-init-test:make"
build-mock-images:
docker build -t "test.localhost/amazon/mock-ecs-agent" -f "scripts/dockerfiles/mock-agent.dockerfile" .
docker build -t "test.localhost/amazon/wants-update" -f "scripts/dockerfiles/wants-update.dockerfile" .
docker build -t "test.localhost/amazon/exit-success" -f "scripts/dockerfiles/exit-success.dockerfile" .
sources.tgz:
./scripts/update-version.sh
cp packaging/amazon-linux-ami/ecs-init.spec ecs-init.spec
cp packaging/amazon-linux-ami/ecs.conf ecs.conf
cp packaging/amazon-linux-ami/ecs.service ecs.service
cp packaging/amazon-linux-ami/amazon-ecs-volume-plugin.conf amazon-ecs-volume-plugin.conf
cp packaging/amazon-linux-ami/amazon-ecs-volume-plugin.service amazon-ecs-volume-plugin.service
cp packaging/amazon-linux-ami/amazon-ecs-volume-plugin.socket amazon-ecs-volume-plugin.socket
tar -czf ./sources.tgz ecs-init scripts
# Hook to perform preparation steps prior to the sources target.
prepare-sources::
sources: prepare-sources sources.tgz
.srpm-done: sources.tgz
test -e SOURCES || ln -s . SOURCES
rpmbuild --define "%_topdir $(PWD)" -bs ecs-init.spec
find SRPMS/ -type f -exec cp {} . \;
touch .srpm-done
srpm: .srpm-done
.rpm-done: sources.tgz
test -e SOURCES || ln -s . SOURCES
rpmbuild --define "%_topdir $(PWD)" -bb ecs-init.spec
find RPMS/ -type f -exec cp {} . \;
touch .rpm-done
rpm: .rpm-done
ARCH:=$(shell uname -m)
ifeq (${ARCH},x86_64)
AGENT_FILENAME=ecs-agent-v${VERSION}.tar
else ifeq (${ARCH},aarch64)
AGENT_FILENAME=ecs-agent-arm64-v${VERSION}.tar
# osx M1 instances
else ifeq (${ARCH},arm64)
AGENT_FILENAME=ecs-agent-arm64-v${VERSION}.tar
endif
BUILDROOT/ecs-agent.tar:
mkdir -p BUILDROOT
curl -o BUILDROOT/ecs-agent.tar https://s3.amazonaws.com/amazon-ecs-agent/${AGENT_FILENAME}
${AGENT_FILENAME}: BUILDROOT/ecs-agent.tar
cp BUILDROOT/ecs-agent.tar ${AGENT_FILENAME}
rpm-in-docker: ${AGENT_FILENAME}
docker build -t "amazon/amazon-ecs-init:build" -f "scripts/dockerfiles/build.dockerfile" .
docker run -u "$(shell id -u)" --tmpfs /.cache -v "$(shell pwd):/workspace/amazon-ecs-init" "amazon/amazon-ecs-init:build"
.generic-rpm-done:
./scripts/update-version.sh
cp packaging/generic-rpm/amazon-ecs-init.spec amazon-ecs-init.spec
cp packaging/generic-rpm/ecs.service ecs.service
cp packaging/generic-rpm/amazon-ecs-volume-plugin.service amazon-ecs-volume-plugin.service
cp packaging/generic-rpm/amazon-ecs-volume-plugin.socket amazon-ecs-volume-plugin.socket
tar -czf ./sources.tgz ecs-init scripts
test -e SOURCES || ln -s . SOURCES
rpmbuild --define "%_topdir $(PWD)" -bb amazon-ecs-init.spec
find RPMS/ -type f -exec cp {} . \;
touch .rpm-done
generic-rpm: .generic-rpm-done
.PHONY: deb
deb: .deb-done
.deb-done: BUILDROOT/ecs-agent.tar
./scripts/update-version.sh
tar -czf ./amazon-ecs-init_${VERSION}.orig.tar.gz ecs-init scripts README.md
cp -r packaging/generic-deb/debian ecs-init scripts README.md BUILDROOT
cd BUILDROOT && debuild -uc -us --lintian-opts --suppress-tags bad-distribution-in-changes-file,file-in-unusual-dir
touch .deb-done
get-deps:
go get golang.org/x/tools/cover
go get golang.org/x/tools/cmd/cover
GO111MODULE=on go get github.com/fzipp/gocyclo/cmd/[email protected]
go get golang.org/x/tools/cmd/goimports
go get github.com/golang/mock/mockgen
go get honnef.co/go/tools/cmd/staticcheck
clean:
-rm -f ecs-init.spec
-rm -f ecs.conf
-rm -f ecs.service
-rm -f amazon-ecs-volume-plugin.conf
-rm -f amazon-ecs-volume-plugin.service
-rm -f amazon-ecs-volume-plugin.socket
-rm -rf ./bin
-rm -f ./sources.tgz
-rm -f ./amazon-ecs-init
-rm -f ./amazon-ecs-init-*.rpm
-rm -f ./ecs-agent-*.tar
-rm -f ./ecs-init-*.src.rpm
-rm -rf ./ecs-init-*
-rm -rf ./BUILDROOT BUILD RPMS SRPMS SOURCES SPECS
-rm -rf ./x86_64
-rm -f ./amazon-ecs-init_${VERSION}*
-rm -f .srpm-done .rpm-done .generic-rpm-done
-rm -f .deb-done
-rm -f cover.out
-rm -f coverprofile.out
-rm -f amazon-ecs-volume-plugin