Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building Amazon Linux RPMs and a Windows executable #4220

Merged
merged 27 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
05d7e81
New Branch off master only adding AL make target to pr-build
Ephylouise Jun 19, 2024
af7d1bd
Replace RELEASE_COMMIT with GO_VERSION in Makefile
Ephylouise Jun 20, 2024
0c3ad34
Correcting username syntax, capital letter
Ephylouise Jun 20, 2024
6ce9caa
Adjust if/then func syntax for AMD environment
Ephylouise Jun 20, 2024
3cfce9f
Add Windows make target in Makefile and pr-build.yml
Ephylouise Jun 20, 2024
cde96f2
Create amzn2 and amzn23 buildspec files
Ephylouise Jun 20, 2024
a7af528
Windows target to rely on inherent logic, add get-cni-sources to AL t…
Ephylouise Jun 21, 2024
e70054e
Redirect windows artifact to correct path
Ephylouise Jun 21, 2024
edb5be1
Remove goenv installed version of go for AL buildspecs
Ephylouise Jun 24, 2024
e23b08e
Set GOROOT for arch type in amzn2 buildspecs
Ephylouise Jun 24, 2024
d118e64
Adding Windows-specific buildspec file
Ephylouise Jun 24, 2024
835ddab
Switching to PowerShell syntax in windows buildspec
Ephylouise Jun 24, 2024
9604f8e
Remove duplicate go version command
Ephylouise Jun 25, 2024
d9b8970
Remove windows specific docker-release
Ephylouise Jun 25, 2024
b410433
Removing a bracket in path adjustment if/then for ubuntu OS buildspec
Ephylouise Jun 25, 2024
13a54e8
Add function to install golang per AL version
Ephylouise Jun 26, 2024
458db4c
Install go based on AL23 version update
Ephylouise Jun 26, 2024
6e10189
Add architecture naming to the file path
Ephylouise Jun 26, 2024
0c0b30b
Rename consolidated Amazon Linux spec, remove pr-build-amzn23.yml
Ephylouise Jun 26, 2024
d930653
Remove changes to amazon-linux-sources.tgz in Makefile
Ephylouise Jun 27, 2024
1efe6eb
Add new make target for AL codebuild jobs
Ephylouise Jun 27, 2024
4ee70f8
Use the os-release file to detect Amazon Linux version
Ephylouise Jun 27, 2024
ed5aaf0
Temporarily change githubusername for CodeBuild testing
Ephylouise Jun 27, 2024
d03102c
Restore githubusername aws after CodeBuild testing
Ephylouise Jun 27, 2024
c20567c
Merge branch 'dev' into dev-stephyr
Ephylouise Jul 1, 2024
540bbcb
Add AL23 ref doc and install specific go version
Ephylouise Jul 1, 2024
d7e4f90
Merge branch 'dev' into dev-stephyr
Ephylouise Jul 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,23 @@ amazon-linux-sources.tgz:

amazon-linux-rpm-integrated: .amazon-linux-rpm-integrated-done

# Make target for Amazon Linux Codebuild jobs
.amazon-linux-rpm-codebuild-done: get-cni-sources
./scripts/update-version.sh
cp packaging/amazon-linux-ami-integrated/ecs-agent.spec ecs-agent.spec
cp packaging/amazon-linux-ami-integrated/ecs.conf ecs.conf
cp packaging/amazon-linux-ami-integrated/ecs.service ecs.service
cp packaging/amazon-linux-ami-integrated/amazon-ecs-volume-plugin.conf amazon-ecs-volume-plugin.conf
cp packaging/amazon-linux-ami-integrated/amazon-ecs-volume-plugin.service amazon-ecs-volume-plugin.service
cp packaging/amazon-linux-ami-integrated/amazon-ecs-volume-plugin.socket amazon-ecs-volume-plugin.socket
tar -czf ./sources.tgz ecs-init scripts misc agent amazon-ecs-cni-plugins amazon-vpc-cni-plugins agent-container Makefile VERSION GO_VERSION
test -e SOURCES || ln -s . SOURCES
rpmbuild --define "%_topdir $(PWD)" -bb ecs-agent.spec
find RPMS/ -type f -exec cp {} . \;
touch .amazon-linux-rpm-codebuild-done

amazon-linux-rpm-codebuild: .amazon-linux-rpm-codebuild-done

.generic-rpm-integrated-done: get-cni-sources
./scripts/update-version.sh
cp packaging/generic-rpm-integrated/amazon-ecs-init.spec amazon-ecs-init.spec
Expand Down
125 changes: 125 additions & 0 deletions buildspecs/pr-build-amzn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
version: 0.2

env:
variables:
# Github username of the forked repo on which to make builds
GITHUBUSERNAME: aws

phases:
install:
commands:
# Same buildspec used for different Amazon Linux versions - detect verison to use in Go installation
- |
if [ -f /etc/os-release ]; then
. /etc/os-release
case $ID:$VERSION_ID in
amzn:2)
amzn_version="amzn2"
;;
amzn:2023)
amzn_version="amzn2023"
;;
*)
echo "Unsupported Linux distribution: $ID:$VERSION_ID"
exit 1
;;
esac
else
echo "Unable to detect the Linux distribution"
exit 1
fi

# Same buildspec for different architectures - detect the architecture here and rename the artifacts accordingly
- architecture=""
- case $(uname -m) in
x86_64)
architecture="amd64"
;;
aarch64)
architecture="arm64"
;;
esac

