diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 9158d73d..5714cb31 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -79,6 +79,7 @@ jobs: uses: docker/build-push-action@v7 with: context: . + target: test platforms: ${{ matrix.platform }} load: true tags: convertx:test @@ -96,6 +97,7 @@ jobs: DOCKER_BUILDKIT: 1 with: context: . + target: release platforms: ${{ matrix.platform }} labels: ${{ steps.meta.outputs.labels }} annotations: ${{ steps.meta.outputs.annotations }} diff --git a/Dockerfile b/Dockerfile index 2e80a69c..e4792c3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,51 +1,14 @@ -FROM debian:testing-slim AS base -LABEL org.opencontainers.image.source="https://github.com/C4illin/ConvertX" +FROM oven/bun:1.4.3-slim AS base WORKDIR /app - -# install bun -RUN apt-get update && apt-get install -y \ - ca-certificates \ - curl \ - unzip \ - && rm -rf /var/lib/apt/lists/* - -COPY .bun-version . - -# if architecture is arm64, use the arm64 version of bun -RUN ARCH=$(uname -m) && \ - BUN_VERSION=$(cat .bun-version) && \ - if [ "$ARCH" = "aarch64" ]; then \ - curl -fsSL -o bun-linux-aarch64.zip https://github.com/oven-sh/bun/releases/download/bun-v${BUN_VERSION}/bun-linux-aarch64.zip; \ - else \ - curl -fsSL -o bun-linux-x64-baseline.zip https://github.com/oven-sh/bun/releases/download/bun-v${BUN_VERSION}/bun-linux-x64-baseline.zip; \ - fi - -RUN unzip -j bun-linux-*.zip -d /usr/local/bin && \ - rm bun-linux-*.zip && \ - chmod +x /usr/local/bin/bun - -# install dependencies into temp directory -# this will cache them and speed up future builds -FROM base AS install -RUN mkdir -p /temp/dev -COPY package.json bun.lock /temp/dev/ -RUN cd /temp/dev && bun install --frozen-lockfile - -# install with --production (exclude devDependencies) -RUN mkdir -p /temp/prod -COPY package.json bun.lock /temp/prod/ -RUN cd /temp/prod && bun install --frozen-lockfile --production - -FROM base AS prerelease -WORKDIR /app -COPY --from=install /temp/dev/node_modules node_modules +COPY package.json bun.lock /app/ +RUN bun install --frozen-lockfile COPY . . -# ENV NODE_ENV=production -RUN bun run build +RUN bun run build:bin -# copy production dependencies and source code into final image -FROM base AS release +FROM debian:testing-slim AS release +LABEL org.opencontainers.image.source="https://github.com/C4illin/ConvertX" +WORKDIR /app # install additional dependencies ENV PIPX_HOME=/opt/pipx @@ -53,7 +16,9 @@ ENV PIPX_BIN_DIR=/usr/local/bin RUN apt-get update && apt-get install -y \ assimp-utils \ + ca-certificates \ calibre \ + curl \ dasel \ dcraw \ djvulibre-bin \ @@ -108,9 +73,8 @@ RUN ARCH=$(uname -m) && \ chmod +x /usr/local/bin/vtracer && \ rm /tmp/vtracer.tar.gz -COPY --from=install /temp/prod/node_modules node_modules -COPY --from=prerelease /app/public/ /app/public/ -COPY --from=prerelease /app/dist /app/dist +COPY --from=base /app/public/ /app/public/ +COPY --from=base /app/dist/convertx /app/convertx # COPY . . RUN mkdir data @@ -123,4 +87,11 @@ EXPOSE 3000/tcp ENV QTWEBENGINE_CHROMIUM_FLAGS="--no-sandbox" ENV NODE_ENV=production ENTRYPOINT [ "/entrypoint.sh" ] -CMD [ "bun", "run", "dist/src/index.js" ] +CMD [ "/app/convertx" ] + +# test stage that includes Bun for running tests if needed +FROM release AS test +COPY --from=base /usr/local/bin/bun /usr/local/bin/bun + +# default target remains release +FROM release diff --git a/compose.yaml b/compose.yaml index 89c7bb66..6df4b69e 100644 --- a/compose.yaml +++ b/compose.yaml @@ -2,7 +2,6 @@ services: convertx: - image: convertx:test pull_policy: build build: context: . diff --git a/entrypoint.sh b/entrypoint.sh index acc2259d..e1777314 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -12,7 +12,7 @@ if [ -z "$PUID" ] || [ "$PUID" -eq 0 ]; then umask "$UMASK" fi if [ $# -eq 0 ]; then - set -- bun run dist/src/index.js + set -- /app/convertx fi exec "$@" fi @@ -45,7 +45,7 @@ fi export HOME=/home/convertx if [ $# -eq 0 ]; then - set -- bun run dist/src/index.js + set -- /app/convertx fi exec gosu convertx "$@" diff --git a/package.json b/package.json index 1af606a4..b58741a3 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,11 @@ "format": "npm-run-all 'format:*'", "format:eslint": "eslint --fix .", "format:prettier": "prettier --write .", + "build:css": "bun x @tailwindcss/cli -i ./src/main.css -o ./public/generated.css", "build:js": "tsc", + "build:bin": "bun run build:css && bun build --compile --minify --sourcemap --bytecode --format=esm --define 'process.env.NODE_ENV=\"production\"' src/index.tsx --outfile dist/convertx", "build:docker": "docker compose build", - "build": "bun x @tailwindcss/cli -i ./src/main.css -o ./public/generated.css && bun run build:js", + "build": "bun run build:css && bun run build:js", "lint": "npm-run-all 'lint:*'", "lint:tsc": "tsc --noEmit", "lint:knip": "knip", @@ -17,7 +19,7 @@ "lint:prettier": "prettier --check .", "lint:xss": "xss-scan", "test": "bun test --path-ignore-patterns=tests/integration", - "test:integration": "docker run --rm -v ./tests:/app/tests -v ./src:/app/src -v ./package.json:/app/package.json convertx:test bun test tests/integration" + "test:integration": "docker build --target test -t convertx:test . && docker run --rm -t -v ./tests:/app/tests -v ./src:/app/src -v ./package.json:/app/package.json convertx:test bun test tests/integration" }, "dependencies": { "@elysiajs/html": "^1.4.2", diff --git a/src/helpers/printVersions.ts b/src/helpers/printVersions.ts index 57b5bf0a..93b615de 100644 --- a/src/helpers/printVersions.ts +++ b/src/helpers/printVersions.ts @@ -211,14 +211,5 @@ if (process.env.NODE_ENV === "production") { } }); - exec("bun -v", (error, stdout) => { - if (error) { - console.error("Bun is not installed. wait what"); - return; - } - - if (stdout) { - console.log(`Bun v${stdout.split("\n")[0]}`); - } - }); + console.log(`Bun v${Bun.version}`); }