Skip to content

Commit 6824f40

Browse files
committed
Dockerfree build and ecs-init make integration (#3149)
* Resolve go modules/vendor conflicts and add dockerfree-all make target * add build-time configuration and update scripts/comments
1 parent c5712fd commit 6824f40

Some content is hidden

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

41 files changed

+397
-18
lines changed

.github/workflows/linux.yml

Lines changed: 2 additions & 0 deletions
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

Lines changed: 26 additions & 0 deletions
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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,22 @@ _bin/
2020
*.iml
2121
cover.out
2222
coverprofile.out
23+
/amazon-ecs-init*
24+
/BUILDROOT/
25+
/x86_64/
26+
/sources.tar
27+
/ecs-init-*
28+
/ecs.conf
29+
/.deb-done
30+
/.rpm-done
31+
/.srpm-done
32+
/BUILD
33+
/RPMS
34+
/SOURCES
35+
/SRPMS
36+
/ecs-init.spec
37+
/sources.tgz
38+
ecs-agent-*.tar
39+
/ecs.service
40+
*.log
41+
*.DS_Store

Makefile

Lines changed: 105 additions & 6 deletions
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,21 @@ 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+
# and with minimal dependencies
241+
# requires glibc-static
242+
243+
dockerfree-pause:
244+
GOOS=linux GOARCH=amd64 ./scripts/build-pause
245+
246+
dockerfree-certs:
247+
GOOS=linux GOARCH=amd64 ./scripts/get-host-certs
248+
249+
dockerfree-cni-plugins: get-cni-sources
250+
GOOS=linux GOARCH=amd64 ./scripts/build-cni-plugins
251+
252+
dockerfree-agent-image: dockerfree-pause dockerfree-certs dockerfree-cni-plugins static-with-pause
253+
GOOS=linux GOARCH=amd64 ./scripts/build-agent-image
226254

227255
.PHONY: codebuild
228256
codebuild: .out-stamp
@@ -259,7 +287,6 @@ image-cleanup-test-images:
259287
container-health-check-image:
260288
$(MAKE) -C misc/container-health $(MFLAGS)
261289

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

316+
.PHONY: gogenerate-check-init
317+
gogenerate-check-init: gogenerate-init
318+
# check that gogenerate does not generate a diff.
319+
git diff --exit-code
320+
289321
.PHONY: static-check
290322
static-check: gocyclo govet importcheck gogenerate-check
291323
# use default checks of staticcheck tool, except style checks (-ST*) and depracation checks (-SA1019)
292324
# 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.
293325
# https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck
294-
staticcheck -tests=false -checks "inherit,-ST*,-SA1019,-SA9002" ./agent/...
326+
staticcheck -tests=false -checks "inherit,-ST*,-SA1019,-SA9002,-SA4006" ./agent/...
327+
328+
.PHONY: static-check-init
329+
static-check-init: gocyclo govet importcheck gogenerate-check-init
330+
# use default checks of staticcheck tool, except style checks (-ST*)
331+
# https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck
332+
staticcheck -tests=false -checks "inherit,-ST*" ./ecs-init/...
295333

296334
.PHONY: goimports
297335
goimports:
@@ -309,13 +347,52 @@ GOPATH=$(shell go env GOPATH)
309347

310348
get-deps: .get-deps-stamp
311349

350+
get-deps-init:
351+
go get golang.org/x/tools/cover
352+
go get golang.org/x/tools/cmd/cover
353+
go get github.com/golang/mock/mockgen
354+
cd "${GOPATH}/src/github.com/golang/mock/mockgen" && git checkout 1.3.1 && go get ./... && go install ./... && cd -
355+
GO111MODULE=on go get github.com/fzipp/gocyclo/cmd/[email protected]
356+
go get golang.org/x/tools/cmd/goimports
357+
go get honnef.co/go/tools/cmd/staticcheck
358+
359+
.generic-rpm-done:
360+
./scripts/update-version.sh
361+
cp packaging/generic-rpm/amazon-ecs-init.spec amazon-ecs-init.spec
362+
cp packaging/generic-rpm/ecs.service ecs.service
363+
cp packaging/generic-rpm/amazon-ecs-volume-plugin.service amazon-ecs-volume-plugin.service
364+
cp packaging/generic-rpm/amazon-ecs-volume-plugin.socket amazon-ecs-volume-plugin.socket
365+
tar -czf ./sources.tgz ecs-init scripts
366+
test -e SOURCES || ln -s . SOURCES
367+
rpmbuild --define "%_topdir $(PWD)" -bb amazon-ecs-init.spec
368+
find RPMS/ -type f -exec cp {} . \;
369+
touch .rpm-done
370+
371+
generic-rpm: .generic-rpm-done
372+
373+
dockerfree-all: dockerfree-agent-image generic-rpm
374+
375+
.deb-done: BUILDROOT/ecs-agent.tar
376+
./scripts/update-version.sh
377+
tar -czf ./amazon-ecs-init_${VERSION}.orig.tar.gz ecs-init scripts README.md
378+
cp -r packaging/generic-deb/debian ecs-init scripts README.md BUILDROOT
379+
cd BUILDROOT && debuild -uc -us --lintian-opts --suppress-tags bad-distribution-in-changes-file,file-in-unusual-dir
380+
touch .deb-done
381+
382+
deb: .deb-done
383+
312384
clean:
313385
# ensure docker is running and we can talk to it, abort if not:
314386
docker ps > /dev/null
315387
-docker rmi $(BUILDER_IMAGE) "amazon/amazon-ecs-agent-cleanbuild:make"
316388
-docker rmi $(BUILDER_IMAGE) "amazon/amazon-ecs-agent-cleanbuild-windows:make"
317-
rm -f misc/certs/ca-certificates.crt &> /dev/null
389+
rm -f misc/certs/host-certs.crt &> /dev/null
390+
rm -rf misc/pause-container/image/
391+
rm -rf misc/pause-container/rootfs/
392+
rm -rf misc/plugins/
393+
rm -f misc/pause-container/amazon-ecs-pause.tar
318394
rm -rf out/
395+
rm -rf rootfs/
319396
-$(MAKE) -C $(ECS_CNI_REPOSITORY_SRC_DIR) clean
320397
-$(MAKE) -C misc/netkitten $(MFLAGS) clean
321398
-$(MAKE) -C misc/volumes-test $(MFLAGS) clean
@@ -329,4 +406,26 @@ clean:
329406
-rm -rf $(PWD)/bin
330407
-rm -rf cover.out
331408
-rm -rf coverprofile.out
332-
409+
-rm -rf coverprofile-init.out
410+
# ecs-init & rpm cleanup
411+
-rm -f ecs-init.spec
412+
-rm -f amazon-ecs-init.spec
413+
-rm -f ecs.conf
414+
-rm -f ecs.service
415+
-rm -f amazon-ecs-volume-plugin.conf
416+
-rm -f amazon-ecs-volume-plugin.service
417+
-rm -f amazon-ecs-volume-plugin.socket
418+
-rm -rf ./bin
419+
-rm -f ./sources.tgz
420+
-rm -f ./amazon-ecs-init
421+
-rm -f ./ecs-init/ecs-init
422+
-rm -f ./amazon-ecs-init-*.rpm
423+
-rm -f ./ecs-agent-*.tar
424+
-rm -f ./ecs-init-*.src.rpm
425+
-rm -rf ./ecs-init-*
426+
-rm -rf ./BUILDROOT BUILD RPMS SRPMS SOURCES SPECS
427+
-rm -rf ./x86_64
428+
-rm -f ./amazon-ecs-init_${VERSION}*
429+
-rm -f .srpm-done .rpm-done .generic-rpm-done
430+
-rm -f .deb-done
431+
-rm -f amazon-ecs-volume-plugin

agent-container/agent-config.json

Lines changed: 1 addition & 0 deletions
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":"[] + [] === \"\"","empty_layer":true}],"os":"linux","rootfs":{"type":"layers","diff_ids":["sha256:~~digest~~"]}}

