Skip to content

Handle case where /tmp directory is mounted with noexec #11

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

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ name: Test

on: [ push ]

env:
# This is required to support GLIB versions present in amazon linux 2. Can be removed once amazon linux 2 is 💀
# More info
# - https://github.com/actions/checkout/issues/1809#issuecomment-2208202462
# - https://github.blog/changelog/2024-03-07-github-actions-all-actions-will-run-on-node20-instead-of-node16-by-default/
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true

jobs:
test_python_installation:
strategy:
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,3 @@ will be used and hence will be very fast (4 to 5 seconds)
## Contributing

Contributions are most welcome! See [CONTRIBUTING.md](./CONTRIBUTING.md)

17 changes: 10 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,33 @@ runs:
shell: bash
run: |
exact_python_version="${{ steps.find-exact-python-version.outputs.exact_python_version }}"
echo "installation_directory=~/setup-python-amazon-linux/.python-versions/${exact_python_version}" >> $GITHUB_OUTPUT
echo "installation_directory=${HOME}/.setup-python-amazon-linux/.python-versions/${exact_python_version}" >> $GITHUB_OUTPUT

- name: Cache
id: cache-python
uses: actions/cache@v3
if: inputs.cache == 'true'
with:
path: |
${{ steps.set-installation-directory.outputs.installation_directory }}
path: ${{ steps.set-installation-directory.outputs.installation_directory }}
key: python-${{ steps.find-exact-python-version.outputs.exact_python_version }}-${{ runner.arch }}

- id: setup-python
shell: bash
if: inputs.cache == 'false' || (inputs.cache == 'true' && steps.cache-python.outputs.cache-hit != 'true')
run: |
installation_directory=${{ steps.set-installation-directory.outputs.installation_directory }}
mkdir -p "${installation_directory}"
installation_directory="${{ steps.set-installation-directory.outputs.installation_directory }}"
exact_python_version="${{ steps.find-exact-python-version.outputs.exact_python_version }}"
${GITHUB_ACTION_PATH}/install-python.sh "${exact_python_version}" "${installation_directory}"

# Using a separate tmp directory instead of /tmp because in some OS images set a noexec option for the mount
# this is a better way compared to changing the mount options of /tmp
tmp_directory="${HOME}/.setup-python-amazon-linux/tmp"

${GITHUB_ACTION_PATH}/install-python.sh "${exact_python_version}" "${installation_directory}" "${tmp_directory}"

- name: Add python to PATH
shell: bash
run: |
installation_directory=${{ steps.set-installation-directory.outputs.installation_directory }}
installation_directory="${{ steps.set-installation-directory.outputs.installation_directory }}"
echo "${installation_directory}/bin" >> "${GITHUB_PATH}"

echo "The following python binaries are now available in the PATH"
Expand Down
13 changes: 9 additions & 4 deletions install-python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ function set_aliases() {

# Reference - https://realpython.com/installing-python/#how-to-build-python-from-source-code
function setup_python() {
python_version="$1"
python_installation_dir="$2"
python_version="${1:?}"
python_installation_dir="${2:?}"
temp_dir="${3:?}"

mkdir -p "${python_installation_dir}"
temp_dir=$(mktemp -d)
mkdir -p "${temp_dir}"
rm -rf "${python_installation_dir:?}/*"
rm -rf "${temp_dir:?}/*"

echo "Installing python from temporary directory ${temp_dir}"
pushd "${temp_dir}" >/dev/null
wget "https://www.python.org/ftp/python/${python_version}/Python-${python_version}.tgz"
tar -zxf "Python-${python_version}.tgz"
Expand All @@ -34,4 +39,4 @@ function setup_python() {
set_aliases
}

setup_python "$1" "$2"
setup_python "$1" "$2" "$3"
Loading