Skip to content

Commit 28b23f6

Browse files
meghnaprhossain-rayhan
authored andcommitted
Support for ARM64 build
1 parent 6c26e38 commit 28b23f6

File tree

10 files changed

+132
-44
lines changed

10 files changed

+132
-44
lines changed

buildspec.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,24 @@ phases:
1414
# List the docker images
1515
- docker images
1616

17-
# Push the image to ECR in the same account and same region the pipeline is hosted.
18-
- docker tag amazon/aws-for-fluent-bit:latest amazon/aws-for-fluent-bit-test:latest
19-
- ecs-cli push amazon/aws-for-fluent-bit-test:latest
17+
# Push the image to ECR with corresponding architecture as the tag.
18+
- aws ecr get-login-password --region ${AWS_REGION}| docker login --username AWS --password-stdin ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com
19+
- aws ecr create-repository --repository-name amazon/aws-for-fluent-bit-test --image-scanning-configuration scanOnPush=true --region ${AWS_REGION} || true
20+
- architecture=$(docker inspect --format='{{.Architecture}}' amazon/aws-for-fluent-bit)
21+
- docker tag amazon/aws-for-fluent-bit:latest ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:$architecture
22+
- docker push ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:$architecture
23+
24+
# Create manifest list
25+
- export DOCKER_CLI_EXPERIMENTAL=enabled
26+
- docker manifest create ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:latest ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:arm64 ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:amd64 || true
27+
- docker manifest annotate --arch arm64 ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:latest ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:arm64 || true
28+
- docker manifest annotate --arch amd64 ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:latest ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:amd64 || true
29+
30+
# Sanity check for the debug log
31+
- docker manifest inspect ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:latest || true
32+
33+
# Push manifest list
34+
- docker manifest push ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:latest || true
2035
artifacts:
2136
files:
22-
- '**/*'
37+
- '**/*'

buildspec_integ.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ phases:
1515
- 'export AWS_SESSION_TOKEN=`echo $CREDS | jq -r .Token`'
1616

1717
# Pull the image that we built and pushed in the `Build` stage
18-
- 'ecs-cli pull amazon/aws-for-fluent-bit-test:latest'
19-
- 'docker tag ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:latest amazon/aws-for-fluent-bit:latest'
18+
- aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com
19+
- docker pull ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:latest
20+
- docker tag ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test amazon/aws-for-fluent-bit:latest
21+
22+
# List the images to do a double check
23+
- docker images
2024

21-
# List the images to do a double check
22-
- 'docker images'
23-
24-
# Command to run the integration test
25-
- 'make integ'
25+
# Command to run the integration test
26+
- make integ
2627
artifacts:
2728
files:
2829
- '**/*'

buildspec_publish_dockerhub.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ phases:
99
build:
1010
commands:
1111
# Pull the image that we built and pushed in the `Build` stage
12-
- 'ecs-cli pull amazon/aws-for-fluent-bit-test:latest'
13-
- 'docker tag ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:latest amazon/aws-for-fluent-bit:latest'
12+
- aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com
13+
- docker pull ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:"amd64"
14+
- docker pull ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:"arm64"
15+
- docker tag ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:amd64 amazon/aws-for-fluent-bit:amd64
16+
- docker tag ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:arm64 amazon/aws-for-fluent-bit:arm64
1417

1518
# List the docker images
1619
- docker images

buildspec_publish_ecr.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ phases:
99
build:
1010
commands:
1111
# Pull the image that we built and pushed in the `Build` stage
12-
- 'ecs-cli pull amazon/aws-for-fluent-bit-test:latest'
13-
- 'docker tag ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:latest amazon/aws-for-fluent-bit:latest'
14-
12+
- aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com
13+
- docker pull ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:"amd64"
14+
- docker pull ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:"arm64"
15+
1516
# List the docker images
1617
- docker images
1718

integ/integ.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ export AWS_REGION="us-west-2"
33
export PROJECT_ROOT="$(pwd)"
44

55
test_cloudwatch() {
6-
export LOG_GROUP_NAME="fluent-bit-integ-test"
6+
export ARCHITECTURE=$(uname -m)
7+
export LOG_GROUP_NAME="fluent-bit-integ-test-${ARCHITECTURE}"
78
# Tag is used to name the log stream; each test run has a unique (random) log stream name
89
export TAG=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 10)
910
docker-compose --file ./integ/test_cloudwatch/docker-compose.test.yml build
1011
docker-compose --file ./integ/test_cloudwatch/docker-compose.test.yml up --abort-on-container-exit
11-
sleep 10
12+
sleep 120
1213

