From f50d4a9dc83af386b86f2f10a28f19e8c44cfdfe Mon Sep 17 00:00:00 2001 From: Tobias Eichert Date: Mon, 10 Mar 2025 16:56:39 +0100 Subject: [PATCH] Add Docker support --- .env | 1 + Dockerfile | 25 +++++++++++++++++++++++++ README.md | 14 ++++++++++++++ config/development.sample.json | 10 +++++++++- config/production.sample.json | 10 +++++++++- docker-compose.yml | 29 +++++++++++++++++++++++++++++ 6 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 .env create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.env b/.env new file mode 100644 index 00000000..c0d66521 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +NODE_ENV=development diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..bdf26b30 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# Use an official Node.js runtime as a parent image +FROM node:lts-alpine + +ARG NODE_ENV=development +ENV NODE_ENV=${NODE_ENV} + +ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true + +RUN apk update +RUN apk add --no-cache bash chromium + +# Set the working directory in the container +WORKDIR /app + +# Initialise app +COPY . . + +# Install dependencies +RUN npm install + +# Expose the port the app runs on +EXPOSE 4000 + +# Run the application +CMD ["node", "index.js"] diff --git a/README.md b/README.md index 416ca4cc..cbaf6b89 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,19 @@ The boot configurations for Pa11y Dashboard are as follows. Look at the sample J This can either be an object containing [Pa11y Webservice configurations][pa11y-webservice-config], or a string which is the base URL of a Pa11y Webservice instance you are running separately. If using environment variables, prefix the webservice vars with `WEBSERVICE_`. +## Docker +You can also run Pa11y Dashboard using [Docker][docker]. In this case, you need to define your environment name, set up the appropriate config file for your environment and build the Docker image before starting the service. +```sh +# Define the environment name in .env, e.g. "development" +NODE_ENV=development +# Set up and modify the config file according to your environment +cp config/development.sample.json config/development.json +# Start the service +docker compose up --build -d +# Optionally, you can also build the image without starting the service +docker build --build-arg ENV=development -t pa11y-dashboard:development . +``` + ## Contributing There are many ways to contribute to Pa11y Dashboard, we cover these in the [contributing guide](CONTRIBUTING.md) for this repo. @@ -200,6 +213,7 @@ The following table lists the major versions available and, for each previous ma Pa11y Dashboard is licensed under the [GNU General Public License 3.0][info-license]. Copyright © 2023, Team Pa11y and contributors +[docker]: https://www.docker.com/ [homebrew]: https://brew.sh/ [issues]: https://github.com/pa11y/pa11y-dashboard/issues?utf8=%E2%9C%93&q=is%3Aissue [issues-create]: https://github.com/pa11y/pa11y-dashboard/issues/new diff --git a/config/development.sample.json b/config/development.sample.json index df66d780..95f45ad4 100644 --- a/config/development.sample.json +++ b/config/development.sample.json @@ -6,6 +6,14 @@ "database": "mongodb://localhost/pa11y-webservice-dev", "host": "0.0.0.0", "port": 3000, - "cron": "0 30 0 * * *" + "cron": "0 30 0 * * *", + "chromeLaunchConfig": { + "args": [ + "--no-sandbox", + "--disable-setuid-sandbox", + "--disable-gpu", + "--ignore-certificate-errors" + ] + } } } diff --git a/config/production.sample.json b/config/production.sample.json index caeef6f7..10af47f7 100644 --- a/config/production.sample.json +++ b/config/production.sample.json @@ -6,6 +6,14 @@ "database": "mongodb://localhost/pa11y-webservice", "host": "0.0.0.0", "port": 3000, - "cron": "0 30 0 * * *" + "cron": "0 30 0 * * *", + "chromeLaunchConfig": { + "args": [ + "--no-sandbox", + "--disable-setuid-sandbox", + "--disable-gpu", + "--ignore-certificate-errors" + ] + } } } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..7c975961 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,29 @@ +services: + pa11y_mongodb: + image: mongodb/mongodb-community-server:latest + container_name: pa11y_mongodb_1 + restart: always + ports: + - "27017:27017" # Expose if needed for external access + volumes: + - mongodb_data:/data/db + + pa11y_dashboard: + build: + context: . + dockerfile: Dockerfile + args: + NODE_ENV: ${NODE_ENV:-development} + image: pa11y-dashboard:${NODE_ENV:-development} + container_name: pa11y_dashboard_1 + restart: always + ports: + - "4000:4000" + environment: + NODE_ENV: ${NODE_ENV:-development} + PORT: 4000 + depends_on: + - pa11y_mongodb + +volumes: + mongodb_data: