Merge branch 'main' into LoadPipelineFromGitHub

This commit is contained in:
Brian Herrera
2021-03-26 17:05:57 -07:00
765 changed files with 11513 additions and 20246 deletions
@@ -0,0 +1,84 @@
#!/bin/bash
set -euo pipefail
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
BUILD_USER=$(aws ssm get-parameters --names "shared.builderuser" --region $region --with-decryption | ConvertFrom-Json)
BUILD_PASS=$(aws ssm get-parameters --names "shared.builderpass" --region $region --with-decryption | ConvertFrom-Json)
echo "Setting up ${BUILD_USER} as autologin admin"
sudo sysadminctl -addUser "${BUILD_USER}" -fullName "${BUILD_USER}" -password "${BUILD_PASS}" -admin
sudo echo "${BUILD_USER} ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/${BUILD_USER}
sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow autoLoginUser "${BUILD_USER}"
echo "Change ownership for brew to ${BUILD_USER}"
sudo chown -R "${BUILD_USER}":admin $(brew --prefix)/*
echo "Configure SSH"
mkdir /Users/"${BUILD_USER}"/.ssh
echo "PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin" > /Users/"${BUILD_USER}"/.ssh/environment
sudo sed -i -e 's/#PermitUserEnvironment no/PermitUserEnvironment yes/g' /etc/ssh/sshd_config
sudo launchctl stop com.openssh.sshd && sudo launchctl start com.openssh.sshd
echo "Expanding root volume to EBS configurated size"
PDISK=$(diskutil list physical external | head -n1 | cut -d" " -f1)
APFSCONT=$(diskutil list physical external | grep "Apple_APFS" | tr -s " " | cut -d" " -f8)
yes | sudo diskutil repairDisk ${PDISK}
sudo diskutil apfs resizeContainer ${APFSCONT} 0
echo "Removing hibernate and sleep image"
sudo pmset hibernatemode 0
sudo rm -f /var/vm/sleepimage
echo "Disable screensaver and sleep modes"
macUUID=$(ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-62)
rm -rf /Users/"${BUILD_USER}"/Library/Preferences/com.apple.screensaver.${macUUID}.plist
rm -rf /Users/"${BUILD_USER}"/Library/Preferences/ByHost/com.apple.screensaver.${macUUID}.plist
rm -rf /Users/"${BUILD_USER}"/Library/Preferences/com.apple.screensaver.plist
rm -rf /Users/"${BUILD_USER}"/Library/Preferences/ByHost/com.apple.screensaver.plist
defaults write /Users/"${BUILD_USER}"/Library/Preferences/com.apple.screensaver.${macUUID}.plist idleTime -string 0
defaults write /Users/"${BUILD_USER}"/Library/Preferences/com.apple.screensaver.${macUUID}.plist CleanExit "YES"
defaults write /Users/"${BUILD_USER}"/Library/Preferences/ByHost/com.apple.screensaver.${macUUID}.plist idleTime -string 0
defaults write /Users/"${BUILD_USER}"/Library/Preferences/ByHost/com.apple.screensaver.${macUUID}.plist CleanExit "YES"
defaults write /Users/"${BUILD_USER}"/Library/Preferences/com.apple.screensaver.plist idleTime -string 0
defaults write /Users/"${BUILD_USER}"/Library/Preferences/com.apple.screensaver.plist CleanExit "YES"
defaults write /Users/"${BUILD_USER}"/Library/Preferences/ByHost/com.apple.screensaver.plist idleTime -string 0
defaults write /Users/"${BUILD_USER}"/Library/Preferences/ByHost/com.apple.screensaver.plist CleanExit "YES"
chown -R "${BUILD_USER}":staff /Users/"${BUILD_USER}"/Library/Preferences/ByHost/
chown -R "${BUILD_USER}":staff /Users/"${BUILD_USER}"/Library/Preferences/
killall cfprefsd
# Set values to 0, to prevent sleep at all
pmset -a displaysleep 0 sleep 0 disksleep 0
echo "Disable automatic updates"
sudo softwareupdate --schedule off
defaults write com.apple.SoftwareUpdate AutomaticDownload -int 0
defaults write com.apple.SoftwareUpdate CriticalUpdateInstall -int 0
defaults write com.apple.commerce AutoUpdate -bool false
defaults write com.apple.SoftwareUpdate AutomaticCheckEnabled -bool false
echo "Additional NTP servers adding into /etc/ntp.conf file"
cat > /etc/ntp.conf << EOF
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org
server time.apple.com
server time.windows.com
EOF
# Set the timezone to UTC.
echo "Setting timezone to UTC"
ln -sf /usr/share/zoneinfo/UTC /etc/localtime
@@ -0,0 +1,22 @@
#!/bin/bash
set -euo pipefail
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
JDK_VERSION="8.282.08.1"
echo "Installing Corretto JDK ${JDK_VERSION}"
curl -o /tmp/amazon-corretto-${JDK_VERSION}-macosx-x64.pkg https://corretto.aws/downloads/resources/${JDK_VERSION}/amazon-corretto-${JDK_VERSION}-macosx-x64.pkg
if sudo installer -allowUntrusted -pkg /tmp/amazon-corretto-${JDK_VERSION}-macosx-x64.pkg -target / ; then
rm /tmp/amazon-corretto-${JDK_VERSION}-macosx-x64.pkg
else
echo "Installation failed!"
exit 1
fi
@@ -0,0 +1,17 @@
#!/bin/bash
set -euo pipefail
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
PY3_VERSION="3.7.10"
echo "Installing Python ${PY3_VERSION}"
brew install python@${PY3_VERSION} || echo "Installation failed!"; exit 1
cat ../common/requirements.txt | cut -f1 -d"#" | sed '/^\s*$/d' | xargs -n 1 pip3 install
@@ -0,0 +1,46 @@
#!/bin/bash
set -euo pipefail
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
XCODE_VER="11.4"
S3_BUCKET=$1
echo "Installing Xcode ${XCODE_VER}"
aws s3 cp ${S3_BUCKET}/Xcode$XCODE_VER.xip /tmp/
cd /Applications
if sudo xip -x /tmp/Xcode$XCODE_VER.xip ; then
sudo xcodebuild -license accept
rm /tmp/Xcode${XCODE_VER}.xip
else
echo "Installation failed!"
exit 1
fi
echo "Installing Xcode Command line tools ${XCODE_VER}"
aws s3 cp ${S3_BUCKET}/Command_Line_Tools_for_${XCODE_VER}.dmg /tmp/
sudo hdiutil attach /tmp/Command_Line_Tools_for_${XCODE_VER}.dmg
if sudo installer -pkg /Volumes/Command\ Line\ Developer\ Tools/Command\ Line\ Tools.pkg -target / ; then
sudo hdiutil detach /Volumes/Command\ Line\ Developer\ Tools/
rm /tmp/Command_Line_Tools_for_${XCODE_VER}.dmg
else
echo "Installation failed!"
sudo hdiutil detach /Volumes/Command\ Line\ Developer\ Tools/
exit 1
fi
echo "Installing XCode iOS packages"
sudo installer -pkg /Applications/Xcode.app/Contents/Resources/Packages/MobileDevice.pkg -target /
sudo installer -pkg /Applications/Xcode.app/Contents/Resources/Packages/MobileDeviceDevelopment.pkg -target /
echo "Enabling developer mode"
sudo /usr/sbin/DevToolsSecurity --enable
@@ -0,0 +1,79 @@
#!/bin/bash
set -euo pipefail
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
set +x
# Function to get EC2 metadata within the instance
get_metadata () {
local response=$(curl -GLsX GET http://169.254.169.254/latest/meta-data/$1)
echo "${response}"
}
# Get instance data
INSTANCE_ID=$(get_metadata "instance-id")
REGION=$(get_metadata "placement/availability-zone" | sed 's/.$//')
INSTANCE_PRIVATE_IP=$(get_metadata "local-ipv4")
INSTANCE_PUBLIC_IP=$(get_metadata "public-ipv4")
INSTANCE_NAME=$(aws ec2 describe-tags --filters "Name=resource-id,Values=$INSTANCE_ID" "Name=key,Values='Name'" --region $REGION --output=text --query="Tags[0].Value" | tr -d '\r')
# Configuration parameters
CONTROLLER_URL=$1
CONTROLLER_SECRET_ID=$2
BUILD_USER=$(aws ssm get-parameters --names "shared.builderuser" --region $region --with-decryption | ConvertFrom-Json)
CONTROLLER_USERNAME=$(aws secretsmanager get-secret-value --secret-id "${CONTROLLER_SECRET_ID}" --query 'SecretString' --output text | python -c 'import sys, json;print(json.load(sys.stdin)["username"])')
CONTROLLER_PASSWORD=$(aws secretsmanager get-secret-value --secret-id "${CONTROLLER_SECRET_ID}" --query 'SecretString' --output text | python -c 'import sys, json;print(json.load(sys.stdin)["apitoken"])')
SSH_KEY="${BUILD_USER}-ssh-key"
NODE_NAME="EC2 (${REGION}) - ${INSTANCE_NAME} (${INSTANCE_ID})"
NODE_LABEL="mac-${REGION}"
ENV_PATH="$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"
# Download CLI jar from the controller
curl "${CONTROLLER_URL}"/jnlpJars/jenkins-cli.jar -o ~/jenkins-cli.jar
# Create node according to parameters passed in
cat <<EOF | java -jar ~/jenkins-cli.jar -auth "${CONTROLLER_USERNAME}:${CONTROLLER_PASSWORD}" -s "${CONTROLLER_URL}" create-node "${NODE_NAME}" |true
<slave>
<name>${NODE_NAME}</name>
<description>Ext IP: ${INSTANCE_PUBLIC_IP}</description>
<remoteFS>/Users/lybuilder/jenkins</remoteFS>
<numExecutors>1</numExecutors>
<mode>EXCLUSIVE</mode>
<retentionStrategy class="hudson.slaves.RetentionStrategy$Always"/>
<launcher class="hudson.plugins.sshslaves.SSHLauncher" plugin="ssh-slaves@1.31.5">
<host>${INSTANCE_PRIVATE_IP}</host>
<port>22</port>
<credentialsId>${SSH_KEY}</credentialsId>
<launchTimeoutSeconds>60</launchTimeoutSeconds>
<maxNumRetries>10</maxNumRetries>
<retryWaitTime>15</retryWaitTime>
<sshHostKeyVerificationStrategy class="hudson.plugins.sshslaves.verifiers.NonVerifyingKeyVerificationStrategy"/>
<tcpNoDelay>true</tcpNoDelay>
</launcher>
<label>${NODE_LABEL}</label>
<nodeProperties>
<hudson.slaves.EnvironmentVariablesNodeProperty>
<envVars serialization="custom">
<unserializable-parents/>
<tree-map>
<default>
<comparator class="hudson.util.CaseInsensitiveComparator"/>
</default>
<int>1</int>
<string>PATH</string>
<string>${ENV_PATH}</string>
</tree-map>
</envVars>
</hudson.slaves.EnvironmentVariablesNodeProperty>
</nodeProperties>
</slave>
EOF