-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathDockerfile
70 lines (62 loc) · 2.16 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# https://bun.sh/guides/ecosystem/docker
# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:1-alpine as base
WORKDIR /app
# 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.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile
# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production
# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM base AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .
# [optional] tests & build
ENV NODE_ENV=production
# RUN bun test
# RUN bun run build
# copy production dependencies and source code into final image
FROM base AS release
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /app/index.ts .
COPY --from=prerelease /app/print.css .
COPY --from=prerelease /app/package.json .
# install prince
VOLUME /app
ARG TARGETARCH
# https://www.princexml.com/latest/
# https://www.princexml.com/download/prince-14.2-alpine3.13-x86_64.tar.gz -o prince.tar.gz
ARG PRINCE_VER=15.1
ARG DISTRO=linux-generic
RUN echo "Building for $TARGETARCH"
RUN apk add --no-cache curl
RUN prince_arch=$([ "$TARGETARCH" == "arm64" ] && echo "aarch64-musl" || echo "x86_64") \
&& curl https://www.princexml.com/download/prince-${PRINCE_VER}-${DISTRO}-${prince_arch}.tar.gz -o prince.tar.gz \
&& mkdir prince \
&& tar -zxvf prince.tar.gz -C prince --strip-components=1 \
&& rm prince.tar.gz \
&& cd prince \
&& yes "" | ./install.sh
RUN apk add --no-cache \
terminus-font \
ttf-inconsolata \
ttf-dejavu \
font-croscore \
font-noto \
font-noto-extra \
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/community/
# Install fonts
RUN apk add --no-cache msttcorefonts-installer fontconfig && \
update-ms-fonts && \
fc-cache -f && rm -rf /var/cache/*
# run the app
USER bun
EXPOSE 8080/tcp
ENTRYPOINT [ "bun", "run", "index.ts" ]