Skip to content

Commit

Permalink
test: [M3-8769] - Add Docker Compose service to reverse proxy Cloud i…
Browse files Browse the repository at this point in the history
…n CI (#11177)

* Expose Cloud Manager-specific Node.js Image

* Remove `expect` and `openssh-client` installation step, consolidate `e2e-install` and `e2e-build` stages

* Add `e2e-reverse-proxy` image which includes caddy

* Add `cypress_containerized` Docker Compose service, improve docs

* Add changesets

* Make pnpm and bun available in Cypress containers
  • Loading branch information
jdamore-linode authored Nov 1, 2024
1 parent 308dc90 commit d871268
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 17 deletions.
42 changes: 39 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tech Stories
---

Add `cypress_containerized` Docker Compose service ([#11177](https://github.com/linode/manager/pull/11177))
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tech Stories
---

Add `nodejs-cloud-manager` Dockerfile target ([#11177](https://github.com/linode/manager/pull/11177))
46 changes: 32 additions & 14 deletions packages/manager/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,49 +1,67 @@
# 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
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
#
# 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
RUN npm install -g pnpm bun
USER node
WORKDIR /home/node/app
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-install as e2e
FROM e2e-build as e2e
WORKDIR /home/node/app
VOLUME /home/node/app
USER node
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

0 comments on commit d871268

Please sign in to comment.