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

Update nodejs installation script in kitchen sink #247

Merged
merged 2 commits into from
Aug 9, 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
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

- Ensure corepack is installed in the `pulumi/pulumi` image
([#247](https://github.com/pulumi/pulumi-docker-containers/pull/247))

- Add Poetry to Python images ([#240](https://github.com/pulumi/pulumi-docker-containers/pull/240))

- Update to debian 12 (bookworm) slim as base image
Expand Down
49 changes: 29 additions & 20 deletions docker/pulumi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ LABEL org.opencontainers.image.description="The Pulumi CLI, in a Docker containe
ENV GOLANG_VERSION 1.21.1
ENV GOLANG_SHA256 b3075ae1ce5dab85f89bc7905d1632de23ca196bd8336afd93fa97434cfa55ae

# Install deps all in one step
# Install base dependencies
RUN apt-get update -y && \
apt-get install -y \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
apt-transport-https \
build-essential \
ca-certificates \
Expand All @@ -20,12 +20,10 @@ RUN apt-get update -y && \
software-properties-common \
wget \
unzip && \
# Get all of the signatures we need all at once.
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && \
curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - && \
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
rm -rf /var/lib/apt/lists/*

# Install cloud tools
RUN \
# IAM Authenticator for EKS
curl -fsSLo /usr/bin/aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.28.2/2023-10-17/bin/linux/amd64/aws-iam-authenticator && \
chmod +x /usr/bin/aws-iam-authenticator && \
Expand All @@ -35,28 +33,38 @@ RUN apt-get update -y && \
./aws/install && \
rm -rf aws && \
rm awscliv2.zip && \
# Add additional apt repos all at once
echo "deb https://deb.nodesource.com/node_18.x $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/node.list && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list && \
# Add additional apt repos
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - && \
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list && \
echo "deb http://packages.cloud.google.com/apt cloud-sdk-$(lsb_release -cs) main" | tee /etc/apt/sources.list.d/google-cloud-sdk.list && \
KUBE_LATEST=$(curl -L -s https://dl.k8s.io/release/stable.txt | awk 'BEGIN { FS="." } { printf "%s.%s", $1, $2 }') && \
mkdir -p /etc/apt/keyrings && \
curl -fsSL https://pkgs.k8s.io/core:/stable:/${KUBE_LATEST}/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/${KUBE_LATEST}/deb/ /" | tee /etc/apt/sources.list.d/kubernetes.list && \
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/azure.list && \
# Install second wave of dependencies
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/azure.list && \
# Install azure-cli, docker, gcloud, kubectl
apt-get update -y && \
apt-get install -y \
azure-cli \
docker-ce \
google-cloud-sdk \
google-cloud-sdk-gke-gcloud-auth-plugin \
kubectl \
kubectl && \
rm -rf /var/lib/apt/lists/*

# Install nodejs and associated tools
RUN \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit is new. I split the above RUN step into multiple steps to keep the steps for various tools grouped together, instead of bundled too much in a single step.

# Add yarn repo
curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
# Add nodejs repo
curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this vs. https://deb.nodesource.com/node_18.x has changed, and I guess this bundles everything when installing nodejs? That answers my other question about npm as well I guess?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct!

# Install packages
apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
nodejs \
npm \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is npm now installed as part of nodejs?

yarn && \
# Clean up the lists work
rm -rf /var/lib/apt/lists/*

# Install Go
Expand All @@ -71,9 +79,10 @@ ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

# Install Java
RUN apt-get update -y && \
apt-get install -y \
gradle \
maven
DEBIAN_FRONTEND=noninteractive apt-get install -y \
gradle \
maven && \
rm -rf /var/lib/apt/lists/*

# Install dotnet 6.0 using instructions from:
# https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script
Expand Down
59 changes: 50 additions & 9 deletions tests/containers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,57 @@ func TestEnvironment(t *testing.T) {
if !hasNodejs(t) {
t.Skip("Skipping test for images without nodejs")
}
expected := "/usr/local/bin/node"
if isUBI(t) || isKitchenSink(t) {
expected = "/usr/bin/node"
}
t.Parallel()
p, err := exec.LookPath("node")
require.NoError(t, err)
require.Equal(t, expected, p)
// Use bash `command` builtin to lookup the path to node
requireOutputWithBash(t, expected, "command", "-v", "node")

for _, testCase := range []struct {
name string
expectedDebian string
expectedUbi string
expectedKitchen string
}{
{
name: "node",
expectedDebian: "/usr/local/bin/node",
expectedUbi: "/usr/bin/node",
expectedKitchen: "/usr/bin/node",
},
{
name: "npm",
expectedDebian: "/usr/local/bin/npm",
expectedUbi: "/usr/local/bin/npm",
expectedKitchen: "/usr/bin/npm",
},

{
name: "yarn",
expectedDebian: "/usr/local/bin/yarn",
expectedUbi: "/usr/local/bin/yarn",
expectedKitchen: "/usr/bin/yarn",
},
{
name: "corepack",
expectedDebian: "/usr/local/bin/corepack",
expectedUbi: "/usr/bin/corepack",
expectedKitchen: "/usr/bin/corepack",
},
} {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
expected := testCase.expectedDebian
if isUBI(t) {
expected = testCase.expectedUbi
}
if isKitchenSink(t) {
expected = testCase.expectedKitchen
}
p, err := exec.LookPath(testCase.name)
require.NoError(t, err)
require.Equal(t, expected, p)
// Use bash `command` builtin to lookup the path when running in bash
requireOutputWithBash(t, expected, "command", "-v", testCase.name)
})
}
})

t.Run(imageVariant, func(t *testing.T) {
Expand Down