diff --git a/Dockerfile.server b/Dockerfile.server new file mode 100644 index 0000000..a30eac1 --- /dev/null +++ b/Dockerfile.server @@ -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"] \ No newline at end of file diff --git a/Dockerfile.test b/Dockerfile.test new file mode 100644 index 0000000..4dca55d --- /dev/null +++ b/Dockerfile.test @@ -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"] \ No newline at end of file diff --git a/README.md b/README.md index 54bb312..2938325 100644 --- a/README.md +++ b/README.md @@ -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): diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8ce850d --- /dev/null +++ b/docker-compose.yml @@ -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 diff --git a/package-lock.json b/package-lock.json index 454d0f5..d8f164f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,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", @@ -7789,7 +7789,6 @@ "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.3.tgz", "integrity": "sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==", "dev": true, - "license": "MIT", "bin": { "prettier": "bin/prettier.cjs" }, diff --git a/package.json b/package.json index a8fdae9..930b390 100644 --- a/package.json +++ b/package.json @@ -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",