Skip to content

Commit ea97409

Browse files
authored
Merge pull request #59 from SoManyHs/arm-support
chore: support ARM architecture
2 parents 6a6717b + 20f2349 commit ea97409

File tree

14 files changed

+2553
-37
lines changed

14 files changed

+2553
-37
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ out/
1919
.idea
2020
.idea/*
2121
.DS_Store
22+
23+
infra/node_modules
24+
infra/*.js
25+
infra/*.d.ts

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# Use amazonlinux as the base image so that:
22
# - we have certificates to make calls to the AWS APIs (/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem)
33
# - it provides 'sh' excutable that is required by aws-sdk-go credential_process
4+
# NOTE: the amazonlinux:2 base image is multi-arch, so docker should be
5+
# able to detect the correct one to use when the image is run
46
FROM amazonlinux:2
57

68
COPY ["LICENSE", "NOTICE", "THIRD-PARTY", "/"]
79

8-
ADD bin/linux-amd64/local-container-endpoints /
10+
ARG ARCH_DIR
11+
ADD bin/$ARCH_DIR/local-container-endpoints /
912

1013
EXPOSE 80
1114

Makefile

Lines changed: 81 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,74 @@ ROOT := $(shell pwd)
1515

1616
all: local-build
1717

18+
GO_VERSION := 1.15
1819
SCRIPT_PATH := $(ROOT)/scripts/:${PATH}
1920
SOURCES := $(shell find . -name '*.go')
20-
LOCAL_BINARY := bin/local-container-endpoints
21-
LINUX_BINARY := bin/linux-amd64/local-container-endpoints
21+
BINARY_NAME := local-container-endpoints
22+
IMAGE_REPO_NAME := amazon/amazon-ecs-local-container-endpoints
23+
LOCAL_BINARY := bin/local/${BINARY_NAME}
24+
25+
# AMD_DIR and ARM_DIR correspond to ARCH_SUFFIX env var set in each CodeBuild
26+
# project which is used in the image tags.
27+
AMD_DIR := amd64
28+
ARM_DIR := arm64
29+
30+
AMD_BINARY := bin/${AMD_DIR}/${BINARY_NAME}
31+
ARM_BINARY := bin/${ARM_DIR}/${BINARY_NAME}
2232
VERSION := $(shell cat VERSION)
2333
AGENT_VERSION_COMPATIBILITY := $(shell cat AGENT_VERSION_COMPATIBILITY)
2434
TAG := $(VERSION)-agent$(AGENT_VERSION_COMPATIBILITY)-compatible
2535

36+
.PHONY: generate
37+
generate: $(SOURCES)
38+
PATH=$(SCRIPT_PATH) go generate ./...
39+
2640
.PHONY: local-build
2741
local-build: $(LOCAL_BINARY)
2842

43+
.PHONY: build-local-image
44+
build-local-image:
45+
docker run -v $(shell pwd):/usr/src/app/src/github.com/awslabs/amazon-ecs-local-container-endpoints \
46+
--workdir=/usr/src/app/src/github.com/awslabs/amazon-ecs-local-container-endpoints \
47+
--env GOPATH=/usr/src/app \
48+
--env ECS_RELEASE=cleanbuild \
49+
golang:$(GO_VERSION) make ${LOCAL_BINARY}
50+
docker build --build-arg ARCH_DIR=local -t $(IMAGE_REPO_NAME):latest-local .
51+
52+
# Build binaries for each architecture into their own subdirectories
2953
$(LOCAL_BINARY): $(SOURCES)
3054
PATH=${PATH} golint ./local-container-endpoints/...
31-
./scripts/build_binary.sh ./bin/
55+
./scripts/build_binary.sh ./bin/local
3256
@echo "Built local-container-endpoints"
3357

34-
.PHONY: generate
35-
generate: $(SOURCES)
36-
PATH=$(SCRIPT_PATH) go generate ./...
58+
$(AMD_BINARY): $(SOURCES)
59+
@mkdir -p ./bin/$(AMD_DIR)
60+
TARGET_GOOS=linux GOARCH=amd64 ./scripts/build_binary.sh ./bin/$(AMD_DIR)
61+
@echo "Built local-container-endpoints for linux-amd64"
3762

63+
$(ARM_BINARY): $(SOURCES)
64+
@mkdir -p ./bin/$(ARM_DIR)
65+
TARGET_GOOS=linux GOARCH=arm64 ./scripts/build_binary.sh ./bin/$(ARM_DIR)
66+
@echo "Built local-container-endpoints for linux-arm64"
67+
68+
# Relies on ARCH_SUFFIX environment variable which is set in the build
69+
# environment (e.g. CodeBuild project). Value will either be amd64 or arm64.
70+
.PHONY: build-image
71+
build-image:
72+
docker run -v $(shell pwd):/usr/src/app/src/github.com/awslabs/amazon-ecs-local-container-endpoints \
73+
--workdir=/usr/src/app/src/github.com/awslabs/amazon-ecs-local-container-endpoints \
74+
--env GOPATH=/usr/src/app \
75+
--env ECS_RELEASE=cleanbuild \
76+
golang:$(GO_VERSION) make bin/${ARCH_SUFFIX}/${BINARY_NAME}
77+
docker build --build-arg ARCH_DIR=$(ARCH_SUFFIX) -t $(IMAGE_REPO_NAME):latest-$(ARCH_SUFFIX) .
78+
docker tag $(IMAGE_REPO_NAME):latest-$(ARCH_SUFFIX) $(IMAGE_REPO_NAME):$(TAG)-$(ARCH_SUFFIX)
79+
docker tag $(IMAGE_REPO_NAME):latest-$(ARCH_SUFFIX) $(IMAGE_REPO_NAME):$(VERSION)-$(ARCH_SUFFIX)
80+
81+
.PHONY: publish-dockerhub
82+
publish-dockerhub:
83+
docker push $(IMAGE_REPO_NAME):latest-$(ARCH_SUFFIX)
84+
docker push $(IMAGE_REPO_NAME):$(TAG)-$(ARCH_SUFFIX)
85+
docker push $(IMAGE_REPO_NAME):$(VERSION)-$(ARCH_SUFFIX)
3886

3987
.PHONY: test
4088
test:
@@ -44,34 +92,37 @@ test:
4492
functional-test:
4593
go test -mod=vendor -timeout=120s -v -tags functional -cover ./local-container-endpoints/handlers/functional_tests/...
4694

47-
$(LINUX_BINARY): $(SOURCES)
48-
@mkdir -p ./bin/linux-amd64
49-
TARGET_GOOS=linux GOARCH=amd64 ./scripts/build_binary.sh ./bin/linux-amd64
50-
@echo "Built local-container-endpoints for linux"
51-
52-
.PHONY: release
53-
release:
54-
docker run -v $(shell pwd):/usr/src/app/src/github.com/awslabs/amazon-ecs-local-container-endpoints \
55-
--workdir=/usr/src/app/src/github.com/awslabs/amazon-ecs-local-container-endpoints \
56-
--env GOPATH=/usr/src/app \
57-
--env ECS_RELEASE=cleanbuild \
58-
golang:1.12 make $(LINUX_BINARY)
59-
docker build -t amazon/amazon-ecs-local-container-endpoints:latest .
60-
docker tag amazon/amazon-ecs-local-container-endpoints:latest amazon/amazon-ecs-local-container-endpoints:$(TAG)
61-
docker tag amazon/amazon-ecs-local-container-endpoints:latest amazon/amazon-ecs-local-container-endpoints:$(VERSION)
62-
6395
.PHONY: integ
64-
integ: release
96+
integ: build-local-image
6597
docker build -t amazon-ecs-local-container-endpoints-integ-test:latest -f ./integ/Dockerfile .
6698
docker-compose --file ./integ/docker-compose.yml up --abort-on-container-exit
6799

68-
69-
.PHONY: publish
70-
publish: release
71-
docker push amazon/amazon-ecs-local-container-endpoints:latest
72-
docker push amazon/amazon-ecs-local-container-endpoints:$(TAG)
73-
docker push amazon/amazon-ecs-local-container-endpoints:$(VERSION)
100+
.PHONY: verify
101+
verify:
102+
docker pull $(IMAGE_REPO_NAME):latest-$(ARCH_SUFFIX)
103+
docker run -d -p 8000:80 -v /var/run:/var/run -v $(HOME)/.aws/:/home/.aws/ -e "ECS_LOCAL_METADATA_PORT=80" -e "HOME=/home" -e "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=${AWS_CONTAINER_CREDENTIALS_RELATIVE_URI}" --name endpoints $(IMAGE_REPO_NAME):latest-$(ARCH_SUFFIX)
104+
curl -s localhost:8000/creds
105+
curl -s localhost:8000/v2/stats
106+
curl -s localhost:8000/v2/metadata
107+
curl -s localhost:8000/v3
108+
curl -s localhost:8000/v4
109+
docker stop endpoints && docker rm endpoints
110+
docker pull $(IMAGE_REPO_NAME):$(TAG)-$(ARCH_SUFFIX)
111+
docker run -d -p 8000:80 -v /var/run:/var/run -v $(HOME)/.aws/:/home/.aws/ -e "ECS_LOCAL_METADATA_PORT=80" -e "HOME=/home" -e "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=${AWS_CONTAINER_CREDENTIALS_RELATIVE_URI}" --name endpoints $(IMAGE_REPO_NAME):$(TAG)-$(ARCH_SUFFIX)
112+
curl -s localhost:8000/creds
113+
curl -s localhost:8000/v2/stats
114+
curl -s localhost:8000/v3
115+
curl -s localhost:8000/v4
116+
docker stop endpoints && docker rm endpoints
117+
docker pull $(IMAGE_REPO_NAME):$(VERSION)-$(ARCH_SUFFIX)
118+
docker run -d -p 8000:80 -v /var/run:/var/run -v $(HOME)/.aws/:/home/.aws/ -e "ECS_LOCAL_METADATA_PORT=80" -e "HOME=/home" -e "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=${AWS_CONTAINER_CREDENTIALS_RELATIVE_URI}" --name endpoints $(IMAGE_REPO_NAME):$(VERSION)-$(ARCH_SUFFIX)
119+
curl -s localhost:8000/creds
120+
curl -s localhost:8000/v2/stats
121+
curl -s localhost:8000/v2/metadata
122+
curl -s localhost:8000/v3
123+
curl -s localhost:8000/v4
124+
docker stop endpoints && docker rm endpoints
74125

75126
.PHONY: clean
76127
clean:
77-
rm bin/local-container-endpoints
128+
rm bin/local/local-container-endpoints

buildspec.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: 0.2
2+
3+
env:
4+
secrets-manager:
5+
USERNAME: "com.amazonaws.ec2.madison.dockerhub.amazon-ecs-local-container-endpoints.credentials:username"
6+
PASSWORD: "com.amazonaws.ec2.madison.dockerhub.amazon-ecs-local-container-endpoints.credentials:password"
7+
8+
phases:
9+
install:
10+
commands:
11+
- echo '#!/bin/bash' > /usr/local/bin/ok; echo 'if [[ "$CODEBUILD_BUILD_SUCCEEDING" == "0" ]]; then exit 1; else exit 0; fi' >> /usr/local/bin/ok; chmod +x /usr/local/bin/ok
12+
pre_build:
13+
commands:
14+
- echo "Logging into DockerHub..."
15+
- docker login -u ${USERNAME} --password ${PASSWORD}
16+
build:
17+
# build and tag docker image. This will read ARCH_SUFFIX env var set in the
18+
# Codebuild project.
19+
commands:
20+
- echo Build started on `date`
21+
- echo Building Docker image...
22+
- make build-image
23+
- make publish-dockerhub
24+
post_build:
25+
commands:
26+
- ok && echo Build completed on `date`

buildspec_verify.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: 0.2
2+
3+
env:
4+
secrets-manager:
5+
USERNAME: "com.amazonaws.ec2.madison.dockerhub.amazon-ecs-local-container-endpoints.credentials:username"
6+
PASSWORD: "com.amazonaws.ec2.madison.dockerhub.amazon-ecs-local-container-endpoints.credentials:password"
7+
8+
phases:
9+
install:
10+
commands:
11+
- echo '#!/bin/bash' > /usr/local/bin/ok; echo 'if [[ "$CODEBUILD_BUILD_SUCCEEDING" == "0" ]]; then exit 1; else exit 0; fi' >> /usr/local/bin/ok; chmod +x /usr/local/bin/ok
12+
pre_build:
13+
commands:
14+
- echo "Logging into DockerHub..."
15+
- docker login -u ${USERNAME} --password ${PASSWORD}
16+
build:
17+
commands:
18+
- echo "Verifying Docker images..."
19+
- make verify
20+
post_build:
21+
commands:
22+
- ok && echo Build completed on `date`

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ For example, on an Ubuntu machine, you can mount your machine's certificates fil
1515

1616
### Custom IAM and STS Endpoints
1717

18-
Local Endpoionts can be configured to use custom IAM and STS endpoints. Simply define the `IAM_ENDPOINT` and `STS_ENDPOINT` environment variables in the Local Endpoints container.
18+
Local Endpoints can be configured to use custom IAM and STS endpoints. Simply define the `IAM_ENDPOINT` and `STS_ENDPOINT` environment variables in the Local Endpoints container.
1919

2020
This may be useful in scenarios where your application container is configured to obtain credentials from ECS (see [Vend Credentials to Containers](features.md#vend-credentials-to-containers)), but you do not want to provide Local Endpoints with AWS credentials. Providing an IAM and STS simulator and configuring the Local Endpoints container with custom IAM and STS endpoints enables testing without an AWS account.
2121

docs/setup-networking.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
## Setting Up Networking
22

3-
ECS Local Container Endpoints supports 3 endpoints:
3+
ECS Local Container Endpoints supports 4 endpoints:
44
* The [ECS Task IAM Roles endpoint](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html)
55
* The [Task Metadata V2 Endpoint](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v2.html)
66
* The [Task Metadata V3 Endpoint](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v3.html)
7+
* The [Task Metadata V4 Endpoint](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v4.html)
78

89
The Task Metadata V2 and Credentials endpoints require the Local Endpoints container to be able to receive requests made to the special IP Address, `169.254.170.2`.
910

@@ -36,5 +37,5 @@ docker run -d -p 51679:51679 \
3637
-v $HOME/.aws/:/home/.aws/ \
3738
-e "ECS_LOCAL_METADATA_PORT=51679" \
3839
--name ecs-local-endpoints \
39-
amazon/amazon-ecs-local-container-endpoints:latest
40-
```
40+
amazon/amazon-ecs-local-container-endpoints:latest-amd64
41+
```

infra/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Continuous delivery pipelines
2+
3+
This package uses the [AWS Cloud Development Kit (AWS)](https://github.com/awslabs/aws-cdk) to model AWS CodePipeline pipelines and to provision them with AWS CloudFormation.
4+
5+
* pipeline.ts: Builds and publishes the base Docker image for amazon/amazon-ecs-local-container-endpoints.
6+
7+
This creates as CodePipeline pipeline which consists of a souce stage that uses
8+
a GitHub webhook, and build stages that uses AWS CodeBuild to build, publish
9+
and verify Docker images for both amd64 and arm64 architectures to DockerHub.
10+
11+
## GitHub Access Token
12+
The official pipeilne uses a team account (ecs-local-container-endpoints+release@amazon.com).
13+
14+
Create a GitHub [personal access token](https://github.com/settings/tokens) with access to your fork of the repo, including "admin:repo_hook" and "repo" permissions. Then store the token in Secrets Manager:
15+
16+
```
17+
aws secretsmanager create-secret --region us-west-2 --name EcsDevXGitHubToken --secret-string <my-github-personal-access-token>
18+
```
19+
20+
## Deploy
21+
22+
To deploy this pipeline, install the AWS CDK CLI: `npm i -g aws-cdk`
23+
24+
Install and build everything: `npm install && npm run build`
25+
26+
Then deploy the pipeline stacks:
27+
28+
```
29+
cdk deploy --app 'node pipeline.js'
30+
31+
```
32+
33+
See the pipelines in the CodePipeline console.

0 commit comments

Comments
 (0)