-
-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Running Container as Runner Host User (#600)
- Added `runAsHostUser` to allow running the container as the same user as the host system. This fixes most permissions issues on self-hosted runners. - Perform android sdk setup during entrypoint.sh to ensure it has root permissions if the user switches to a non-root user - Automatically detect android sdk target version if parameters are not already provided to configure the sdk - Generate a new uuid for machineID to ensure separate containers are unique to reduce license activation errors - Add exponential retry strategy for Ubuntu license activations
- Loading branch information
1 parent
8da77ac
commit 8ca1282
Showing
15 changed files
with
174 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,76 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Ensure machine ID is randomized | ||
dbus-uuidgen > /etc/machine-id && mkdir -p /var/lib/dbus/ && ln -sf /etc/machine-id /var/lib/dbus/machine-id | ||
|
||
# | ||
# Create directory for license activation | ||
# Prepare Android SDK, if needed | ||
# We do this here to ensure it has root permissions | ||
# | ||
|
||
ACTIVATE_LICENSE_PATH="$GITHUB_WORKSPACE/_activate-license~" | ||
mkdir -p "$ACTIVATE_LICENSE_PATH" | ||
fullProjectPath="$GITHUB_WORKSPACE/$PROJECT_PATH" | ||
|
||
# | ||
# Run steps | ||
# | ||
source /steps/set_extra_git_configs.sh | ||
source /steps/set_gitcredential.sh | ||
source /steps/activate.sh | ||
source /steps/build.sh | ||
source /steps/return_license.sh | ||
if [[ "$BUILD_TARGET" == "Android" ]]; then | ||
export JAVA_HOME="$(awk -F'=' '/JAVA_HOME=/{print $2}' /usr/bin/unity-editor.d/*)" | ||
ANDROID_HOME_DIRECTORY="$(awk -F'=' '/ANDROID_HOME=/{print $2}' /usr/bin/unity-editor.d/*)" | ||
SDKMANAGER=$(find $ANDROID_HOME_DIRECTORY/cmdline-tools -name sdkmanager) | ||
if [ -z "${SDKMANAGER}" ] | ||
then | ||
echo "No sdkmanager found" | ||
exit 1 | ||
fi | ||
|
||
# | ||
# Remove license activation directory | ||
# | ||
if [[ -n "$ANDROID_SDK_MANAGER_PARAMETERS" ]]; then | ||
echo "Updating Android SDK with parameters: $ANDROID_SDK_MANAGER_PARAMETERS" | ||
$SDKMANAGER "$ANDROID_SDK_MANAGER_PARAMETERS" | ||
else | ||
echo "Updating Android SDK with auto detected target API version" | ||
# Read the line containing AndroidTargetSdkVersion from the file | ||
targetAPILine=$(grep 'AndroidTargetSdkVersion' "$fullProjectPath/ProjectSettings/ProjectSettings.asset") | ||
|
||
rm -r "$ACTIVATE_LICENSE_PATH" | ||
chmod -R 777 "/BlankProject" | ||
# Extract the number after the semicolon | ||
targetAPI=$(echo "$targetAPILine" | cut -d':' -f2 | tr -d '[:space:]') | ||
|
||
# | ||
# Instructions for debugging | ||
# | ||
$SDKMANAGER "platforms;android-$targetAPI" | ||
fi | ||
|
||
if [[ $BUILD_EXIT_CODE -gt 0 ]]; then | ||
echo "" | ||
echo "###########################" | ||
echo "# Failure #" | ||
echo "###########################" | ||
echo "" | ||
echo "Please note that the exit code is not very descriptive." | ||
echo "Most likely it will not help you solve the issue." | ||
echo "" | ||
echo "To find the reason for failure: please search for errors in the log above." | ||
echo "" | ||
fi; | ||
echo "Updated Android SDK." | ||
else | ||
echo "Not updating Android SDK." | ||
fi | ||
|
||
# | ||
# Exit with code from the build step. | ||
# | ||
if [[ "$RUN_AS_HOST_USER" == "true" ]]; then | ||
echo "Running as host user" | ||
|
||
# Stop on error if we can't set up the user | ||
set -e | ||
|
||
# Get host user/group info so we create files with the correct ownership | ||
USERNAME=$(stat -c '%U' "$fullProjectPath") | ||
USERID=$(stat -c '%u' "$fullProjectPath") | ||
GROUPNAME=$(stat -c '%G' "$fullProjectPath") | ||
GROUPID=$(stat -c '%g' "$fullProjectPath") | ||
|
||
groupadd -g $GROUPID $GROUPNAME | ||
useradd -u $USERID -g $GROUPID $USERNAME | ||
usermod -aG $GROUPNAME $USERNAME | ||
mkdir -p "/home/$USERNAME" | ||
chown $USERNAME:$GROUPNAME "/home/$USERNAME" | ||
|
||
# Normally need root permissions to access when using su | ||
chmod 777 /dev/stdout | ||
chmod 777 /dev/stderr | ||
|
||
# Don't stop on error when running our scripts as error handling is baked in | ||
set +e | ||
|
||
# Switch to the host user so we can create files with the correct ownership | ||
su $USERNAME -c "$SHELL -c 'source /steps/runsteps.sh'" | ||
else | ||
echo "Running as root" | ||
|
||
# Run as root | ||
source /steps/runsteps.sh | ||
fi | ||
|
||
exit $BUILD_EXIT_CODE | ||
exit $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# Run steps | ||
# | ||
source /steps/set_extra_git_configs.sh | ||
source /steps/set_gitcredential.sh | ||
source /steps/activate.sh | ||
|
||
# If we didn't activate successfully, exit with the exit code from the activation step. | ||
if [[ $UNITY_EXIT_CODE -ne 0 ]]; then | ||
exit $UNITY_EXIT_CODE | ||
fi | ||
|
||
source /steps/build.sh | ||
source /steps/return_license.sh | ||
|
||
# | ||
# Instructions for debugging | ||
# | ||
|
||
if [[ $BUILD_EXIT_CODE -gt 0 ]]; then | ||
echo "" | ||
echo "###########################" | ||
echo "# Failure #" | ||
echo "###########################" | ||
echo "" | ||
echo "Please note that the exit code is not very descriptive." | ||
echo "Most likely it will not help you solve the issue." | ||
echo "" | ||
echo "To find the reason for failure: please search for errors in the log above and check for annotations in the summary view." | ||
echo "" | ||
fi; | ||
|
||
# | ||
# Exit with code from the build step. | ||
# | ||
|
||
# Exiting su | ||
exit $BUILD_EXIT_CODE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.