mirror of
https://github.com/stonith404/pingvin-share.git
synced 2025-01-29 01:28:59 -05:00
Improve Docker image
This commit is contained in:
parent
d98c31f748
commit
961967f57a
5 changed files with 10 additions and 52 deletions
|
@ -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();
|
||||
|
||||
|
|
20
Dockerfile
20
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"]
|
||||
CMD npm run build && npm start
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 "$@"
|
|
@ -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 ."
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue