diff --git a/Makefile b/Makefile index 5ead2975a8a..e8a28594b8f 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/buildspecs/pr-build-amzn.yml b/buildspecs/pr-build-amzn.yml new file mode 100644 index 00000000000..797d004aac0 --- /dev/null +++ b/buildspecs/pr-build-amzn.yml @@ -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)" -)" + - 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 + diff --git a/buildspecs/pr-build-ubuntu.yml b/buildspecs/pr-build-ubuntu.yml index a2766ec6715..822b8370c6c 100644 --- a/buildspecs/pr-build-ubuntu.yml +++ b/buildspecs/pr-build-ubuntu.yml @@ -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 diff --git a/buildspecs/pr-build.yml b/buildspecs/pr-build.yml index 65821221b08..78ba5887d2c 100644 --- a/buildspecs/pr-build.yml +++ b/buildspecs/pr-build.yml @@ -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 @@ -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 @@ -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: @@ -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 \ No newline at end of file