From 3b1611548b342471bc5f643526a51e854cf43119 Mon Sep 17 00:00:00 2001 From: valgul Date: Thu, 2 Nov 2023 22:55:07 +0100 Subject: [PATCH 1/2] Add Dockerfile and compose.yml for Docker setup This commit adds a Dockerfile and compose.yml for building and running the application in a containerized environment. --- .github/workflows/docker.yml | 32 ++++++++++++++++++++++++++++++++ Dockerfile | 22 ++++++++++++++++++++++ compose.yml | 20 ++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile create mode 100644 compose.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..accbfe3 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,32 @@ +name: Docker ci + +on: + push: + branches: [ master ] + + +jobs: + + docker: + + runs-on: ubuntu-latest + + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + - name: Build and push + id: docker_build + uses: docker/build-push-action@v5 + with: + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ secrets.DOCKER_HUB_USERNAME }}/adolla:latest + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d17fe82 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +# Stage 1: Build the application +FROM node:16-alpine AS builder + +WORKDIR /app + +COPY package*.json ./ + +RUN npm install + +COPY . . + +RUN npm run build + + +# Stage 2: Run the application +FROM node:16-alpine + +WORKDIR /app + +COPY --from=builder /app/build ./build + +CMD ["npm", "start"] \ No newline at end of file diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..085b67e --- /dev/null +++ b/compose.yml @@ -0,0 +1,20 @@ +version: '3' +services: + adolla: + build: + context: . + dockerfile: Dockerfile + container_name: "adolla" + restart: unless-stopped + environment: + - PORT=8080 # the port the web app will run on + #- MAXREADINGTOSHOWPOPULAR=10 # the amount of items in "continue reading" required to stop showing "popular" on the home page (for faster loading) + #- IGNOREREADING= #stop storing the progress. Old progress will be kept and shown, but nothing new will be added. Useful for shared servers. + #- TELEGRAMTOKEN= # Telegram bot token to send from + #- TELEGRAMUSER= # Telegram user ID to send new chapters & updates to. Not sure what your ID? Plug in your bot token, start the app, and send the bot a message. Adolla will log your user ID. + #- DISCORDWEBHOOK= # Discord webhook URL to send new chapters & updates to. + #- DISABLE_ANALYTICS= # disable sending a message to me when you start Adolla (useful for me to know how many users I have). + #- IMAGE_PROXY_URL= # the URL to use for image proxy. By default is makes a request in the back-end and pipes the response through. It's recommended you use a third-party proxy on lower powered devices like a Raspberry Pi with 1GB of RAM. + #- DIRSUFFIX= # suffix to add to the .adolla folder (for example, DIRSUFFIX=hi makes .adolla-hi) + ports: + - 8080:8080 # host port: docker port. they can be different. \ No newline at end of file From 6ee644462dba41e78140ee70ad24184ce8ecf9b4 Mon Sep 17 00:00:00 2001 From: valgul Date: Thu, 2 Nov 2023 23:05:44 +0100 Subject: [PATCH 2/2] Use Non-Root User and Set Environment Variables in Dockerfile. --- Dockerfile | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index d17fe82..e7b0df6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,12 +11,20 @@ COPY . . RUN npm run build - # Stage 2: Run the application FROM node:16-alpine WORKDIR /app -COPY --from=builder /app/build ./build +COPY --from=builder /app/ . + +# Create a non-root user and switch to that user +RUN addgroup -g 1001 adollagroup && adduser -u 1001 -G adollagroup -s /bin/sh -D adolla +USER adolla + +# Set environment variables +ENV NODE_ENV production + +EXPOSE 8080 -CMD ["npm", "start"] \ No newline at end of file +CMD ["npm", "start"]