Skip to content

Commit

Permalink
Install Python and Node.js in the UBI containers using pyenv and fnm (#…
Browse files Browse the repository at this point in the history
…326)

We don't have the full matrix of versions available for the UBI
containers because we are installing from the UBI software catalog. This
is problematic now that we want the default to be Nodejs 22 and Python
3.13, neither of which is available.

Instead of installing from pre-built packages, use fnm and pyenv to
install the versions, similar to what we do for the kitchen-sink image.

Fixes #327
  • Loading branch information
julienp authored Nov 18, 2024
1 parent 1a32ea9 commit 133dfdd
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 71 deletions.
14 changes: 1 addition & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -434,20 +434,8 @@ jobs:
- uses: actions/checkout@master
- name: Define Matrix for UBI SDK Manifests
id: define-matrix-sdk-manifests
# Filter out the nodejs 22 and 23 versions from the matrix, as they are not supported on UBI.
# https://access.redhat.com/articles/3376841
# Filter out the python 3.10 and 3.13 versions from the matrix, as they are supported on UBI.
# https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/installing_and_using_dynamic_programming_languages/assembly_introduction-to-python_installing-and-using-dynamic-programming-languages#con_python-versions_assembly_introduction-to-python
run: |
echo matrix=$(python ./.github/scripts/matrix/gen-matrix.py --no-arch |
jq '.include |= map(
select(
(.sdk != "nodejs" or .language_version != "22") and
(.sdk != "nodejs" or .language_version != "23") and
(.sdk != "python" or .language_version != "3.10") and
(.sdk != "python" or .language_version != "3.13")
)
)') >> "$GITHUB_OUTPUT"
echo matrix=$(python ./.github/scripts/matrix/gen-matrix.py --no-arch) >> "$GITHUB_OUTPUT"
ubi-sdk:
name: UBI SDK images
Expand Down
14 changes: 1 addition & 13 deletions .github/workflows/sync-ecr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,8 @@ jobs:
- uses: actions/checkout@master
- name: Define Matrix
id: define-matrix
# Filter out the nodejs 22 and 23 versions from the matrix, as they are not supported on UBI.
# https://access.redhat.com/articles/3376841
# Filter out the python 3.10 and 3.13 versions from the matrix, as they are not supported on UBI.
# https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/installing_and_using_dynamic_programming_languages/assembly_introduction-to-python_installing-and-using-dynamic-programming-languages#con_python-versions_assembly_introduction-to-python
run: |
echo matrix=$(python ./.github/scripts/matrix/gen-matrix.py --no-arch |
jq '.include |= map(
select(
(.sdk != "nodejs" or .language_version != "22") and
(.sdk != "nodejs" or .language_version != "23") and
(.sdk != "python" or .language_version != "3.10") and
(.sdk != "python" or .language_version != "3.13")
)
)') >> "$GITHUB_OUTPUT"
echo matrix=$(python ./.github/scripts/matrix/gen-matrix.py --no-arch) >> "$GITHUB_OUTPUT"
# NOTE: If UBI images become multi platform, this job can be replaced by adding a similar step to "-debian" for "-ubi" the previous job.
ubi-images:
Expand Down
14 changes: 1 addition & 13 deletions .github/workflows/sync-ghcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,8 @@ jobs:
- uses: actions/checkout@master
- name: Define Matrix
id: define-matrix
# Filter out the nodejs 22 and 23 versions from the matrix, as they are not supported on UBI.
# https://access.redhat.com/articles/3376841
# Filter out the python 3.10 and 3.13 versions from the matrix, as they are not supported on UBI.
# https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/installing_and_using_dynamic_programming_languages/assembly_introduction-to-python_installing-and-using-dynamic-programming-languages#con_python-versions_assembly_introduction-to-python
run: |
echo matrix=$(python ./.github/scripts/matrix/gen-matrix.py --no-arch |
jq '.include |= map(
select(
(.sdk != "nodejs" or .language_version != "22") and
(.sdk != "nodejs" or .language_version != "23") and
(.sdk != "python" or .language_version != "3.10") and
(.sdk != "python" or .language_version != "3.13")
)
)') >> "$GITHUB_OUTPUT"
echo matrix=$(python ./.github/scripts/matrix/gen-matrix.py --no-arch) >> "$GITHUB_OUTPUT"
# NOTE: If UBI images become multi platform, this job can be replaced by adding a similar step to "-debian" for "-ubi" the previous job.
ubi-images:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- Install Python and Node.js in the UBI containers using pyenv and fnm
([326])https://github.com/pulumi/pulumi-docker-containers/pull/326))