1314
# Creates a file as a flag for the validation failure
1415
mkdir -p ./integ/out
@@ -20,7 +21,7 @@ test_cloudwatch() {
2021
}
2122

2223
clean_cloudwatch() {
23-
export LOG_GROUP_NAME="fluent-bit-integ-test"
24+
export LOG_GROUP_NAME="fluent-bit-integ-test-${ARCHITECTURE}"
2425
# Clean up resources that were created in the test
2526
docker-compose --file ./integ/test_cloudwatch/docker-compose.clean.yml build
2627
docker-compose --file ./integ/test_cloudwatch/docker-compose.clean.yml up --abort-on-container-exit
@@ -81,7 +82,6 @@ test_firehose() {
8182
clean_s3() {
8283
validate_or_clean_s3 clean
8384
}
84-
8585
if [ "${1}" = "cloudwatch" ]; then
8686
export PLUGIN_UNDER_TEST="cloudwatch"
8787
test_cloudwatch
@@ -163,4 +163,4 @@ fi
163163

164164
if [ "${1}" = "delete" ]; then
165165
source ./integ/resources/delete_test_resources.sh
166-
fi
166+
fi
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/bash
22

33
# Deploys the CloudFormation template to create the stack and necessary resources- kinesis data stream, s3 bucket, and kinesis firehose delivery stream
4-
# Resource (stream, s3, delivery stream) names will start with the stack name "integ-test-fluent-bit"
5-
aws cloudformation deploy --template-file ./integ/resources/cfn-kinesis-s3-firehose.yml --stack-name integ-test-fluent-bit --region us-west-2 --capabilities CAPABILITY_NAMED_IAM
4+
# Resource (stream, s3, delivery stream) names will start with the stack name followed by the corresponding architecture. "integ-test-fluent-bit-architecture"
5+
ARCHITECTURE=$(uname -m)
6+
if [ ARCHITECTURE=="x86_64" ]
7+
then
8+
ARCHITECTURE="x86-64"
9+
fi
10+
aws cloudformation deploy --template-file ./integ/resources/cfn-kinesis-s3-firehose.yml --stack-name integ-test-fluent-bit-${ARCHITECTURE} --region us-west-2 --capabilities CAPABILITY_NAMED_IAM
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
# Delete the CloudFormation stack which created all the resources for running the integration test
2-
aws cloudformation delete-stack --stack-name integ-test-fluent-bit
2+
ARCHITECTURE=$(uname -m)
3+
if [ ARCHITECTURE=="x86_64" ]
4+
then
5+
ARCHITECTURE="x86-64"
6+
fi
7+
aws cloudformation delete-stack --stack-name integ-test-fluent-bit-${ARCHITECTURE}

integ/resources/setup_test_environment.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#!/bin/bash
22

33
# Using CloudFormation describe-stacks extracts the output values for kinesis stream and s3 bucket name, and sets them as environment variables
4-
stackOutputs=$(aws cloudformation describe-stacks --stack-name integ-test-fluent-bit --output text --query 'Stacks[0].Outputs[*].OutputValue')
4+
ARCHITECTURE=$(uname -m)
5+
if [ ARCHITECTURE=="x86_64" ]
6+
then
7+
ARCHITECTURE="x86-64"
8+
fi
9+
stackOutputs=$(aws cloudformation describe-stacks --stack-name integ-test-fluent-bit-${ARCHITECTURE} --output text --query 'Stacks[0].Outputs[*].OutputValue')
510
read -r -a outputArray <<< "$stackOutputs"
611
export FIREHOSE_STREAM="${outputArray[0]}"
712
export KINESIS_STREAM="${outputArray[1]}"

integ/validate_cloudwatch/validator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
client = boto3.client('logs', region_name=os.environ.get('AWS_REGION'))
1010
metrics_client = boto3.client("cloudwatch", region_name=os.environ["AWS_REGION"])
11-
start_time = datetime.utcnow() - timedelta(seconds=60)
11+
start_time = datetime.utcnow() - timedelta(seconds=600)
1212
end_time = datetime.utcnow()
1313

1414
LOG_GROUP_NAME = os.environ.get('LOG_GROUP_NAME')
@@ -55,7 +55,7 @@ def validate_metric(test_name, metric_namespace, dim_key, dim_value, expected_sa
5555
return True
5656
attempts += 1
5757
print(f"No metrics yet. Sleeping before trying again. Attempt # {attempts}")
58-
time.sleep(2)
58+
time.sleep(10)
5959

6060
sys.exit('TEST_FAILURE: failed to validate metric existence in CloudWatch')
6161

@@ -102,4 +102,4 @@ def get_expected_metric_name():
102102

103103
if success_case_1 and success_case_2 and success_case_emf:
104104
# if this file is still present, integ script will mark the test as a failure
105-
os.remove("/out/cloudwatch-test")
105+
os.remove("/out/cloudwatch-test")

scripts/publish.sh

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,11 @@ gamma_account_id="626332813196"
7373

7474
DOCKER_HUB_SECRET="com.amazonaws.dockerhub.aws-for-fluent-bit.credentials"
7575

76+
ARCHITECTURES=("amd64" "arm64")
77+
7678
publish_to_docker_hub() {
7779
DRY_RUN="${DRY_RUN:-true}"
80+
export DOCKER_CLI_EXPERIMENTAL=enabled
7881

7982
username="$(aws secretsmanager get-secret-value --secret-id $DOCKER_HUB_SECRET --region us-west-2 | jq -r '.SecretString | fromjson.username')"
8083
password="$(aws secretsmanager get-secret-value --secret-id $DOCKER_HUB_SECRET --region us-west-2 | jq -r '.SecretString | fromjson.password')"
@@ -90,13 +93,23 @@ publish_to_docker_hub() {
9093

9194
# Publish to DockerHub only if $DRY_RUN is set to false
9295
if [[ "${DRY_RUN}" == "false" ]]; then
93-
docker tag ${1} ${2}
94-
docker push ${1}
95-
docker push ${2}
96+
for arch in "${ARCHITECTURES[@]}"
97+
do
98+
docker tag ${1}:"$arch" ${1}:"${arch}"-${AWS_FOR_FLUENT_BIT_VERSION}
99+
docker push ${1}:"$arch"-${AWS_FOR_FLUENT_BIT_VERSION}
100+
done
101+
102+
create_manifest_list ${1} "latest"
103+
create_manifest_list ${1} ${AWS_FOR_FLUENT_BIT_VERSION}
104+
96105
else
97-
echo "DRY_RUN: docker tag ${1} ${2}"
98-
echo "DRY_RUN: docker push ${1}"
99-
echo "DRY_RUN: docker push ${2}"
106+
for arch in "${ARCHITECTURES[@]}"
107+
do
108+
echo "DRY_RUN: docker tag ${1}:${arch} ${1}:${arch}-${AWS_FOR_FLUENT_BIT_VERSION}"
109+
echo "DRY_RUN: docker push ${1}:${arch}-${AWS_FOR_FLUENT_BIT_VERSION}"
110+
done
111+
echo "DRY_RUN: create manifest list ${1}:latest"
112+
echo "DRY_RUN: create manifest list ${1}:${AWS_FOR_FLUENT_BIT_VERSION}"
100113
echo "DRY_RUN is NOT set to 'false', skipping DockerHub update. Exiting..."
101114
fi
102115

@@ -173,11 +186,41 @@ verify_ssm() {
173186
fi
174187
}
175188

176-
push_to_ecr() {
177-
docker tag ${1} ${2}
178-
ecs-cli push ${2} --region ${3} --registry-id ${4}
189+
create_manifest_list() {
190+
191+
export DOCKER_CLI_EXPERIMENTAL=enabled
192+
tag=${2}
193+
194+
# TODO: Add a way to automatically generate arch images in manifest
195+
docker manifest create ${1}:${tag} \
196+
${1}:arm64-${AWS_FOR_FLUENT_BIT_VERSION} \
197+
${1}:amd64-${AWS_FOR_FLUENT_BIT_VERSION}
198+
199+
for arch in "${ARCHITECTURES[@]}"
200+
do
201+
docker manifest annotate --arch "$arch" \
202+
${1}:${tag} \
203+
${1}:"$arch"-${AWS_FOR_FLUENT_BIT_VERSION}
204+
done
205+
206+
# sanity check on the debug log.
207+
docker manifest inspect ${1}:${tag}
208+
docker manifest push ${1}:${tag}
209+
}
210+
211+
push_image_ecr() {
212+
account_id=${1}
213+
region=${2}
214+
215+
for arch in "${ARCHITECTURES[@]}"
216+
do
217+
docker tag ${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/amazon/aws-for-fluent-bit-test:"$arch" \
218+
${account_id}.dkr.ecr.${region}.amazonaws.com/aws-for-fluent-bit:"$arch"-${AWS_FOR_FLUENT_BIT_VERSION}
219+
docker push ${account_id}.dkr.ecr.${region}.amazonaws.com/aws-for-fluent-bit:"$arch"-${AWS_FOR_FLUENT_BIT_VERSION}
220+
done
179221
}
180222

223+
# TODO: remove dependency on ecs-cli
181224
pull_ecr() {
182225
ecs-cli pull ${1} --region ${2}
183226
}
@@ -189,8 +232,17 @@ make_repo_public() {
189232
publish_ecr() {
190233
region=${1}
191234
account_id=${2}
192-
push_to_ecr amazon/aws-for-fluent-bit:latest aws-for-fluent-bit:latest ${region} ${account_id}
193-
push_to_ecr amazon/aws-for-fluent-bit:latest "aws-for-fluent-bit:${AWS_FOR_FLUENT_BIT_VERSION}" ${region} ${account_id}
235+
echo $region
236+
echo $account_id
237+
238+
aws ecr get-login-password --region ${region}| docker login --username AWS --password-stdin ${account_id}.dkr.ecr.${region}.amazonaws.com
239+
aws ecr create-repository --repository-name aws-for-fluent-bit --image-scanning-configuration scanOnPush=true --region ${region} || true
240+
241+
push_image_ecr ${account_id} ${region}
242+
243+
create_manifest_list ${account_id}.dkr.ecr.${region}.amazonaws.com/aws-for-fluent-bit ${AWS_FOR_FLUENT_BIT_VERSION}
244+
create_manifest_list ${account_id}.dkr.ecr.${region}.amazonaws.com/aws-for-fluent-bit "latest"
245+
194246
make_repo_public ${region}
195247
}
196248

@@ -204,14 +256,15 @@ verify_ecr() {
204256
endpoint=${endpoint}.cn
205257
fi
206258

207-
pull_ecr ${account_id}.dkr.ecr.${region}.${endpoint}/aws-for-fluent-bit:latest ${region}
259+
aws ecr get-login-password --region ${region} | docker login --username AWS --password-stdin ${account_id}.dkr.ecr.${region}.amazonaws.com
260+
docker pull ${account_id}.dkr.ecr.${region}.${endpoint}/aws-for-fluent-bit:latest
208261
sha1=$(docker inspect --format='{{index .RepoDigests 0}}' ${account_id}.dkr.ecr.${region}.${endpoint}/aws-for-fluent-bit:latest)
209262

210263
if [ "${is_sync_task}" = "true" ]; then
211264
pull_ecr ${account_id}.dkr.ecr.${region}.${endpoint}/aws-for-fluent-bit:${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB} ${region}
212265
sha2=$(docker inspect --format='{{index .RepoDigests 0}}' ${account_id}.dkr.ecr.${region}.${endpoint}/aws-for-fluent-bit:${AWS_FOR_FLUENT_BIT_VERSION_DOCKERHUB})
213266
else
214-
pull_ecr ${account_id}.dkr.ecr.${region}.${endpoint}/aws-for-fluent-bit:${AWS_FOR_FLUENT_BIT_VERSION} ${region}
267+
docker pull ${account_id}.dkr.ecr.${region}.${endpoint}/aws-for-fluent-bit:${AWS_FOR_FLUENT_BIT_VERSION}
215268
sha2=$(docker inspect --format='{{index .RepoDigests 0}}' ${account_id}.dkr.ecr.${region}.${endpoint}/aws-for-fluent-bit:${AWS_FOR_FLUENT_BIT_VERSION})
216269
fi
217270

@@ -259,7 +312,7 @@ match_two_sha() {
259312

260313
if [ "${1}" = "publish" ]; then
261314
if [ "${2}" = "dockerhub" ]; then
262-
publish_to_docker_hub amazon/aws-for-fluent-bit:latest amazon/aws-for-fluent-bit:${AWS_FOR_FLUENT_BIT_VERSION}
315+
publish_to_docker_hub amazon/aws-for-fluent-bit
263316
fi
264317

265318
if [ "${2}" = "aws" ]; then
@@ -417,7 +470,7 @@ fi
417470
# Following scripts will be called only from the CI/CD pipeline
418471
if [ "${1}" = "cicd-publish" ]; then
419472
if [ "${2}" = "dockerhub" ]; then
420-
publish_to_docker_hub amazon/aws-for-fluent-bit:latest amazon/aws-for-fluent-bit:${AWS_FOR_FLUENT_BIT_VERSION}
473+
publish_to_docker_hub amazon/aws-for-fluent-bit
421474
elif [ "${2}" = "us-gov-east-1" ] || [ "${2}" = "us-gov-west-1" ]; then
422475
for region in ${gov_regions}; do
423476
sync_latest_image ${region} ${gov_regions_account_id}
@@ -496,4 +549,4 @@ if [ "${1}" = "cicd-verify-ssm" ]; then
496549
verify_ssm ${region}
497550
done
498551
fi
499-
fi
552+
fi

0 commit comments

Comments
 (0)