# Identify the correct AL2023 version to use in the Go installation
# Ref: https://docs.aws.amazon.com/linux/al2023/ug/managing-repos-os-updates.html
# xmllint is required to find the latest distribution release from releasemd.xml in us-west-2
- AL23_VERSION="$(curl -s https://al2023-repos-us-west-2-de612dc2.s3.dualstack.us-west-2.amazonaws.com/core/releasemd.xml | xmllint --xpath "string(//root/releases/release[last()]/@version)" -)"
Ephylouise marked this conversation as resolved.
Show resolved Hide resolved
- AGENT_VERSION=$(cat VERSION)

# Need to install GOLANG explicitly as required versions do not come preinstalled
# Remove existing go installation (goenv utility)
- sudo rm -rf /root/.goenv
- sudo rm -rf /usr/local/go/bin/go

# Define the Go version to install
- GOVERSION="$(cat GO_VERSION)"

# Install Go and define variables based on Amazon Linux version (2 or 2023)
# Amazon Linux 2023 uses package manager DNF, while older versions use YUM
# Set the appropriate AL23 version echo string to include in build log
- |
if [[ "$amzn_version" = "amzn2023" ]]; then
sudo dnf --releasever="$AL23_VERSION" update -y
sudo yum install -y golang-$GOVERSION
amzn_version="amzn2023"
al23_version_echo="Amazon Linux 2023 Version: $AL23_VERSION"
elif [[ "$amzn_version" = "amzn2" ]]; then
sudo yum install -y golang-$GOVERSION
amzn_version="amzn2"
al23_version_echo=""
else
echo "Unsupported Amazon Linux version"
exit 1
fi

# Define the log file with AL version (amzn2 or amzn23) and the architecture
- BUILD_LOG="build_${amzn_version}_${architecture}.log"

# Print all environment variables to the log file
# Amazon Linux 2023 verion will print only to the AL23 log
- echo "$al23_version_echo" | tee -a $BUILD_LOG
- which go | tee -a $BUILD_LOG
- go version | tee -a $BUILD_LOG

build:
commands:
# Print the current working directory to the log file
- echo "build_id = $CODEBUILD_LOG_PATH" 2>&1 | tee -a $BUILD_LOG
- echo $(pwd) 2>&1 | tee -a $BUILD_LOG

# Define the path for the ecs-init RPM file
- AMZN_LINUX_RPM="ecs-init-${AGENT_VERSION}-1.${amzn_version}.x86_64.rpm"

# Path readjustment for codebuild testing with fork and setting GOPATH appropriately
- cd ../../../..
- export GOPATH=$GOPATH:$(pwd)
- cd src/github.com
- |
if [[ $GITHUBUSERNAME != "aws" ]]; then
mv $GITHUBUSERNAME aws
fi
- cd aws/amazon-ecs-agent

# Build Amazon Linux RPM
- GO111MODULE=auto
- make amazon-linux-rpm-codebuild 2>&1 | tee -a $BUILD_LOG
- echo $(pwd) 2>&1 | tee -a $BUILD_LOG

# Rename artifacts for architecture
- |
if [[ $architecture == "arm64" ]] ; then
AMZN_LINUX_RPM="ecs-init-${AGENT_VERSION}-1.${amzn_version}.aarch64.rpm"
fi

# List directory files to view artifacts in build log
- ls

post_build:
commands:

artifacts:
files:
- $AMZN_LINUX_RPM
- $BUILD_LOG
name: $CODEBUILD_RESOLVED_SOURCE_VERSION

2 changes: 1 addition & 1 deletion buildspecs/pr-build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ phases:
- cd ../../../..
- cd src/github.com
- |
if [[ $GITHUBUSERNAME != "aws" ]] ; then
if [ $GITHUBUSERNAME != "aws" ] ; then
mv $GITHUBUSERNAME aws
fi
- cd aws/amazon-ecs-agent
Expand Down
15 changes: 11 additions & 4 deletions buildspecs/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ phases:

build:
commands:
- go version
- echo "build_id = $CODEBUILD_LOG_PATH" 2>&1 | tee -a $BUILD_LOG
- echo "Building agent image" 2>&1 | tee -a $BUILD_LOG
- AGENT_VERSION=$(cat VERSION)
- ECS_AGENT_TAR="ecs-agent-v${AGENT_VERSION}.tar"
- CSI_DRIVER_TAR="./ecs-agent/daemonimages/csidriver/tarfiles/ebs-csi-driver.tar"
- ECS_AGENT_RPM="amazon-ecs-init-${AGENT_VERSION}-1.x86_64.rpm"
- WINDOWS_EXE="amazon-ecs-agent.exe"
- echo $(pwd) 2>&1 | tee -a $BUILD_LOG

# Path readjustment for codebuild testing with fork and setting GOPATH appropriately
Expand All @@ -64,7 +64,11 @@ phases:
- make release-agent 2>&1 | tee -a $BUILD_LOG
- make generic-rpm-integrated 2>&1 | tee -a $BUILD_LOG
- make -C ./ecs-agent/daemonimages/csidriver 2>&1 | tee -a $BUILD_LOG
- ls

# Build Windows executable
- make docker-release TARGET_OS="windows" 2>&1 | tee -a $BUILD_LOG
- cp ./out/amazon-ecs-agent.exe .

# Rename artifacts for architecture
- |
if [[ $architecture == "arm64" ]] ; then
Expand All @@ -75,6 +79,9 @@ phases:
CSI_DRIVER_TAR="./ecs-agent/daemonimages/csidriver/tarfiles/ebs-csi-driver-arm64.tar"
fi

# List directory files to view artifacts in build log
- ls

post_build:
commands:

Expand All @@ -84,5 +91,5 @@ artifacts:
- $ECS_AGENT_RPM
- $BUILD_LOG
- $CSI_DRIVER_TAR
name: $CODEBUILD_RESOLVED_SOURCE_VERSION

- $WINDOWS_EXE
name: $CODEBUILD_RESOLVED_SOURCE_VERSION
Loading