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

Add pypy to tool cache #78

Merged
merged 2 commits into from
Oct 28, 2023
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
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"pkrvars",
"pulumi",
"pwsh",
"pypy",
"quickview",
"realpath",
"rubygems",
Expand Down
5 changes: 5 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ variable "POWERSHELL_MODULES" {
default = "[\"MarkdownPS\",\"Microsoft.Graph\",\"Pester\",\"PSScriptAnalyzer\"]"
}

variable "PYPY_VERSIONS" {
default = "[\"3.10\",\"3.9\",\"3.8\",\"3.7\"]"
}

group "default" {
targets = [
"ubuntu"
Expand Down Expand Up @@ -133,6 +137,7 @@ target "ubuntu" {
POWERSHELL_MODULES = POWERSHELL_MODULES
POWERSHELL_VERSION = release.POWERSHELL_VERSION
PULUMI_VERSION = PULUMI_VERSION
PYPY_VERSIONS = PYPY_VERSIONS
RUSTUP_HOME = "/usr/local/rustup"
TOOL_PATH_PWSH = "/usr/share/powershell"
}
Expand Down
32 changes: 32 additions & 0 deletions linux/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,35 @@ RUN KUBECTL_VERSION=$(curl -fsSL "https://dl.k8s.io/release/stable.txt") \
&& curl -sSLO "https://storage.googleapis.com/minikube/releases/latest/minikube-linux-${TARGETARCH}" \
&& install "minikube-linux-${TARGETARCH}" "${PATH_LOCAL_BINS}/minikube"

FROM base as pypy
SHELL [ "/bin/bash", "--login", "-e", "-o", "pipefail", "-c" ]
ARG PYPY_VERSIONS
RUN export PYPY_VERSIONS_JSON=/tmp/pypy_versions.json \
&& curl -fsSL https://downloads.python.org/pypy/versions.json -o "${PYPY_VERSIONS_JSON}" \
&& arch="$(uname -m)" && if [[ "${arch}" = "x86_64" ]]; then arch="x64"; fi \
&& export arch \
&& export PYPY_TMP_ARCHIVE=/tmp/pypy.tar.bz2 \
&& versions=() \
&& while IFS='' read -r version; do versions+=("$version"); done < <(printf "%s\n" "${PYPY_VERSIONS}" | jq -r '.[]') \
&& for version in "${versions[@]}"; do latest_python_version=$(jq --arg version "$version" -r '.[] | select((.python_version | startswith($version)) and (.stable==true)) | .python_version' "${PYPY_VERSIONS_JSON}" | sort -V | tail -n1) \
&& echo "loading PyPy ${latest_python_version} for arch ${arch}" \
&& curl -fsSL "$(jq \
--arg latest_python_version "${latest_python_version}" \
--arg arch "${arch}" \
-r 'map(select((.python_version==$latest_python_version) and .stable==true) | .files[] | select((.arch==$arch) and (.platform=="linux")) | .download_url) | .[]' "${PYPY_VERSIONS_JSON}")" \
-o "${PYPY_TMP_ARCHIVE}" \
&& PYPY_TOOLCACHE_DIR="${AGENT_TOOLSDIRECTORY}/PyPy" \
&& PYPY_TOOLCACHE_VERSION_DIR="${PYPY_TOOLCACHE_DIR}/${latest_python_version}" \
&& PYPY_TOOLCACHE_VERSION_ARCH_DIR="${PYPY_TOOLCACHE_VERSION_DIR}/${arch}" \
&& mkdir -p "$PYPY_TOOLCACHE_VERSION_ARCH_DIR" \
&& tar -xjf "${PYPY_TMP_ARCHIVE}" \
--strip-components=1 \
-C "$PYPY_TOOLCACHE_VERSION_ARCH_DIR" \
&& printf "%s\n" "$("${PYPY_TOOLCACHE_VERSION_ARCH_DIR}/bin/python" -c "import sys;print('{}.{}.{}'.format(*sys.pypy_version_info[0:3]))")" >"${PYPY_TOOLCACHE_VERSION_ARCH_DIR}/PYPY_VERSION" \
&& touch "${PYPY_TOOLCACHE_VERSION_ARCH_DIR}.complete" \
&& rm "${PYPY_TMP_ARCHIVE}"; done \
&& rm "${PYPY_VERSIONS_JSON}"

FROM base as terraform
ARG TARGETARCH
ARG PATH_LOCAL_BINS
Expand Down Expand Up @@ -436,6 +465,9 @@ COPY --link --from=k8s-tools \
"${PATH_LOCAL_BINS}/minikube" \
"${PATH_LOCAL_BINS}"/

# add PyPy
COPY --link --from=pypy "${AGENT_TOOLSDIRECTORY}/PyPy" "${AGENT_TOOLSDIRECTORY}/PyPy"

# add terraform
COPY --link --from=terraform "${PATH_LOCAL_BINS}/terraform" "${PATH_LOCAL_BINS}/terraform"

Expand Down