agent-container/agent-image-VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0

agent-container/agent-manifest.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[{"Config":"config.json","RepoTags":["amazon/amazon-ecs-agent:~~agentversion~~"],"Layers":["rootfs/layer.tar"]}]
2+

agent-container/agent-repositories

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

dependencies_mocks.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
//
14+
// Source: dependencies.go in package cache
15+

ecs-init/cache/cache_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// +build test
12
// Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
23
//
34
// Licensed under the Apache License, Version 2.0 (the "License"). You may

ecs-init/cache/dependencies.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package cache
1818
// package-level functions. These interfaces are then used to create mocks
1919
// for the unit tests.
2020

21-
//go:generate mockgen.sh $GOPACKAGE $GOFILE
21+
//go:generate mockgen.sh cache $GOFILE
2222

2323
import (
2424
"io"

ecs-init/cache/dependencies_mocks.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ecs-init/config/config_al2.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build al2
12
// +build al2
23

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

ecs-init/config/config_generic_rpm.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build generic_rpm
12
// +build generic_rpm
23

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

ecs-init/config/config_suse_ubuntu_debian.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build suse || ubuntu || debian
12
// +build suse ubuntu debian
23

34
// Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.

ecs-init/config/config_unspecified.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !suse && !ubuntu && !al2 && !debian && !generic_rpm
12
// +build !suse,!ubuntu,!al2,!debian,!generic_rpm
23

34
// Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.

ecs-init/config/development.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build development
12
// +build development
23

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

ecs-init/config/logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ and limitations under the License.
3434
<seelog type="asyncloop">
3535
<outputs formatid="main">
3636
<console formatid="console" />
37-
<rollingfile filename="` + initLogFile() + `" type="date"
37+
<rollingfile filename="`+initLogFile()+`" type="date"
3838
datepattern="2006-01-02-15" archivetype="zip" maxrolls="5" />
3939
</outputs>
4040
<formats>

ecs-init/config/release.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !development
12
// +build !development
23

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

ecs-init/docker/backoff_mocks.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ecs-init/docker/dependencies_mocks.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ecs-init/docker/dependencies_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// +build test
12
// Copyright 2015-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
23
//
34
// Licensed under the Apache License, Version 2.0 (the "License"). You may

ecs-init/docker/docker_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// +build test
12
// Copyright 2015-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
23
//
34
// Licensed under the Apache License, Version 2.0 (the "License"). You may

ecs-init/engine/dependencies_mocks.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ecs-init/engine/engine_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// +build test
12
// Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
23
//
34
// Licensed under the Apache License, Version 2.0 (the "License"). You may

ecs-init/exec/iptables/cmd_mocks.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ecs-init/exec/iptables/exec_mocks.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ecs-init/exec/sysctl/cmd_mocks.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ecs-init/exec/sysctl/exec_mocks.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)