diff --git a/.dockerignore b/.dockerignore index 62925caa..6e11b36b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -28,6 +28,7 @@ install.sh SECURITY.md tsconfig.json .env +/tmp ### .gitignore content (commented rules are duplicated) diff --git a/dockerfile b/dockerfile index b6c48b28..ae935de6 100644 --- a/dockerfile +++ b/dockerfile @@ -4,7 +4,7 @@ WORKDIR /app ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1 COPY . . -RUN npm install --legacy-peer-deps && \ +RUN npm ci && \ npm run build && \ npm prune --production && \ chmod +x /app/extra/entrypoint.sh diff --git a/dockerfile-alpine b/dockerfile-alpine index 7604c40c..a3a079eb 100644 --- a/dockerfile-alpine +++ b/dockerfile-alpine @@ -4,7 +4,7 @@ WORKDIR /app ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1 COPY . . -RUN npm install --legacy-peer-deps && \ +RUN npm ci && \ npm run build && \ npm prune --production && \ chmod +x /app/extra/entrypoint.sh diff --git a/extra/download-dist.js b/extra/download-dist.js new file mode 100644 index 00000000..0a08b7f9 --- /dev/null +++ b/extra/download-dist.js @@ -0,0 +1,57 @@ +console.log("Downloading dist"); +const https = require("https"); +const tar = require("tar"); + +const packageJSON = require("../package.json"); +const fs = require("fs"); +const version = packageJSON.version; + +const filename = "dist.tar.gz"; + +const url = `https://github.com/louislam/uptime-kuma/releases/download/${version}/${filename}`; +download(url); + +function download(url) { + console.log(url); + + https.get(url, (response) => { + if (response.statusCode === 200) { + console.log("Extracting dist..."); + + if (fs.existsSync("./dist")) { + + if (fs.existsSync("./dist-backup")) { + fs.rmdirSync("./dist-backup", { + recursive: true + }); + } + + fs.renameSync("./dist", "./dist-backup"); + } + + const tarStream = tar.x({ + cwd: "./", + }); + + tarStream.on("close", () => { + fs.rmdirSync("./dist-backup", { + recursive: true + }); + console.log("Done"); + }); + + tarStream.on("error", () => { + if (fs.existsSync("./dist-backup")) { + fs.renameSync("./dist-backup", "./dist"); + } + console.log("Done"); + }); + + response.pipe(tarStream); + } else if (response.statusCode === 302) { + download(response.headers.location); + } else { + console.log("dist not found"); + } + }); +} diff --git a/package-lock.json b/package-lock.json index 3820dbf7..104b38c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,6 +40,7 @@ "redbean-node": "0.1.2", "socket.io": "~4.2.0", "socket.io-client": "~4.2.0", + "tar": "^6.1.11", "tcp-ping": "~0.1.1", "thirty-two": "~1.0.2", "timezones-list": "~3.0.1", diff --git a/package.json b/package.json index 024816ba..ae8ed1b1 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,8 @@ "build-docker-nightly-alpine": "docker buildx build -f dockerfile-alpine --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:nightly-alpine --target nightly . --push", "build-docker-nightly-amd64": "docker buildx build --platform linux/amd64 -t louislam/uptime-kuma:nightly-amd64 --target nightly . --push --progress plain", "upload-artifacts": "docker buildx build --platform linux/amd64 -t louislam/uptime-kuma:upload-artifact --build-arg GITHUB_TOKEN --target upload-artifact . --progress plain", - "setup": "git checkout 1.7.3 && npm install --legacy-peer-deps && node node_modules/esbuild/install.js && npm run build && npm prune", + "setup": "git checkout 1.7.3 && npm ci --production && npm run download-dist", + "download-dist": "node extra/download-dist.js", "update-version": "node extra/update-version.js", "mark-as-nightly": "node extra/mark-as-nightly.js", "reset-password": "node extra/reset-password.js", @@ -81,6 +82,7 @@ "redbean-node": "0.1.2", "socket.io": "~4.2.0", "socket.io-client": "~4.2.0", + "tar": "^6.1.11", "tcp-ping": "~0.1.1", "thirty-two": "~1.0.2", "timezones-list": "~3.0.1",