diff --git a/.setup/index.ts b/.setup/index.ts index a109074..4c70f78 100644 --- a/.setup/index.ts +++ b/.setup/index.ts @@ -14,6 +14,11 @@ import rl from "readline-sync"; defaultInput: "http://localhost/v1", } ); + process.env["APPWRITE_HOST"] = process.env["APPWRITE_HOST"].replace( + "localhost", + "host.docker.internal" + ); + console.info("Authenticate..."); process.env["APPWRITE_USER_TOKEN"] = await authService.getToken(); diff --git a/Dockerfile b/Dockerfile index 5d3229e..5b76f30 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,12 +4,6 @@ WORKDIR /opt/app COPY package.json package-lock.json ./ RUN npm ci -FROM node:16-alpine AS builder -ENV NODE_ENV=production -WORKDIR /opt/app -COPY . . -COPY --from=deps /opt/app/node_modules ./node_modules -RUN npm run build FROM node:16-alpine AS script-builder WORKDIR /opt/app @@ -23,17 +17,9 @@ RUN ncc build index.ts FROM node:16-alpine AS runner WORKDIR /opt/app ENV NODE_ENV=production -COPY --from=builder /opt/app/next.config.js ./ -COPY --from=builder /opt/app/public ./public -COPY --from=builder /opt/app/.next ./.next -COPY --from=builder /opt/app/node_modules ./node_modules +COPY . . +COPY --from=deps /opt/app/node_modules ./node_modules COPY --from=script-builder /opt/app/.setup/dist/index.js ./scripts/setup.js -COPY .env.example .env -COPY entrypoint.sh . -RUN apk add --no-cache --upgrade bash -RUN ["chmod", "+x", "./entrypoint.sh"] -ENTRYPOINT ["./entrypoint.sh"] - EXPOSE 3000 -CMD ["node_modules/.bin/next", "start"] \ No newline at end of file +CMD npm run build && npm start \ No newline at end of file diff --git a/README.md b/README.md index 711b024..02f23d2 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Pingvin Share is currently in beta and there are issues and limitations that sho - `DownloadAll` generates the zip file on the client side. This takes alot of time. Because of that I temporarily limited this function to maximal 150 MB. - If a user knows the share id, he can list and download the files directly from the Appwrite API even if the share is secured by a password or a visitor limit. +- Because NextJS injects environments variables at build time, the website must be rebuilt when an environment variable changes. At the moment the container rebuilts the website after every restart. This takes some time. ## Contribute diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100644 index 93baeb8..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -# This script is used to inject env variables in Docker after the build. -# Normally the env variables get injecten while the build. This means, you can't add env variables when you start the conatainer. -# Source of the script: https://raphaelpralat.medium.com/system-environment-variables-in-next-js-with-docker-1f0754e04cde - -set +x - -envFilename='.env' -nextFolder='./.next/' -function apply_path { - # read all config file - while read line; do - # no comment or not empty - if [ "${line:0:1}" == "#" ] || [ "${line}" == "" ]; then - continue - fi - - # split - configName="$(cut -d'=' -f1 <<<"$line")" - configValue="$(cut -d'=' -f2 <<<"$line")" - # get system env - envValue=$(env | grep "^$configName=" | grep -oe '[^=]*$'); - - # if config found - if [ -n "$configValue" ] && [ -n "$envValue" ]; then - # replace all - echo "Replace: ${configValue} with: ${envValue}" - find $nextFolder \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#$configValue#$envValue#g" - fi - done < $envFilename - } - -apply_path -echo "Starting Nextjs" -exec "$@" \ No newline at end of file diff --git a/package.json b/package.json index b476306..20669b7 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "build": "next build", "start": "next start", "lint": "next lint", + "start:docker": "docker build -t pingvin-share:latest . && docker run pingvin-share:latest", "init:appwrite": "cd .setup && npm install && npx ts-node index.ts", "deploy": "docker buildx build -t stonith404/pingvin-share --platform linux/amd64,linux/arm64 --push ." },