Skip to content

Commit 2bcc664

Browse files
author
Greg Trihus
committed
run cypress tests with docker
- launchs a custom version of the dev server with the latest packages for vite testing - sets the vite optimize deps so it is not run during tests - tests are run in a docker instance - user needs to be added to a docker group so sudo is note required - write was added to packages.json to support running stamp - npm run cy:docker:build - sets up containers ... reloads dependencies - npm run cy:docker - runs tests each time - npm run cy:docker:down - removes containers and network add docker cypress tests to github actions add docker-compose add docker clean up aggressive agent clean up for docker add copilot suggestions change group and user name change group and user id remove user change separate cypress tests into their own job docker w/o root deps
1 parent 8f6bab3 commit 2bcc664

File tree

9 files changed

+376
-2
lines changed

9 files changed

+376
-2
lines changed

.dockerignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Dependencies
2+
node_modules
3+
**/node_modules
4+
5+
# Build outputs
6+
dist
7+
build
8+
*.log
9+
10+
# Git
11+
.git
12+
.gitignore
13+
14+
# IDE
15+
.vscode
16+
.idea
17+
*.swp
18+
*.swo
19+
20+
# OS
21+
.DS_Store
22+
Thumbs.db
23+
24+
# Test coverage
25+
coverage
26+
.nyc_output
27+
28+
# Cypress
29+
cypress/videos
30+
cypress/screenshots
31+
32+
# Environment files
33+
.env
34+
.env.local
35+
.env.*.local
36+
37+
# Temporary files
38+
tmp
39+
temp
40+
*.tmp

