From b810dd4f2558ad0c44773cb13286c7108906ed32 Mon Sep 17 00:00:00 2001 From: ceramicwhite Date: Fri, 12 Apr 2024 03:38:23 -0700 Subject: [PATCH] Add Docker support - Add Dockerfile for prod selfhost - Add dev Dockerfile for use with 'docker compose --profile dev watch' - Include compose.yml - Update readme with selfhost instructions - Added 'npm run start:dev:docker' for running synced watched container --- .dockerignore | 28 ++++++++++++++++++++++++++++ Dockerfile | 41 +++++++++++++++++++++++++++++++++++++++++ Dockerfile.dev | 26 ++++++++++++++++++++++++++ README.md | 7 ++++++- compose.yaml | 39 +++++++++++++++++++++++++++++++++++++++ package.json | 1 + 6 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 Dockerfile.dev create mode 100644 compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..ee24db50f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,28 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.next +**/.cache +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +**/build +**/dist +LICENSE +README.md \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..297dd8e17 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +# syntax=docker/dockerfile:1 + +ARG NODE_VERSION=${NODE_VERSION:-18.3.0} +ARG OS=${OS:-alpine} + +##################################### +FROM node:${NODE_VERSION}-${OS} as build + +ENV VITE_BYPASS_LOGIN=1 \ + VITE_BYPASS_TUTORIAL=0 \ + NEXT_TELEMETRY_DISABLED=1 + +WORKDIR /app + +RUN --mount=type=bind,source=package.json,target=package.json \ + --mount=type=bind,source=package-lock.json,target=package-lock.json \ + --mount=type=cache,target=/root/.npm \ + npm ci + +COPY . . + +RUN npm run build + +###################################### +FROM node:${NODE_VERSION}-${OS} as app + + ENV NODE_ENV=production \ + PORT=${PORT:-8000} + +RUN npm install --location=global vite + +USER node + +WORKDIR /app + +COPY --from=build /app/dist/ . +COPY --from=build /app/package.json ./package.json + +EXPOSE $PORT + +CMD npm run start -- --host --port $PORT \ No newline at end of file diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 000000000..6a707528e --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,26 @@ +# syntax=docker/dockerfile:1 + +ARG NODE_VERSION=${NODE_VERSION:-18.3.0} +ARG OS=${OS:-alpine} + +###################################### +FROM node:${NODE_VERSION}-${OS} as dev + +ENV VITE_BYPASS_LOGIN=1 \ + VITE_BYPASS_TUTORIAL=0 \ + NODE_ENV=development + +USER node + +WORKDIR /app + +RUN --mount=type=bind,source=package.json,target=package.json \ + --mount=type=bind,source=package-lock.json,target=package-lock.json \ + --mount=type=cache,target=/root/.npm \ + npm ci + +COPY --chown=node:node . . + +EXPOSE 8000 + +CMD npm run start:dev -- --host --port 8000 \ No newline at end of file diff --git a/README.md b/README.md index 513bee8c0..b7cb1d871 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,12 @@ node: 18.3.0 1. Clone the repo and in the root directory run `npm install` - *if you run into any errors, reach out in the **#dev-corner** channel in discord* -2. Run `npm run start:dev` to locally run the project in `localhost:8000` +2. Run `npm run start:dev` to locally run the project in `localhost:8000` or `npm run start:dev:docker` to run in a docker container + +### 🐳 Docker Selfhost + +1. Clone the repo and in the root directory run `docker compose up -d` +2. The project will be running on `localhost:8000` ### ❔ FAQ diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 000000000..258ef023b --- /dev/null +++ b/compose.yaml @@ -0,0 +1,39 @@ +services: + web: + build: + context: . + image: pagefaultgames/pokerogue + container_name: pokerogue + init: true + environment: + PORT: 8000 + ports: + - 8000:8000 + profiles: [""] + + dev: + build: + context: . + dockerfile: ./Dockerfile.dev + environment: + NODE_ENV: development + command: npm run start:dev -- --host --port 8000 + develop: + watch: + - action: sync + path: ./src + target: /app/src + ignore: + - node_modules/ + - action: sync + path: ./public + target: /app/public + ignore: + - node_modules/ + - action: rebuild + path: ./package.json + - action: rebuild + path: ./package-lock.json + ports: + - 8000:8000 + profiles: ["dev"] \ No newline at end of file diff --git a/package.json b/package.json index fd189fd4d..446966c89 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "start": "vite", "start:dev": "vite --mode development", + "start:dev:docker": "docker-compose --profile dev watch -d", "build": "vite build", "preview": "vite preview", "test": "vitest run",