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

Include pyenv and Python 3.9 to 3.12 in the kitchen sink image #232

Merged
merged 10 commits into from
Aug 26, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ jobs:
--volume /tmp:/src \
--entrypoint /src/pulumi-test-containers \
${{ env.DOCKER_ORG }}/pulumi:${{ env.PULUMI_VERSION }} \
-test.parallel=1 -test.timeout=1h -test.v
-test.timeout=1h -test.v

provider-build-environment:
name: Provider Build Environment image
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
--volume /tmp:/src \
--entrypoint /src/pulumi-test-containers \
${{ env.DOCKER_ORG }}/pulumi:${{ env.PULUMI_VERSION }} \
-test.parallel=1 -test.timeout=1h -test.v
-test.timeout=1h -test.v
- name: Push ${{ env.PULUMI_VERSION }}
run: docker push ${{ env.DOCKER_ORG }}/pulumi:${{ env.PULUMI_VERSION }}
- name: Push latest
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# CHANGELOG

## Unreleased
- Include pyenv and Python 3.9 to 3.12 in the kitchen sink image

([#232](https://github.com/pulumi/pulumi-docker-containers/pull/232))

- Add $GOPATH/bin to $PATH for Go containers
([249](https://github.com/pulumi/pulumi-docker-containers/pull/249))
Expand Down
34 changes: 31 additions & 3 deletions docker/pulumi/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.9-slim-bookworm AS base
FROM debian:12 AS base

LABEL "repository"="https://github.com/pulumi/pulumi"
LABEL "homepage"="https://pulumi.com"
Expand All @@ -17,9 +17,20 @@ RUN apt-get update -y && \
curl \
git \
gnupg \
libbz2-dev \
libffi-dev \
liblzma-dev \
libncurses5-dev \
libreadline-dev \
libsqlite3-dev \
libssl-dev \
libxml2-dev \
libxmlsec1-dev \
software-properties-common \
unzip \
wget \
unzip && \
xz-utils \
zlib1g-dev && \
rm -rf /var/lib/apt/lists/*

# Install cloud tools
Expand Down Expand Up @@ -53,7 +64,7 @@ RUN \
google-cloud-sdk-gke-gcloud-auth-plugin \
kubectl && \
rm -rf /var/lib/apt/lists/*

# Install nodejs and associated tools
RUN \
# Add yarn repo
Expand Down Expand Up @@ -103,6 +114,23 @@ RUN curl -L https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-
helm repo add stable https://charts.helm.sh/stable && \
helm repo update

# Python
# Install Pyenv and preinstall supported Python versions
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 3.12
RUN pyenv install 3.11
RUN pyenv install 3.10
RUN pyenv install 3.9
RUN pyenv global 3.9 # Default version
# Poetry
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/usr/local/share/pypoetry python3 -
RUN ln -s /usr/local/share/pypoetry/bin/poetry /usr/local/bin/
# Set poetry to prefer the active python version so it interacts nicely with pyenv, otherwise
# poetry will create virtual environments using the python version used by poetry itself.
RUN poetry config virtualenvs.prefer-active-python true

# Passing --build-arg PULUMI_VERSION=vX.Y.Z will use that version
# of the SDK. Otherwise, we use whatever get.pulumi.com thinks is
# the latest
Expand Down
78 changes: 66 additions & 12 deletions tests/containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,27 @@
package containers

import (
"crypto/rand"
"embed"
"encoding/hex"
"encoding/json"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"

"github.com/pulumi/pulumi/pkg/v3/engine"
"github.com/pulumi/pulumi/pkg/v3/testing/integration"
ptesting "github.com/pulumi/pulumi/sdk/v3/go/common/testing"
"github.com/stretchr/testify/require"
)

//go:embed all:testdata
var testdata embed.FS

type testCase struct {
template string
config map[string]string
Expand Down Expand Up @@ -115,6 +123,33 @@ func TestPulumiTemplateTests(t *testing.T) {
}
}

func TestKitchenSinkPythonVersions(t *testing.T) {
if !isKitchenSink(t) {
t.Skip("Only running python version tests on kitchen sink")
}
t.Parallel()

dirs, err := testdata.ReadDir("testdata")
require.NoError(t, err)
for _, dir := range dirs {
dir := dir
t.Run(dir.Name(), func(t *testing.T) {
p := filepath.Join("testdata", dir.Name())
copyTestData(t, p)
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: p,
Quick: true,
SkipRefresh: true,
PrepareProject: func(info *engine.Projinfo) error {
cmd := exec.Command("pulumi", "install", "--use-language-version-tools")
cmd.Dir = info.Root
return cmd.Run()
},
})
})
}
}

func TestCLIToolTests(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -178,6 +213,9 @@ func TestEnvironment(t *testing.T) {
}
t.Parallel()
expected := "/usr/local/bin/python"
if isKitchenSink(t) {
expected = "/usr/local/share/pyenv/shims/python"
}
if isUBI(t) {
expected = "/usr/bin/python"
}
Expand All @@ -187,17 +225,13 @@ func TestEnvironment(t *testing.T) {
// Use bash `command` builtin to lookup the path to python
requireOutputWithBash(t, expected, "command", "-v", "python")

// TODO: enable test for kitchen sink after https://github.com/pulumi/pulumi-docker-containers/pull/232
// is merged. https://github.com/pulumi/pulumi-docker-containers/issues/239
if !isKitchenSink(t) {
// Poetry should be available
expectedPoetryPath := "/usr/local/bin/poetry"
poetryPath, err := exec.LookPath("poetry")
require.NoError(t, err)
require.Equal(t, expectedPoetryPath, poetryPath)
// Use bash `command` builtin to lookup the path to python
requireOutputWithBash(t, expectedPoetryPath, "command", "-v", "poetry")
}
// Poetry should be available
expectedPoetryPath := "/usr/local/bin/poetry"
poetryPath, err := exec.LookPath("poetry")
require.NoError(t, err)
require.Equal(t, expectedPoetryPath, poetryPath)
// Use bash `command` builtin to lookup the path to python
requireOutputWithBash(t, expectedPoetryPath, "command", "-v", "poetry")
})

t.Run("Node", func(t *testing.T) {
Expand Down Expand Up @@ -261,7 +295,7 @@ func TestEnvironment(t *testing.T) {
// Install scripts for various tools can sometimes modify PATH, usually by adding entries
// to ~/.bashrc. This test ensures that we notice such modifications.
expectedPaths := map[string]string{
"pulumi": "/usr/share/dotnet:/pulumi/bin:/go/bin:/usr/local/go/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"pulumi": "/usr/local/share/pyenv/shims:/usr/local/share/pyenv/bin:/usr/share/dotnet:/pulumi/bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"pulumi-debian-dotnet": "/root/.dotnet:/pulumi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"pulumi-debian-go": "/pulumi/bin:/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"pulumi-debian-java": "/pulumi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
Expand Down Expand Up @@ -378,3 +412,23 @@ func isUBI(t *testing.T) bool {
imageVariant := mustEnv(t, "IMAGE_VARIANT")
return strings.HasPrefix(imageVariant, "pulumi-ubi")
}

func RandomStackName(t *testing.T) string {
t.Helper()
b := make([]byte, 4)
_, err := rand.Read(b)
require.NoError(t, err)
return "test" + hex.EncodeToString(b)
}

func copyTestData(t *testing.T, path string) {
require.NoError(t, os.MkdirAll(path, os.ModePerm))
files, err := testdata.ReadDir(path)
require.NoError(t, err, "readdir")
for _, file := range files {
p := filepath.Join(path, file.Name())
fileContent, err := testdata.ReadFile(p)
require.NoError(t, err, "readfile")
require.NoError(t, os.WriteFile(p, fileContent, os.ModePerm), "writefile")
}
}
Loading