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

test: [M3-8769] - Add Docker Compose service to reverse proxy Cloud in CI #11177

Merged
42 changes: 39 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
45 changes: 31 additions & 14 deletions packages/manager/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,49 +1,66 @@
# 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
bnussman-akamai marked this conversation as resolved.
Show resolved Hide resolved

# `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
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