Skip to content

Commit 629c7eb

Browse files
authored
Merge pull request #3234 from fierlion/initAgentIntegration
Merge latest ecs-init & initAgentIntegration into dev
2 parents 2dd337e + 861f585 commit 629c7eb

File tree

471 files changed

+6207
-3217
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

471 files changed

+6207
-3217
lines changed

.github/workflows/linux.yml

+2
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ jobs:
2828
cd $GITHUB_WORKSPACE/src/github.com/aws/amazon-ecs-agent
2929
make test-silent
3030
make analyze-cover-profile
31+
make test-init
32+
make analyze-cover-profile-init

.github/workflows/static.yml

+26
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,32 @@ jobs:
2929
make get-deps
3030
make static-check
3131
32+
init-check:
33+
name: Static Analysis Init
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v2
37+
with:
38+
path: src/github.com/aws/amazon-ecs-agent
39+
- name: get GO_VERSION
40+
run: |
41+
cd $GITHUB_WORKSPACE/src/github.com/aws/amazon-ecs-agent
42+
echo "GO_VERSION=$(cat GO_VERSION)" >> $GITHUB_ENV
43+
- uses: actions/setup-go@v2
44+
with:
45+
go-version: ${{ env.GO_VERSION }}
46+
- uses: actions/checkout@v2
47+
with:
48+
path: src/github.com/aws/amazon-ecs-agent
49+
- name: run static checks
50+
run: |
51+
export GOPATH=$GITHUB_WORKSPACE
52+
export PATH=$PATH:$(go env GOPATH)/bin
53+
export GO111MODULE=auto
54+
cd $GITHUB_WORKSPACE/src/github.com/aws/amazon-ecs-agent
55+
make get-deps-init
56+
make static-check-init
57+
3258
x-platform-build:
3359
name: Cross platform build
3460
runs-on: ubuntu-latest

.gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _bin/
88
*.swp
99
*.orig
1010
/agent/version/_version.go
11+
/ecs-init/version/version.go
1112
.agignore
1213
*.sublime-*
1314
.DS_Store
@@ -20,3 +21,22 @@ _bin/
2021
*.iml
2122
cover.out
2223
coverprofile.out
24+
/amazon-ecs-init*
25+
/BUILDROOT/
26+
/x86_64/
27+
/sources.tar
28+
/ecs-init-*
29+
/ecs.conf
30+
/.deb-done
31+
/.rpm-done
32+
/.srpm-done
33+
/BUILD
34+
/RPMS
35+
/SOURCES
36+
/SRPMS
37+
/ecs-init.spec
38+
/sources.tgz
39+
ecs-agent-*.tar
40+
/ecs.service
41+
*.log
42+
*.DS_Store

Makefile

+181-14
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ all: docker
3939
gobuild:
4040
./scripts/build false
4141

42-
4342
# create output directories
4443
.out-stamp:
4544
mkdir -p ./out/test-artifacts ./out/cni-plugins ./out/amazon-ecs-cni-plugins ./out/amazon-vpc-cni-plugins
@@ -49,6 +48,9 @@ gobuild:
4948
static:
5049
./scripts/build
5150

51+
static-with-pause:
52+
./scripts/build true "" false true
53+
5254
# Cross-platform build target for static checks
5355
xplatform-build:
5456
GOOS=linux GOARCH=arm64 ./scripts/build true "" false
@@ -119,6 +121,10 @@ gogenerate:
119121
go generate -x ./agent/...
120122
$(MAKE) goimports
121123

124+
gogenerate-init:
125+
PATH=$(PATH):$(shell pwd)/scripts go generate -x ./ecs-init/...
126+
$(MAKE) goimports
127+
122128
# 'go' may not be on the $PATH for sudo tests
123129
GO_EXECUTABLE=$(shell command -v go 2> /dev/null)
124130

@@ -140,6 +146,10 @@ test:
140146
${GOTEST} -tags unit -coverprofile cover.out -timeout=60s ./agent/...
141147
go tool cover -func cover.out > coverprofile.out
142148