- Update default language versions
([324](https://github.com/pulumi/pulumi-docker-containers/pull/324))

Expand Down
20 changes: 12 additions & 8 deletions docker/nodejs/Dockerfile.ubi
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@ ARG LANGUAGE_VERSION
LABEL org.opencontainers.image.description="Pulumi CLI container for nodejs"
WORKDIR /pulumi/projects

COPY dnf/nodejs.module /etc/dnf/modules.d/nodejs.module
RUN sed -i s"/__LANGUAGE_VERSION_PLACEHOLDER__/${LANGUAGE_VERSION}/g" /etc/dnf/modules.d/nodejs.module
RUN cat /etc/dnf/modules.d/nodejs.module

RUN microdnf install -y \
ca-certificates \
curl \
git \
nodejs \
tar && \
npm install -g [email protected] && \
npm install -g corepack && \
tar \
unzip

# Install nodejs using fnm
RUN curl -fsSL https://fnm.vercel.app/install | bash -s -- --install-dir "/usr/local/share/fnm" --skip-shell && \
ln -s /usr/local/share/fnm/fnm /usr/local/bin/fnm
ENV FNM_COREPACK_ENABLED="true"
ENV FNM_DIR=/usr/local/share/fnm
RUN fnm install ${LANGUAGE_VERSION} && \
fnm alias ${LANGUAGE_VERSION} default
ENV PATH=/usr/local/share/fnm/aliases/default/bin:$PATH
RUN npm install -g corepack && \
corepack install -g yarn@1

# Uses the workdir, copies from pulumi interim container
Expand Down
5 changes: 0 additions & 5 deletions docker/nodejs/dnf/nodejs.module

This file was deleted.

36 changes: 27 additions & 9 deletions docker/python/Dockerfile.ubi
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,36 @@ ARG LANGUAGE_VERSION
LABEL org.opencontainers.image.description="Pulumi CLI container for python"
WORKDIR /pulumi/projects


# Set the shell to bash so we can do the shell substitution below
SHELL ["/bin/bash", "-c"]
# Install needed tools, like git
# Install needed tools, like git, and build dependencies
RUN microdnf install -y \
bzip2 \
bzip2-devel \
ca-certificates \
findutils \
gcc \
gdbm-libs \
git \
# For Python 3.9 we need the package names python39 and python39-pip
python${LANGUAGE_VERSION//3.9/39} \
python${LANGUAGE_VERSION//3.9/39}-pip \
tar && \
pip3 install --user pipenv
libffi-devel \
libnsl2 \
libuuid-devel \
make \
ncurses \
ncurses-devel \
openssl-devel \
patch \
readline \
sqlite \
sqlite-devel \
tar \
xz-devel \
zlib-devel

# Install python using pyenv
RUN git clone --depth=1 https://github.com/pyenv/pyenv.git /usr/local/share/pyenv
ENV PYENV_ROOT=/usr/local/share/pyenv
ENV PATH="${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${PATH}"
RUN pyenv install ${LANGUAGE_VERSION}
RUN pyenv global ${LANGUAGE_VERSION}

# Install poetry
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/usr/local/share/pypoetry python3 -
Expand Down
17 changes: 7 additions & 10 deletions tests/containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,9 @@ func TestEnvironment(t *testing.T) {
}
t.Parallel()
expected := "/usr/local/bin/python"
if isKitchenSink(t) {
if isKitchenSink(t) || isUBI(t) {
expected = "/usr/local/share/pyenv/shims/python"
}
if isUBI(t) {
expected = "/usr/bin/python"
}
p, err := exec.LookPath("python")
require.NoError(t, err)
require.Equal(t, expected, p)
Expand Down Expand Up @@ -327,26 +324,26 @@ func TestEnvironment(t *testing.T) {
{
name: "node",
expectedDebian: "/usr/local/bin/node",
expectedUbi: "/usr/bin/node",
expectedUbi: "/usr/local/share/fnm/aliases/default/bin/node",
expectedKitchen: "/usr/local/share/fnm/aliases/default/bin/node",
},
{
name: "npm",
expectedDebian: "/usr/local/bin/npm",
expectedUbi: "/usr/local/bin/npm",
expectedUbi: "/usr/local/share/fnm/aliases/default/bin/npm",
expectedKitchen: "/usr/local/share/fnm/aliases/default/bin/npm",
},

{
name: "yarn",
expectedDebian: "/usr/local/bin/yarn",
expectedUbi: "/usr/local/bin/yarn",
expectedUbi: "/usr/local/share/fnm/aliases/default/bin/yarn",
expectedKitchen: "/usr/local/share/fnm/aliases/default/bin/yarn",
},
{
name: "corepack",
expectedDebian: "/usr/local/bin/corepack",
expectedUbi: "/usr/local/bin/corepack",
expectedUbi: "/usr/local/share/fnm/aliases/default/bin/corepack",
expectedKitchen: "/usr/local/share/fnm/aliases/default/bin/corepack",
},
} {
Expand Down Expand Up @@ -383,8 +380,8 @@ func TestEnvironment(t *testing.T) {
"pulumi-ubi-dotnet": "/root/.dotnet:/pulumi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"pulumi-ubi-go": "/pulumi/bin:/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"pulumi-ubi-java": "/pulumi/bin:/root/.sdkman/candidates/maven/current/bin:/root/.sdkman/candidates/gradle/current/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"pulumi-ubi-nodejs": "/pulumi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"pulumi-ubi-python": "/pulumi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"pulumi-ubi-nodejs": "/pulumi/bin:/usr/local/share/fnm/aliases/default/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"pulumi-ubi-python": "/pulumi/bin:/usr/local/share/pyenv/shims:/usr/local/share/pyenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
}

t.Run("PATH when running in bash", func(t *testing.T) {
Expand Down

0 comments on commit 133dfdd

Please sign in to comment.