diff --git a/README.md b/README.md index 721d41c..f6612a2 100644 --- a/README.md +++ b/README.md @@ -77,13 +77,25 @@ There are mainly 2 ways of installing Perplexica - With Docker, Without Docker. - `SIMILARITY_MEASURE`: The similarity measure to use (This is filled by default; you can leave it as is if you are unsure about it.) -5. Ensure you are in the directory containing the `docker-compose.yaml` file and execute: +5. Rename the `.env.example` file to `.env` and fill in all necessary fields. - ```bash - docker compose up -d - ``` + ```bash + mv .env.example .env + ``` -6. Wait a few minutes for the setup to complete. You can access Perplexica at http://localhost:3000 in your web browser. +6. Rename the `./ui/.env.example` file to `./ui/.env` and fill in all necessary fields. + + ```bash + mv ./ui/.env.example ./ui/.env + ``` + +7. Ensure you are in the directory containing the `docker-compose.yaml` file and execute: + + ```bash + docker compose up -d + ``` + +8. Wait a few minutes for the setup to complete. You can access Perplexica at http://localhost:3000 in your web browser. **Note**: After the containers are built, you can start Perplexica directly from Docker without having to open a terminal. diff --git a/app.dockerfile b/app.dockerfile index 488e64b..4dbce0d 100644 --- a/app.dockerfile +++ b/app.dockerfile @@ -1,15 +1,44 @@ -FROM node:20.18.0-alpine +############################# +# Build stage +############################# + +FROM node:22-alpine AS builder ARG NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 ARG NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api ENV NEXT_PUBLIC_WS_URL=${NEXT_PUBLIC_WS_URL} ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} -WORKDIR /home/perplexica +WORKDIR /app -COPY ui /home/perplexica/ +# Copy package.json and yarn.lock +COPY ui/package.json ui/yarn.lock ./ -RUN yarn install --frozen-lockfile -RUN yarn build +# Copy the rest of the application code +COPY ui . +# Install dependencies & build the application +RUN yarn install --frozen-lockfile && yarn build + +############################# +# Production stage +############################# + +FROM node:22-alpine + +ENV NEXT_PUBLIC_WS_URL=ws://localhost:3001 +ENV NEXT_PUBLIC_API_URL=http://localhost:3001/api + +WORKDIR /app + +# Copy built assets from the builder stage +COPY --chown=node:node --from=builder /app/.next ./.next +COPY --chown=node:node --from=builder /app/node_modules ./node_modules +COPY --chown=node:node --from=builder /app/package.json ./package.json +COPY --chown=node:node --from=builder /app/public ./public + +# Run the Docker image as node instead of root +USER node + +# Start the application CMD ["yarn", "start"] \ No newline at end of file diff --git a/backend.dockerfile b/backend.dockerfile index 87cd21c..87dc9dd 100644 --- a/backend.dockerfile +++ b/backend.dockerfile @@ -1,16 +1,48 @@ -FROM node:18-slim +############################# +# Build stage +############################# -WORKDIR /home/perplexica +FROM node:22-alpine AS builder -COPY src /home/perplexica/src -COPY tsconfig.json /home/perplexica/ -COPY drizzle.config.ts /home/perplexica/ -COPY package.json /home/perplexica/ -COPY yarn.lock /home/perplexica/ +WORKDIR /app -RUN mkdir /home/perplexica/data +# Copy package.json and yarn.lock +COPY package.json yarn.lock ./ -RUN yarn install --frozen-lockfile --network-timeout 600000 -RUN yarn build +# Copy the rest of the application code +COPY tsconfig.json drizzle.config.ts ./ +COPY src ./src +# Install dependencies & build the application +RUN yarn install --frozen-lockfile --network-timeout 600000 && yarn build + +############################# +# Production stage +############################# + +FROM node:22-alpine + +ARG USER=node + +WORKDIR /app + +# Copy built assets and necessary files from the builder stage +COPY --chown=node:node --from=builder /app/dist ./dist +COPY --chown=node:node --from=builder /app/node_modules ./node_modules + +# Copy the rest of the application code +COPY --chown=node:node drizzle.config.ts ./ +COPY --chown=node:node tsconfig.json ./ +COPY --chown=node:node src/db/schema.ts ./src/db/schema.ts +COPY --chown=node:node package.json ./package.json + +# Create data directory & set permissions to node user +RUN mkdir /app/data && \ + chown -R node:node /app/data && \ + chmod -R 755 /app/data + +# Run the Docker image as node or root if Docker Compose du to volume permissions +USER ${USER} + +# Start the application CMD ["yarn", "start"] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 46d82c6..69b8810 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -12,41 +12,42 @@ services: perplexica-backend: build: context: . + args: + - USER=root dockerfile: backend.dockerfile image: itzcrazykns1337/perplexica-backend:main environment: - SEARXNG_API_URL=http://searxng:8080 - depends_on: - - searxng ports: - 3001:3001 volumes: - - backend-dbstore:/home/perplexica/data - - ./config.toml:/home/perplexica/config.toml + - backend-dbstore:/app/data:rw + - ./config.toml:/app/config.toml:rw extra_hosts: - 'host.docker.internal:host-gateway' + networks: + - 'host.docker.internal:host-gateway' networks: - perplexica-network restart: unless-stopped - - perplexica-frontend: build: context: . dockerfile: app.dockerfile - args: - - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api - - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 image: itzcrazykns1337/perplexica-frontend:main + depends_on: + - perplexica-backend depends_on: - perplexica-backend ports: - 3000:3000 + - 3000:3000 networks: - perplexica-network + env_file: + - ./.env restart: unless-stopped networks: - perplexica-network: volumes: backend-dbstore: diff --git a/ui/.env.example b/ui/.env.example index 57a3ed9..f23835c 100644 --- a/ui/.env.example +++ b/ui/.env.example @@ -1,2 +1,3 @@ -NEXT_PUBLIC_WS_URL=ws://localhost:3001 -NEXT_PUBLIC_API_URL=http://localhost:3001/api \ No newline at end of file +NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 +NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api +SEARXNG_API_URL=http://searxng:8080 \ No newline at end of file