149+
test-init:
150+
go test -count=1 -short -v -coverprofile cover.out ./ecs-init/...
151+
go tool cover -func cover.out > coverprofile-init.out
152+
143153
test-silent:
144154
$(eval VERBOSE=)
145155
${GOTEST} -tags unit -coverprofile cover.out -timeout=60s ./agent/...
@@ -149,6 +159,10 @@ test-silent:
149159
analyze-cover-profile: coverprofile.out
150160
./scripts/analyze-cover-profile
151161

162+
.PHONY: analyze-cover-profile-init
163+
analyze-cover-profile-init: coverprofile-init.out
164+
./scripts/analyze-cover-profile-init
165+
152166
run-integ-tests: test-registry gremlin container-health-check-image run-sudo-tests
153167
ECS_LOGLEVEL=debug ${GOTEST} -tags integration -timeout=30m ./agent/...
154168

@@ -158,7 +172,6 @@ run-sudo-tests:
158172
benchmark-test:
159173
go test -run=XX -bench=. ./agent/...
160174

161-
162175
.PHONY: build-image-for-ecr upload-images replicate-images
163176

164177
build-image-for-ecr: netkitten volumes-test image-cleanup-test-images fluentd exec-command-agent-test
@@ -223,6 +236,20 @@ cni-plugins: get-cni-sources .out-stamp build-ecs-cni-plugins build-vpc-cni-plug
223236
mv $(PWD)/out/amazon-vpc-cni-plugins/* $(PWD)/out/cni-plugins
224237
@echo "Built all cni plugins successfully."
225238

239+
# dockerfree build process will build the agent container image from scratch
240+
# requires glibc-static -- we precompile amd/arm to the misc/pause-container/pause-image-tar-files/ directory
241+
dockerfree-pause:
242+
./scripts/build-pause
243+
244+
dockerfree-certs:
245+
./scripts/get-host-certs
246+
247+
dockerfree-cni-plugins: get-cni-sources
248+
./scripts/build-cni-plugins
249+
250+
# see dockerfree-pause above: assumes that the pre-compiled pause container tar exists
251+
dockerfree-agent-image: dockerfree-certs dockerfree-cni-plugins static-with-pause
252+
./scripts/build-agent-image
226253

227254
.PHONY: codebuild
228255
codebuild: .out-stamp
@@ -259,7 +286,6 @@ image-cleanup-test-images:
259286
container-health-check-image:
260287
$(MAKE) -C misc/container-health $(MFLAGS)
261288

262-
263289
# all .go files in the agent, excluding vendor/, model/ and testutils/ directories, and all *_test.go and *_mocks.go files
264290
GOFILES:=$(shell go list -f '{{$$p := .}}{{range $$f := .GoFiles}}{{$$p.Dir}}/{{$$f}} {{end}}' ./agent/... \
265291
| grep -v /testutils/ | grep -v _test\.go$ | grep -v _mocks\.go$ | grep -v /model)
@@ -286,12 +312,23 @@ gogenerate-check: gogenerate
286312
# check that gogenerate does not generate a diff.
287313
git diff --exit-code
288314

315+
.PHONY: gogenerate-check-init
316+
gogenerate-check-init: gogenerate-init
317+
# check that gogenerate does not generate a diff.
318+
git diff --exit-code
319+
289320
.PHONY: static-check
290321
static-check: gocyclo govet importcheck gogenerate-check
291322
# use default checks of staticcheck tool, except style checks (-ST*) and depracation checks (-SA1019)
292323
# depracation checks have been left out for now; removing their warnings requires error handling for newer suggested APIs, changes in function signatures and their usages.
293324
# https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck
294-
staticcheck -tests=false -checks "inherit,-ST*,-SA1019,-SA9002" ./agent/...
325+
staticcheck -tests=false -checks "inherit,-ST*,-SA1019,-SA9002,-SA4006" ./agent/...
326+
327+
.PHONY: static-check-init
328+
static-check-init: gocyclo govet importcheck gogenerate-check-init
329+
# use default checks of staticcheck tool, except style checks (-ST*)
330+
# https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck
331+
staticcheck -tests=false -checks "inherit,-ST*" ./ecs-init/...
295332

296333
.PHONY: goimports
297334
goimports:
@@ -309,24 +346,154 @@ GOPATH=$(shell go env GOPATH)
309346

310347
get-deps: .get-deps-stamp
311348

349+
get-deps-init:
350+
go get golang.org/x/tools/cover
351+
go get golang.org/x/tools/cmd/cover
352+
go get github.com/golang/mock/mockgen
353+
cd "${GOPATH}/src/github.com/golang/mock/mockgen" && git checkout 1.3.1 && go get ./... && go install ./... && cd -
354+
GO111MODULE=on go get github.com/fzipp/gocyclo/cmd/[email protected]
355+
go get golang.org/x/tools/cmd/goimports
356+
GO111MODULE=on go get honnef.co/go/tools/cmd/[email protected]
357+
358+
amazon-linux-sources.tgz:
359+
./scripts/update-version.sh
360+
cp packaging/amazon-linux-ami-integrated/ecs-init.spec ecs-init.spec
361+
cp packaging/amazon-linux-ami-integrated/ecs-agent.spec ecs-agent.spec
362+
cp packaging/amazon-linux-ami-integrated/ecs.conf ecs.conf
363+
cp packaging/amazon-linux-ami-integrated/ecs.service ecs.service
364+
cp packaging/amazon-linux-ami-integrated/amazon-ecs-volume-plugin.conf amazon-ecs-volume-plugin.conf
365+
cp packaging/amazon-linux-ami-integrated/amazon-ecs-volume-plugin.service amazon-ecs-volume-plugin.service
366+
cp packaging/amazon-linux-ami-integrated/amazon-ecs-volume-plugin.socket amazon-ecs-volume-plugin.socket
367+
tar -czf ./sources.tgz ecs-init scripts misc agent amazon-ecs-cni-plugins amazon-vpc-cni-plugins agent-container VERSION
368+
369+
.amazon-linux-rpm-integrated-done: amazon-linux-sources.tgz
370+
test -e SOURCES || ln -s . SOURCES
371+
rpmbuild --define "%_topdir $(PWD)" -bb ecs-init.spec
372+
find RPMS/ -type f -exec cp {} . \;
373+
touch .amazon-linux-rpm-integrated-done
374+
375+
amazon-linux-rpm-integrated: .amazon-linux-rpm-integrated-done
376+
377+
.generic-rpm-integrated-done: get-cni-sources
378+
./scripts/update-version.sh
379+
cp packaging/generic-rpm-integrated/amazon-ecs-init.spec amazon-ecs-init.spec
380+
cp packaging/generic-rpm-integrated/ecs.service ecs.service
381+
cp packaging/generic-rpm-integrated/amazon-ecs-volume-plugin.service amazon-ecs-volume-plugin.service
382+
cp packaging/generic-rpm-integrated/amazon-ecs-volume-plugin.socket amazon-ecs-volume-plugin.socket
383+
tar -czf ./sources.tgz ecs-init scripts misc agent amazon-ecs-cni-plugins amazon-vpc-cni-plugins agent-container VERSION
384+
test -e SOURCES || ln -s . SOURCES
385+
rpmbuild --define "%_topdir $(PWD)" -bb amazon-ecs-init.spec
386+
find RPMS/ -type f -exec cp {} . \;
387+
touch .generic-rpm-integrated-done
388+
389+
generic-rpm-integrated: .generic-rpm-integrated-done
390+
391+
VERSION = $(shell cat ecs-init/ECSVERSION)
392+
393+
.generic-deb-integrated-done: get-cni-sources
394+
mkdir -p BUILDROOT
395+
./scripts/update-version.sh
396+
tar -czf ./amazon-ecs-init_${VERSION}.orig.tar.gz ecs-init scripts README.md
397+
cp -r packaging/generic-deb-integrated/debian ecs-init scripts misc agent agent-container amazon-ecs-cni-plugins amazon-vpc-cni-plugins README.md VERSION BUILDROOT
398+
cd BUILDROOT && debuild -uc -us --lintian-opts --suppress-tags bad-distribution-in-changes-file,file-in-unusual-dir
399+
touch .generic-deb-integrated-done
400+
401+
generic-deb-integrated: .generic-deb-integrated-done
402+
403+
ARCH:=$(shell uname -m)
404+
ifeq (${ARCH},x86_64)
405+
AGENT_FILENAME=ecs-agent-v${VERSION}.tar
406+
else ifeq (${ARCH},aarch64)
407+
AGENT_FILENAME=ecs-agent-arm64-v${VERSION}.tar
408+
# osx M1 instances
409+
else ifeq (${ARCH},arm64)
410+
AGENT_FILENAME=ecs-agent-arm64-v${VERSION}.tar
411+
endif
412+
413+
BUILDROOT/ecs-agent.tar:
414+
mkdir -p BUILDROOT
415+
curl -o BUILDROOT/ecs-agent.tar https://s3.amazonaws.com/amazon-ecs-agent/${AGENT_FILENAME}
416+
417+
${AGENT_FILENAME}: BUILDROOT/ecs-agent.tar
418+
cp BUILDROOT/ecs-agent.tar ${AGENT_FILENAME}
419+
420+
rpm-in-docker: ${AGENT_FILENAME}
421+
docker build -t "amazon/amazon-ecs-init:build" -f "scripts/dockerfiles/build.dockerfile" .
422+
docker run -u "$(shell id -u)" --tmpfs /.cache -v "$(shell pwd):/workspace/amazon-ecs-init" "amazon/amazon-ecs-init:build"
423+
424+
.generic-rpm-done: ${AGENT_FILENAME}
425+
./scripts/update-version.sh
426+
cp packaging/generic-rpm/amazon-ecs-init.spec amazon-ecs-init.spec
427+
cp packaging/generic-rpm/ecs.service ecs.service
428+
cp packaging/generic-rpm/amazon-ecs-volume-plugin.service amazon-ecs-volume-plugin.service
429+
cp packaging/generic-rpm/amazon-ecs-volume-plugin.socket amazon-ecs-volume-plugin.socket
430+
tar -czf ./sources.tgz ecs-init scripts
431+
test -e SOURCES || ln -s . SOURCES
432+
rpmbuild --define "%_topdir $(PWD)" -bb amazon-ecs-init.spec
433+
find RPMS/ -type f -exec cp {} . \;
434+
touch .generic-rpm-done
435+
436+
generic-rpm: .generic-rpm-done
437+
438+
.deb-done: BUILDROOT/ecs-agent.tar
439+
./scripts/update-version.sh
440+
tar -czf ./amazon-ecs-init_${VERSION}.orig.tar.gz ecs-init scripts README.md
441+
cp -r packaging/generic-deb/debian ecs-init scripts README.md BUILDROOT
442+
cd BUILDROOT && debuild -uc -us --lintian-opts --suppress-tags bad-distribution-in-changes-file,file-in-unusual-dir
443+
touch .deb-done
444+
445+
.PHONY: deb
446+
deb: .deb-done
447+
312448
clean:
449+
rm -f misc/certs/host-certs.crt &> /dev/null
450+
rm -rf misc/pause-container/image/
451+
rm -rf misc/pause-container/rootfs/
452+
rm -rf misc/plugins/
453+
rm -rf out/
454+
rm -rf rootfs/
455+
-$(MAKE) -C $(ECS_CNI_REPOSITORY_SRC_DIR) clean
456+
-rm -f .get-deps-stamp
457+
-rm -f .builder-image-stamp
458+
-rm -f .out-stamp
459+
-rm -rf $(PWD)/bin
460+
-rm -rf cover.out
461+
-rm -rf coverprofile.out
462+
-rm -rf coverprofile-init.out
463+
# ecs-init & rpm cleanup
464+
-rm -f ecs-init.spec
465+
-rm -f amazon-ecs-init.spec
466+
-rm -f ecs.conf
467+
-rm -f ecs.service
468+
-rm -f amazon-ecs-volume-plugin.conf
469+
-rm -f amazon-ecs-volume-plugin.service
470+
-rm -f amazon-ecs-volume-plugin.socket
471+
-rm -rf ./bin
472+
-rm -f ./sources.tgz
473+
-rm -f ./amazon-ecs-init
474+
-rm -f ./ecs-init/ecs-init
475+
-rm -f ./amazon-ecs-init-*.rpm
476+
-rm -f ./ecs-agent-*.tar
477+
-rm -f ./ecs-init-*.src.rpm
478+
-rm -rf ./ecs-init-*
479+
-rm -rf ./BUILDROOT BUILD RPMS SRPMS SOURCES SPECS
480+
-rm -rf ./x86_64
481+
-rm -f ./amazon-ecs-init_${VERSION}*
482+
-rm -f .srpm-done .rpm-done .generic-rpm-done
483+
-rm -f .deb-done
484+
-rm -f .amazon-linux-rpm-integrated-done
485+
-rm -f .generic-rpm-integrated-done
486+
-rm -f amazon-ecs-volume-plugin
487+
488+
clean-all: clean
489+
# for our dockerfree builds, we likely don't have docker
313490
# ensure docker is running and we can talk to it, abort if not:
314491
docker ps > /dev/null
315492
-docker rmi $(BUILDER_IMAGE) "amazon/amazon-ecs-agent-cleanbuild:make"
316493
-docker rmi $(BUILDER_IMAGE) "amazon/amazon-ecs-agent-cleanbuild-windows:make"
317-
rm -f misc/certs/ca-certificates.crt &> /dev/null
318-
rm -rf out/
319-
-$(MAKE) -C $(ECS_CNI_REPOSITORY_SRC_DIR) clean
320494
-$(MAKE) -C misc/netkitten $(MFLAGS) clean
321495
-$(MAKE) -C misc/volumes-test $(MFLAGS) clean
322496
-$(MAKE) -C misc/exec-command-agent-test $(MFLAGS) clean
323497
-$(MAKE) -C misc/gremlin $(MFLAGS) clean
324498
-$(MAKE) -C misc/image-cleanup-test-images $(MFLAGS) clean
325499
-$(MAKE) -C misc/container-health $(MFLAGS) clean
326-
-rm -f .get-deps-stamp
327-
-rm -f .builder-image-stamp
328-
-rm -f .out-stamp
329-
-rm -rf $(PWD)/bin
330-
-rm -rf cover.out
331-
-rm -rf coverprofile.out
332-

agent-container/agent-config.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"author":"Amazon Web Services, Inc.","config":{"Cmd":["/agent"],"ArgsEscaped":true},"created":"~~timestamp~~","history":[{"created":"~~timestamp~~","author":"Amazon Web Services, Inc.","created_by":"°o°","empty_layer":true}],"os":"linux","rootfs":{"type":"layers","diff_ids":["sha256:~~digest~~"]}}

agent-container/agent-image-VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0

agent-container/agent-manifest.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"Config":"config.json","RepoTags":["amazon/amazon-ecs-agent:latest"],"Layers":["rootfs/layer.tar"]}]

agent-container/agent-repositories

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"amazon/amazon-ecs-agent":{"amazon-ecs":"rootfs"}}

agent/acs/client/acs_client_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//go:build unit
2+
// +build unit
23

34
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
45
//

agent/acs/client/acs_error_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//go:build unit
2+
// +build unit
23

34
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
45
//

agent/acs/handler/acs_handler_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//go:build unit
2+
// +build unit
23

34
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
45
//

agent/acs/handler/attach_eni_handler_common_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//go:build unit
2+
// +build unit
23

34
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
45
//

agent/acs/handler/attach_instance_eni_handler_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//go:build unit
2+
// +build unit
23

34
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
45
//

agent/acs/handler/attach_task_eni_handler_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//go:build unit
2+
// +build unit
23

34
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
45
//

agent/acs/handler/heartbeat_handler_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//go:build unit
2+
// +build unit
23

34
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
45
//

0 commit comments

Comments
 (0)