diff --git a/.dockerignore b/.dockerignore index babc429a..47e82a10 100644 --- a/.dockerignore +++ b/.dockerignore @@ -31,6 +31,9 @@ tsconfig.json /tmp /babel.config.js /ecosystem.config.js +/extra/healthcheck.exe +/extra/healthcheck + ### .gitignore content (commented rules are duplicated) diff --git a/.gitignore b/.gitignore index 78e1a965..06dca04b 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ cypress/screenshots /extra/healthcheck.exe /extra/healthcheck +/extra/healthcheck-armv7 diff --git a/docker/dockerfile b/docker/dockerfile index 6657e681..e084d649 100644 --- a/docker/dockerfile +++ b/docker/dockerfile @@ -1,15 +1,19 @@ ############################################ # Build in Golang -# Super slow for armv7 (compile time = 1200 seconds, but other platforms within 5 seconds). -# Do not change everything here, so it should always use the cache. +# Run npm run build-healthcheck-armv7 in the host first, another it will be super slow where it is building the armv7 healthcheck ############################################ FROM golang:1.19.4-buster AS build_healthcheck WORKDIR /app - -COPY ./extra/healthcheck.go ./extra/healthcheck.go +ARG TARGETPLATFORM +COPY ./extra/ ./extra/ # Compile healthcheck.go -RUN go build -x -o ./extra/healthcheck ./extra/healthcheck.go +RUN apt update +RUN apt --yes --no-install-recommends install curl +RUN curl -sL https://deb.nodesource.com/setup_18.x | bash +RUN apt --yes --no-install-recommends install nodejs +RUN node -v +RUN node ./extra/build-healthcheck.js $TARGETPLATFORM ############################################ # Build in Node.js @@ -18,8 +22,8 @@ FROM louislam/uptime-kuma:base-debian AS build WORKDIR /app ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1 - COPY . . +COPY --from=build_healthcheck /app/extra/healthcheck /app/extra/healthcheck RUN npm ci --production && \ chmod +x /app/extra/entrypoint.sh @@ -31,7 +35,7 @@ WORKDIR /app # Copy app files from build layer COPY --from=build /app /app -COPY --from=build_healthcheck /app/extra/healthcheck /app/extra/healthcheck + EXPOSE 3001 VOLUME ["/app/data"] diff --git a/extra/build-healthcheck.js b/extra/build-healthcheck.js new file mode 100644 index 00000000..e4c8026a --- /dev/null +++ b/extra/build-healthcheck.js @@ -0,0 +1,27 @@ +const childProcess = require("child_process"); +const fs = require("fs"); +const platform = process.argv[2]; + +if (!platform) { + console.error("No platform??"); + process.exit(1); +} + +if (platform === "linux/arm/v7") { + console.log("Arch: armv7"); + if (fs.existsSync("./extra/healthcheck-armv7")) { + fs.renameSync("./extra/healthcheck-armv7", "./extra/healthcheck"); + console.log("Already built in the host, skip."); + process.exit(0); + } else { + console.log("prebuilt not found, it will be slow! You should execute `npm run build-healthcheck-armv7` before build."); + } +} else { + if (fs.existsSync("./extra/healthcheck-armv7")) { + fs.rmSync("./extra/healthcheck-armv7"); + } +} + +const output = childProcess.execSync("go build -x -o ./extra/healthcheck ./extra/healthcheck.go").toString("utf8"); +console.log(output); + diff --git a/package.json b/package.json index f43c21d4..0a0a7aed 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,8 @@ "start-pr-test": "node extra/checkout-pr.js && npm install && npm run dev", "cy:test": "node test/prepare-test-server.js && node server/server.js --port=3002 --data-dir=./data/test/ --e2e", "cy:run": "npx cypress run --browser chrome --headless --config-file ./config/cypress.config.js", - "cypress-open": "concurrently -k -r \"node test/prepare-test-server.js && node server/server.js --port=3002 --data-dir=./data/test/\" \"cypress open --config-file ./config/cypress.config.js\"" + "cypress-open": "concurrently -k -r \"node test/prepare-test-server.js && node server/server.js --port=3002 --data-dir=./data/test/\" \"cypress open --config-file ./config/cypress.config.js\"", + "build-healthcheck-armv7": "cross-env GOOS=linux GOARCH=arm GOARM=7 go build -x -o ./extra/healthcheck-armv7 ./extra/healthcheck.go" }, "dependencies": { "@grpc/grpc-js": "~1.7.3",