Skip to content
Draft
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
14 changes: 14 additions & 0 deletions Dockerfile.server
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:22 AS builder
WORKDIR /app
COPY package*.json ./
RUN npm cache clean --force
RUN npm install
COPY . .
RUN npm run build

FROM node:22-slim
WORKDIR /app
RUN npm install -g serve
COPY --from=builder /app/dist ./dist
EXPOSE 4321
CMD ["serve", "dist", "-l", "4321"]
12 changes: 12 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:22
WORKDIR /app
RUN apt-get update && apt-get install -y \
libgtk2.0-0 libgtk-3-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 \
libdrm2 libgbm1 libxkbcommon0 libxcb-randr0 \
xvfb \
build-essential git curl ca-certificates --no-install-recommends && \
rm -rf /var/lib/apt/lists/*
COPY package*.json ./
RUN npm install
COPY . .
CMD ["sh", "-c", "npm run test:server"]
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ npm run preview
npm run test
```

#### Running Tests and Linting with Docker

From the project directory, run this command:

```console
docker-compose up --build --abort-on-container-exit

```

This will:

- Build the necessary Docker images if they aren't already there.
- Start up the server container to serve the site.
- Launch the tester container, which waits for the server to be ready and then runs all of our tests and linters.
- Automatically shut down both containers once the tests are finished.

### Scripts

The following scripts are made available via [package.json](./package.json):
Expand Down
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
server:
build:
context: .
dockerfile: Dockerfile.server
ports:
- '4321:4321'
restart: 'on-failure'

tester:
build:
context: .
dockerfile: Dockerfile.test
depends_on:
- server
command: sh -c "npm run test && npm run prettier:check && npm run stylelint:check"
environment:
- CYPRESS_BASE_URL=http://server:4321
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"devDependencies": {
"cypress": "14.3.2",
"postcss-html": "^1.8.0",
"prettier": "3.5.3",
"prettier": "^3.5.3",
"prettier-plugin-astro": "^0.14.1",
"stylelint": "^16.19.1",
"stylelint-config-html": "^1.1.0",
Expand Down