mirror of
https://github.com/C4illin/ConvertX.git
synced 2026-10-27 23:30:55 +01:00
build: use bun build to create binary (#674)
This commit is contained in:
@@ -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 }}
|
||||
|
||||
+19
-48
@@ -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
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
services:
|
||||
convertx:
|
||||
image: convertx:test
|
||||
pull_policy: build
|
||||
build:
|
||||
context: .
|
||||
|
||||
+2
-2
@@ -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 "$@"
|
||||
|
||||
+4
-2
@@ -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",
|
||||
|
||||
@@ -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}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user