.github/workflows/dev.yml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,141 @@ jobs:
133133
if: always()
134134
run: |
135135
pkill -f node || true
136+
137+
cypress-tests:
138+
runs-on: ubuntu-latest
139+
needs: build
140+
141+
steps:
142+
- name: Checkout code
143+
uses: actions/checkout@v4
144+
145+
- name: Setup Volta
146+
uses: volta-cli/action@v4
147+
148+
- name: Install Node.js 22
149+
run: |
150+
volta install node@22
151+
node --version
152+
153+
- name: Clean up memory (kill any existing node processes)
154+
run: |
155+
pkill -f node || true
156+
157+
# - name: Install root dependencies
158+
# run: npm ci
159+
160+
- name: Install renderer dependencies
161+
working-directory: src/renderer
162+
run: npm ci
163+
164+
- name: Make Environment (.env.local)
165+
working-directory: src/renderer
166+
run: |
167+
echo "VITE_DOMAIN=${{ env.DOMAIN }}" > .env.local
168+
echo "VITE_CLIENTID=${{ env.CLIENT_ID }}" >> .env.local
169+
echo "VITE_ENDPOINT=${{ env.APP }}" >> .env.local
170+
echo "VITE_CALLBACK=${{ env.CALLBACK }}" >> .env.local
171+
echo "VITE_HOST=${{ env.HOST }}" >> .env.local
172+
echo "VITE_HELP=${{ env.HELP }}" >> .env.local
173+
echo "VITE_COMMUNITY=${{ env.COMMUNITY }}" >> .env.local
174+
echo "VITE_OPENNOTES=${{ env.OPEN_NOTES }}" >> .env.local
175+
echo "VITE_RESOURCES=${{ env.RESOURCES }}" >> .env.local
176+
echo "VITE_OPENCONTENT=${{ env.OPEN_CONTENT }}" >> .env.local
177+
echo "VITE_COURSE=${{ env.COURSE }}" >> .env.local
178+
echo "VITE_VIDEO_TRAINING=${{ env.VIDEOS }}" >> .env.local
179+
echo "VITE_WALK_THRU=${{ env.WALK_THRU }}" >> .env.local
180+
echo "VITE_AKUO=${{ env.AKUO }}" >> .env.local
181+
echo "VITE_FLAT=${{ env.FLAT }}" >> .env.local
182+
echo "VITE_HIERARCHICAL=${{ env.HIERARCHICAL }}" >> .env.local
183+
echo "VITE_GEN_FLAT=${{ env.GEN_FLAT }}" >> .env.local
184+
echo "VITE_GEN_HIERARCHICAL=${{ env.GEN_HIERARCHICAL }}" >> .env.local
185+
echo "VITE_GOOGLE_SAMPLES=${{ env.GOOGLE_SAMPLES }}" >> .env.local
186+
echo "VITE_SNAGID=${{ env.SNAG_ID }}" >> .env.local
187+
echo "VITE_SIZELIMIT=${{ env.SIZELIMIT }}" >> .env.local
188+
echo "VITE_SITE_TITLE=${{ env.NAME }}" >> .env.local
189+
190+
- name: Create auth0-variables.json
191+
working-directory: src/renderer
192+
run: |
193+
echo '{"apiIdentifier":"${{ env.API_ID }}","auth0Domain":"${{ env.DOMAIN }}","webClientId":"${{ env.CLIENT_ID }}"}' > src/auth/auth0-variables.json
194+
195+
- name: Set up Docker Buildx
196+
uses: docker/setup-buildx-action@v3
197+
198+
- name: Install docker-compose
199+
run: |
200+
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
201+
sudo chmod +x /usr/local/bin/docker-compose
202+
docker-compose --version
203+
204+
- name: Clean up disk space before tests
205+
run: |
206+
# Clean up system packages
207+
sudo apt-get clean || true
208+
sudo rm -rf /var/lib/apt/lists/* || true
209+
210+
# Clean up Docker aggressively
211+
docker system prune -af --volumes || true
212+
docker builder prune -af || true
213+
214+
# Remove cache directories to free up space
215+
rm -rf node_modules/.cache || true
216+
rm -rf src/renderer/node_modules/.cache || true
217+
218+
- name: Check disk space
219+
run: |
220+
df -h
221+
docker system df
222+
223+
- name: Build and run Cypress tests in Docker
224+
working-directory: src/renderer
225+
env:
226+
DOCKER_BUILDKIT: 1
227+
COMPOSE_DOCKER_CLI_BUILD: 1
228+
run: npm run cy:docker:build
229+
230+
- name: Clean up Docker containers
231+
if: always()
232+
working-directory: src/renderer
233+
run: npm run cy:docker:down
234+
235+
- name: Clean up Docker system after tests
236+
if: always()
237+
run: |
238+
docker system prune -af --volumes || true
239+
docker builder prune -af || true
240+
241+
- name: Upload Cypress screenshots on failure
242+
if: failure()
243+
uses: actions/upload-artifact@v4
244+
with:
245+
name: cypress-screenshots-${{ github.run_number }}
246+
path: src/renderer/cypress/screenshots
247+
retention-days: 7
248+
if-no-files-found: ignore
249+
250+
- name: Upload Cypress videos on failure
251+
if: failure()
252+
uses: actions/upload-artifact@v4
253+
with:
254+
name: cypress-videos-${{ github.run_number }}
255+
path: src/renderer/cypress/videos
256+
retention-days: 7
257+
if-no-files-found: ignore
258+
259+
- name: Upload Cypress test results
260+
if: always()
261+
uses: actions/upload-artifact@v4
262+
with:
263+
name: cypress-results-${{ github.run_number }}
264+
path: |
265+
src/renderer/cypress/reports
266+
src/renderer/cypress/results
267+
retention-days: 30
268+
if-no-files-found: ignore
269+
270+
- name: Clean up processes
271+
if: always()
272+
run: |
273+
pkill -f node || true

src/renderer/.dockerignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Dependencies
2+
node_modules
3+
**/node_modules
4+
5+
# Build outputs
6+
dist
7+
build
8+
*.log
9+
10+
# Git
11+
.git
12+
.gitignore
13+
14+
# IDE
15+
.vscode
16+
.idea
17+
*.swp
18+
*.swo
19+
20+
# OS
21+
.DS_Store
22+
Thumbs.db
23+
24+
# Test coverage
25+
coverage
26+
.nyc_output
27+
28+
# Cypress
29+
cypress/videos
30+
cypress/screenshots
31+
32+
# Environment files
33+
.env
34+
.env.local
35+
.env.*.local
36+
37+
# Temporary files
38+
tmp
39+
temp
40+
*.tmp

