From 1769bfc0c17b4566654f5928787738b6089131e8 Mon Sep 17 00:00:00 2001 From: Joe D'Amore Date: Mon, 28 Oct 2024 15:26:22 -0400 Subject: [PATCH 1/6] Expose Cloud Manager-specific Node.js Image --- packages/manager/Dockerfile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/manager/Dockerfile b/packages/manager/Dockerfile index 466edaf64ea..fc5d882f51c 100644 --- a/packages/manager/Dockerfile +++ b/packages/manager/Dockerfile @@ -1,7 +1,16 @@ +# Node.js base image for Cloud Manager CI tasks. +# +# Extends from the Node.js base image that corresponds with our latest supported +# version of Node, and includes other tools that we rely on like pnpm and bun. +FROM node:20.17-bullseye-slim as nodejs-cloud-manager +RUN npm install -g pnpm bun + # `manager` # # Serves Cloud Manager. -FROM node:20.17-bullseye-slim as manager +# Assumes Cloud Manager dependencies are installed at `/home/node/app/node_modules`, +# and Cloud Manager is built. +FROM nodejs-cloud-manager as manager ENV NODE_ENV=development WORKDIR /home/node/app VOLUME /home/node/app From 67080ce9d84771e1665ce3bf3157be6219c2eea4 Mon Sep 17 00:00:00 2001 From: Joe D'Amore Date: Mon, 28 Oct 2024 15:29:35 -0400 Subject: [PATCH 2/6] Remove `expect` and `openssh-client` installation step, consolidate `e2e-install` and `e2e-build` stages --- packages/manager/Dockerfile | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/packages/manager/Dockerfile b/packages/manager/Dockerfile index fc5d882f51c..b776e7b7192 100644 --- a/packages/manager/Dockerfile +++ b/packages/manager/Dockerfile @@ -29,16 +29,6 @@ CMD yarn start:manager:ci # Builds an image containing Cypress and miscellaneous system utilities required # by the tests. FROM cypress/included:13.11.0 as e2e-build -RUN apt-get update \ - && apt-get install -y expect openssh-client \ - && rm -rf /var/cache/apt/* \ - && rm -rf /var/lib/apt/lists/* \ - && apt-get clean - -# e2e-install -# -# Installs Cypress and sets up cache directories. -FROM e2e-build as e2e-install USER node WORKDIR /home/node/app VOLUME /home/node/app @@ -48,7 +38,7 @@ RUN mkdir -p /home/node/.cache/Cypress && cypress install # `e2e` # # Runs Cloud Manager Cypress tests. -FROM e2e-install as e2e +FROM e2e-build as e2e WORKDIR /home/node/app VOLUME /home/node/app USER node From 86b45a750055605cb3fea94dd33b6859cd291fa5 Mon Sep 17 00:00:00 2001 From: Joe D'Amore Date: Mon, 28 Oct 2024 15:31:16 -0400 Subject: [PATCH 3/6] Add `e2e-reverse-proxy` image which includes caddy --- packages/manager/Dockerfile | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/manager/Dockerfile b/packages/manager/Dockerfile index b776e7b7192..4105c942ad6 100644 --- a/packages/manager/Dockerfile +++ b/packages/manager/Dockerfile @@ -15,13 +15,13 @@ ENV NODE_ENV=development WORKDIR /home/node/app VOLUME /home/node/app EXPOSE 3000/tcp + # Curl is needed for health check. RUN apt-get update \ && apt-get install -y curl \ && rm -rf /var/cache/apt/* \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean - CMD yarn start:manager:ci # e2e-build @@ -35,7 +35,7 @@ VOLUME /home/node/app ENV CYPRESS_CACHE_FOLDER=/home/node/.cache/Cypress RUN mkdir -p /home/node/.cache/Cypress && cypress install -# `e2e` +# e2e # # Runs Cloud Manager Cypress tests. FROM e2e-build as e2e @@ -46,3 +46,21 @@ ENV CI=1 ENV NO_COLOR=1 ENV HOME=/home/node/ ENV CYPRESS_CACHE_FOLDER=/home/node/.cache/Cypress + +# e2e-reverse-proxy +# +# Runs Cloud Manager Cypress tests, with Caddy installed. +# Extends from `e2e`, and includes Caddy to support reverse proxying Cloud Manager. +FROM e2e as e2e-reverse-proxy +USER root +# Install Caddy. +# Instructions adapted from Caddy documentation at caddyserver.com: +# https://caddyserver.com/docs/install#debian-ubuntu-raspbian +RUN apt-get update \ + && apt-get install -y debian-keyring debian-archive-keyring apt-transport-https curl \ + && curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg \ + && curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list \ + && apt-get update \ + && apt-get install caddy +VOLUME /home/node/app +USER node From d5e8acfce0d8398dcedb6ca099674f94113ced71 Mon Sep 17 00:00:00 2001 From: Joe D'Amore Date: Mon, 28 Oct 2024 15:32:59 -0400 Subject: [PATCH 4/6] Add `cypress_containerized` Docker Compose service, improve docs --- docker-compose.yml | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 36bbe54ef43..ced361320f6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -117,10 +117,14 @@ services: <<: *default-env MANAGER_OAUTH: ${MANAGER_OAUTH} - # Cypress test runner service to run tests against a locally-served Cloud instance. + # Cypress test runner service to run tests against a local Cloud instance. # - # This is useful when testing against a customized or in-development build of - # Cloud Manager. + # This is useful when testing against a Cloud Manager instance served locally at + # `localhost:3000`, e.g. during development. + # + # If the local Cloud Manager instance is not served at `localhost:3000` (when + # served from a container, for example), prefer the `cypress_containerized` + # service instead. cypress_local: <<: *default-runner environment: @@ -130,6 +134,38 @@ services: web: condition: service_healthy + # Cypress test runner service to run tests against a containerized Cloud instance. + # + # This service reverse proxies the given $CYPRESS_BASE_URL to `localhost:3000`. + # This is necessary for certain tests which require a secure context, which + # can typically only be achieved when Cloud is served at `localhost` or + # remotely behind SSL. + # + # For more information, refer to: + # https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts + # + # If the local Cloud Manager instance is served at `localhost:3000` (when + # running Cloud Manager locally during development, for example), prefer the + # `cypress_local` service instead. + cypress_containerized: + <<: *default-runner + build: + context: . + dockerfile: ./packages/manager/Dockerfile + target: e2e-reverse-proxy + environment: + <<: *default-env + MANAGER_OAUTH: ${MANAGER_OAUTH} + CYPRESS_BASE_URL: "http://localhost:3000" + REVERSE_PROXY_URL: ${CYPRESS_BASE_URL} + depends_on: + web: + condition: service_healthy + entrypoint: + - "/bin/sh" + - "-c" + - "caddy reverse-proxy --from $${CYPRESS_BASE_URL} --to $${REVERSE_PROXY_URL} & yarn $0 $@" + # Cypress component test runner service. # # Unlike other Cloud Manager Cypress tests, these tests can be run without From 9890ec6ef16c5f35b92fbe1db480d4f53bf07f4b Mon Sep 17 00:00:00 2001 From: Joe D'Amore Date: Tue, 29 Oct 2024 11:13:31 -0400 Subject: [PATCH 5/6] Add changesets --- .../.changeset/pr-11177-tech-stories-1730214757061.md | 5 +++++ .../.changeset/pr-11177-tech-stories-1730214793474.md | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 packages/manager/.changeset/pr-11177-tech-stories-1730214757061.md create mode 100644 packages/manager/.changeset/pr-11177-tech-stories-1730214793474.md diff --git a/packages/manager/.changeset/pr-11177-tech-stories-1730214757061.md b/packages/manager/.changeset/pr-11177-tech-stories-1730214757061.md new file mode 100644 index 00000000000..1987e5ba9b7 --- /dev/null +++ b/packages/manager/.changeset/pr-11177-tech-stories-1730214757061.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Tech Stories +--- + +Add `cypress_containerized` Docker Compose service ([#11177](https://github.com/linode/manager/pull/11177)) diff --git a/packages/manager/.changeset/pr-11177-tech-stories-1730214793474.md b/packages/manager/.changeset/pr-11177-tech-stories-1730214793474.md new file mode 100644 index 00000000000..0c79ba70e01 --- /dev/null +++ b/packages/manager/.changeset/pr-11177-tech-stories-1730214793474.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Tech Stories +--- + +Add `nodejs-cloud-manager` Dockerfile target ([#11177](https://github.com/linode/manager/pull/11177)) From f3062a5d220d1cf8b4ad1daa97b6719927c2c1f7 Mon Sep 17 00:00:00 2001 From: Joe D'Amore Date: Thu, 31 Oct 2024 10:09:31 -0400 Subject: [PATCH 6/6] Make pnpm and bun available in Cypress containers --- packages/manager/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/manager/Dockerfile b/packages/manager/Dockerfile index 4105c942ad6..37e1785a48a 100644 --- a/packages/manager/Dockerfile +++ b/packages/manager/Dockerfile @@ -29,6 +29,7 @@ CMD yarn start:manager:ci # Builds an image containing Cypress and miscellaneous system utilities required # by the tests. FROM cypress/included:13.11.0 as e2e-build +RUN npm install -g pnpm bun USER node WORKDIR /home/node/app VOLUME /home/node/app