forked from aws/amazon-ecs-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-agent-image
executable file
·85 lines (75 loc) · 3.14 KB
/
build-agent-image
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
#!/bin/bash
# Copyright 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.
# This script builds a copy of the agent.
# It exists to wrap go build and properly make a static binary, as well as to
# correctly setup versioning before creating the binary
set -ex
ROOT=$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )
cd "${ROOT}"
AGENT_VERSION=$(cat VERSION)
architecture=""
case $(uname -m) in
x86_64)
architecture="amd64"
;;
arm64)
architecture="arm64"
;;
aarch64)
architecture="arm64"
;;
*)
echo $"Unknown architecture $0"
exit 1
esac
if [ "$architecture" == "amd64" ]; then export GOARCH=amd64; fi
if [ "$architecture" == "arm64" ]; then export GOARCH=arm64; fi
# add cni-plugins
mkdir -p rootfs/amazon-ecs-cni-plugins/
cp ./misc/plugins/aws-appmesh rootfs/amazon-ecs-cni-plugins/aws-appmesh
cp ./misc/plugins/ecs-bridge rootfs/amazon-ecs-cni-plugins/ecs-bridge
cp ./misc/plugins/vpc-eni rootfs/amazon-ecs-cni-plugins/vpc-eni
cp ./misc/plugins/ecs-ipam rootfs/amazon-ecs-cni-plugins/ecs-ipam
cp ./misc/plugins/vpc-branch-eni rootfs/amazon-ecs-cni-plugins/vpc-branch-eni
cp ./misc/plugins/ecs-serviceconnect rootfs/amazon-ecs-cni-plugins/ecs-serviceconnect
# add certs
mkdir -p rootfs/etc/ssl/certs/
cp ./misc/certs/host-certs.crt rootfs/etc/ssl/certs/ca-certificates.crt
# add pause container
mkdir -p rootfs/images/
# check for precompiled pause image tar -- if one doesn't exist,
# you need to run make dockerfree-pause
PAUSE_TAR_FILE="${ROOT}/misc/pause-container/pause-image-tar-files/amazon-ecs-pause-${GOARCH}.tar"
if test -f "$PAUSE_TAR_FILE"; then
echo "using existing pause container: $PAUSE_TAR_FILE"
cp ${PAUSE_TAR_FILE} rootfs/images/amazon-ecs-pause.tar
else
echo "$PAUSE_TAR_FILE does not exist; you should run make dockerfree-pause"
exit 2
fi
# add agent
cp ./out/amazon-ecs-agent rootfs/agent
# build container
mkdir -p image/rootfs
tar --mtime="@1492525740" --owner=0 --group=0 --numeric-owner -cf image/rootfs/layer.tar -C rootfs .
DIGEST=$(sha256sum image/rootfs/layer.tar | sed -e 's/ .*//')
install -m 0644 ./agent-container/agent-image-VERSION image/rootfs/VERSION
install -m 0644 ./agent-container/agent-config.json image/config.json
sed -i "s/~~digest~~/${DIGEST}/" image/config.json
sed -i "s/~~timestamp~~/$(date +"%FT%T.%NZ")/g" image/config.json
install -m 0644 ./agent-container/agent-manifest.json image/manifest.json
sed -i "s/~~agentversion~~/${AGENT_VERSION}/" image/manifest.json
install -m 0644 ./agent-container/agent-repositories image/repositories
tar --mtime="@1492525740" --owner=0 --group=0 --numeric-owner -cf ./ecs-agent-v${AGENT_VERSION}.tar -C image .
rm -rf image/