src/renderer/Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM node:22.19.0
2+
3+
# Install wget for healthcheck
4+
RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/*
5+
6+
WORKDIR /app
7+
8+
# Copy root package files first
9+
COPY package*.json ./
10+
11+
# Install root dependencies (use ci for clean install, ignore cache)
12+
RUN npm ci
13+
14+
# These lines appear to cause the container build to hang
15+
# # Create a non-root user for running the application
16+
# RUN groupadd --gid 1010 apm \
17+
# && useradd --uid 1010 --gid apm --shell /bin/bash --create-home apm
18+
# # Change ownership of the app directory to the apm user
19+
# RUN chown -R apm:apm /app
20+
# # Switch to the non-root user
21+
# USER apm
22+
23+
# Copy renderer package files
24+
COPY src/renderer/package*.json ./src/renderer/
25+
26+
# Install renderer dependencies (use ci for clean install, ignore cache)
27+
RUN cd src/renderer && npm ci
28+
29+
# Copy necessary config files
30+
COPY env-config ./env-config
31+
COPY tsconfig*.json ./
32+
COPY electron.vite.config.ts ./
33+
COPY src/renderer ./src/renderer
34+
35+
# Expose Vite dev server port
36+
EXPOSE 3000
37+
38+
# The command will be overridden by docker-compose
39+
CMD ["npm", "start"]

src/renderer/Dockerfile.cypress

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM cypress/included:15.7.1
2+
3+
# Install curl for warming up Vite
4+
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
5+
6+
WORKDIR /e2e
7+
8+
# Copy package files
9+
COPY package*.json ./
10+
11+
# Install project dependencies (including vite-dev-server, etc.)
12+
RUN npm ci
13+
14+
# The rest will be mounted via volumes

src/renderer/docker-compose.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
version: '3.8'
2+
3+
services:
4+
# Vite development server
5+
app:
6+
build:
7+
context: ../..
8+
dockerfile: src/renderer/Dockerfile
9+
ports:
10+
- '3000:3000'
11+
volumes:
12+
- ../..:/app
13+
- /app/node_modules
14+
- /app/src/renderer/node_modules
15+
environment:
16+
- NODE_ENV=development
17+
command: sh -c "set -e; cd /app && npm run stamp && npm run devs && cd /app/src/renderer && npm start"
18+
healthcheck:
19+
test:
20+
[
21+
'CMD',
22+
'wget',
23+
'--no-verbose',
24+
'--tries=1',
25+
'--spider',
26+
'http://localhost:3000',
27+
]
28+
interval: 3s
29+
timeout: 5s
30+
retries: 20
31+
start_period: 40s
32+
networks:
33+
- cypress-net
34+
35+
# Cypress tests
36+
cypress:
37+
build:
38+
context: .
39+
dockerfile: Dockerfile.cypress
40+
depends_on:
41+
app:
42+
condition: service_healthy
43+
environment:
44+
- CYPRESS_baseUrl=http://app:3000
45+
working_dir: /e2e
46+
volumes:
47+
- .:/e2e
48+
- /e2e/node_modules
49+
command: >
50+
docker run
51+
--component
52+
--config-file cypress/config/local.config.ts
53+
networks:
54+
- cypress-net
55+
56+
networks:
57+
cypress-net:
58+
driver: bridge

0 commit comments

Comments
 (0)