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
|
uses: docker/build-push-action@v7
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
|
target: test
|
||||||
platforms: ${{ matrix.platform }}
|
platforms: ${{ matrix.platform }}
|
||||||
load: true
|
load: true
|
||||||
tags: convertx:test
|
tags: convertx:test
|
||||||
@@ -96,6 +97,7 @@ jobs:
|
|||||||
DOCKER_BUILDKIT: 1
|
DOCKER_BUILDKIT: 1
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
|
target: release
|
||||||
platforms: ${{ matrix.platform }}
|
platforms: ${{ matrix.platform }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
annotations: ${{ steps.meta.outputs.annotations }}
|
annotations: ${{ steps.meta.outputs.annotations }}
|
||||||
|
|||||||
+19
-48
@@ -1,51 +1,14 @@
|
|||||||
FROM debian:testing-slim AS base
|
FROM oven/bun:1.4.3-slim AS base
|
||||||
LABEL org.opencontainers.image.source="https://github.com/C4illin/ConvertX"
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
COPY package.json bun.lock /app/
|
||||||
# install bun
|
RUN bun install --frozen-lockfile
|
||||||
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 . .
|
COPY . .
|
||||||
|
|
||||||
# ENV NODE_ENV=production
|
RUN bun run build:bin
|
||||||
RUN bun run build
|
|
||||||
|
|
||||||
# copy production dependencies and source code into final image
|
FROM debian:testing-slim AS release
|
||||||
FROM base AS release
|
LABEL org.opencontainers.image.source="https://github.com/C4illin/ConvertX"
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
# install additional dependencies
|
# install additional dependencies
|
||||||
ENV PIPX_HOME=/opt/pipx
|
ENV PIPX_HOME=/opt/pipx
|
||||||
@@ -53,7 +16,9 @@ ENV PIPX_BIN_DIR=/usr/local/bin
|
|||||||
|
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
assimp-utils \
|
assimp-utils \
|
||||||
|
ca-certificates \
|
||||||
calibre \
|
calibre \
|
||||||
|
curl \
|
||||||
dasel \
|
dasel \
|
||||||
dcraw \
|
dcraw \
|
||||||
djvulibre-bin \
|
djvulibre-bin \
|
||||||
@@ -108,9 +73,8 @@ RUN ARCH=$(uname -m) && \
|
|||||||
chmod +x /usr/local/bin/vtracer && \
|
chmod +x /usr/local/bin/vtracer && \
|
||||||
rm /tmp/vtracer.tar.gz
|
rm /tmp/vtracer.tar.gz
|
||||||
|
|
||||||
COPY --from=install /temp/prod/node_modules node_modules
|
COPY --from=base /app/public/ /app/public/
|
||||||
COPY --from=prerelease /app/public/ /app/public/
|
COPY --from=base /app/dist/convertx /app/convertx
|
||||||
COPY --from=prerelease /app/dist /app/dist
|
|
||||||
|
|
||||||
# COPY . .
|
# COPY . .
|
||||||
RUN mkdir data
|
RUN mkdir data
|
||||||
@@ -123,4 +87,11 @@ EXPOSE 3000/tcp
|
|||||||
ENV QTWEBENGINE_CHROMIUM_FLAGS="--no-sandbox"
|
ENV QTWEBENGINE_CHROMIUM_FLAGS="--no-sandbox"
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENTRYPOINT [ "/entrypoint.sh" ]
|
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:
|
services:
|
||||||
convertx:
|
convertx:
|
||||||
image: convertx:test
|
|
||||||
pull_policy: build
|
pull_policy: build
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
|
|||||||
+2
-2
@@ -12,7 +12,7 @@ if [ -z "$PUID" ] || [ "$PUID" -eq 0 ]; then
|
|||||||
umask "$UMASK"
|
umask "$UMASK"
|
||||||
fi
|
fi
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
set -- bun run dist/src/index.js
|
set -- /app/convertx
|
||||||
fi
|
fi
|
||||||
exec "$@"
|
exec "$@"
|
||||||
fi
|
fi
|
||||||
@@ -45,7 +45,7 @@ fi
|
|||||||
export HOME=/home/convertx
|
export HOME=/home/convertx
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
set -- bun run dist/src/index.js
|
set -- /app/convertx
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec gosu convertx "$@"
|
exec gosu convertx "$@"
|
||||||
|
|||||||
+4
-2
@@ -7,9 +7,11 @@
|
|||||||
"format": "npm-run-all 'format:*'",
|
"format": "npm-run-all 'format:*'",
|
||||||
"format:eslint": "eslint --fix .",
|
"format:eslint": "eslint --fix .",
|
||||||
"format:prettier": "prettier --write .",
|
"format:prettier": "prettier --write .",
|
||||||
|
"build:css": "bun x @tailwindcss/cli -i ./src/main.css -o ./public/generated.css",
|
||||||
"build:js": "tsc",
|
"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: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": "npm-run-all 'lint:*'",
|
||||||
"lint:tsc": "tsc --noEmit",
|
"lint:tsc": "tsc --noEmit",
|
||||||
"lint:knip": "knip",
|
"lint:knip": "knip",
|
||||||
@@ -17,7 +19,7 @@
|
|||||||
"lint:prettier": "prettier --check .",
|
"lint:prettier": "prettier --check .",
|
||||||
"lint:xss": "xss-scan",
|
"lint:xss": "xss-scan",
|
||||||
"test": "bun test --path-ignore-patterns=tests/integration",
|
"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": {
|
"dependencies": {
|
||||||
"@elysiajs/html": "^1.4.2",
|
"@elysiajs/html": "^1.4.2",
|
||||||
|
|||||||
@@ -211,14 +211,5 @@ if (process.env.NODE_ENV === "production") {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
exec("bun -v", (error, stdout) => {
|
console.log(`Bun v${Bun.version}`);
|
||||||
if (error) {
|
|
||||||
console.error("Bun is not installed. wait what");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stdout) {
|
|
||||||
console.log(`Bun v${stdout.split("\n")[0]}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user