Skip to content

Commit c737cef

Browse files
committed
wip
1 parent 2aedae3 commit c737cef

File tree

1 file changed

+44
-26
lines changed

1 file changed

+44
-26
lines changed

Dockerfile

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,73 @@
11
# syntax=docker/dockerfile:1@sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50032edf31be0021
22

3-
FROM buildpack-deps:bookworm AS model-fetch
3+
# ビルド時に基礎として使うイメージを定義
4+
FROM buildpack-deps:bookworm as base-build
5+
ENV PNPM_HOME="/pnpm"
6+
ENV PATH="$PNPM_HOME:$PATH"
7+
# jqのバイナリを取得する => /jq
8+
FROM ghcr.io/jqlang/jq:1.7 as fetch-jq
9+
10+
# 音声モデルを取得する => /app/
11+
FROM --platform=$BUILDPLATFORM base-build AS model-fetch
412
WORKDIR /app
513
RUN wget https://github.com/jpreprocess/jpreprocess/releases/download/v0.6.1/naist-jdic-jpreprocess.tar.gz \
614
&& tar xzf naist-jdic-jpreprocess.tar.gz \
715
&& rm naist-jdic-jpreprocess.tar.gz
816
RUN git clone --depth 1 https://github.com/icn-lab/htsvoice-tohoku-f01.git
917

10-
FROM ghcr.io/jqlang/jq:1.7 as fetch-jq
11-
12-
FROM quay.io/curl/curl-base:8.4.0 as fetch-pnpm
18+
# pnpmを取得する => /pnpm/
19+
FROM base-build as fetch-pnpm
1320
ENV SHELL="sh"
1421
ENV ENV="/tmp/env"
15-
ENV PNPM_HOME="/pnpm"
1622
WORKDIR /dist
1723
RUN --mount=type=bind,source=package.json,target=package.json \
1824
--mount=type=bind,from=fetch-jq,source=/jq,target=/mounted-bin/jq \
1925
curl -fsSL --compressed https://get.pnpm.io/install.sh | env PNPM_VERSION=$(cat package.json | /mounted-bin/jq -r .packageManager | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') sh -
2026

21-
FROM buildpack-deps:bookworm as fetch-deps
22-
ENV PNPM_HOME="/pnpm"
23-
ENV PATH="$PNPM_HOME:$PATH"
24-
WORKDIR /package
27+
# .npmrcに設定を追記する => /.npmrc
28+
FROM base-build as change-npmrc
29+
COPY --link .npmrc ./
30+
RUN --mount=type=bind,source=.node-version,target=.node-version \
31+
echo \
32+
"store-dir=/.pnpm-store\n \
33+
use-node-version=`cat .node-version`"\
34+
>> .npmrc
35+
36+
# Node.jsと依存パッケージを取得する => /pnpm/,/.pnpm-store
37+
FROM base-build as fetch-deps
2538
COPY --link --from=fetch-pnpm /pnpm/ /pnpm/
26-
RUN pnpm config set store-dir /.pnpm-store
27-
COPY --link .npmrc .node-version ./
28-
RUN echo "use-node-version=`cat .node-version`" >> .npmrc
2939
RUN --mount=type=cache,target=/.pnpm-store \
40+
--mount=type=bind,from=change-npmrc,source=/.npmrc,target=.npmrc \
41+
--mount=type=bind,source=package.json,target=package.json \
3042
--mount=type=bind,source=pnpm-lock.yaml,target=pnpm-lock.yaml \
3143
pnpm fetch
32-
COPY --link package.json ./
3344

34-
FROM fetch-deps as dev-deps
35-
RUN --mount=type=cache,target=/.pnpm-store \
45+
# dev用の依存パッケージをインストールする => /node_modules/
46+
FROM --platform=$BUILDPLATFORM base-build as dev-deps
47+
RUN --mount=type=bind,from=fetch-deps,source=/pnpm/,target=/pnpm/ \
48+
--mount=type=bind,from=fetch-deps,source=/.pnpm-store,target=.pnpm-store \
49+
--mount=type=bind,from=change-npmrc,source=/.npmrc,target=.npmrc \
50+
--mount=type=bind,source=package.json,target=package.json \
3651
--mount=type=bind,source=pnpm-lock.yaml,target=pnpm-lock.yaml \
3752
pnpm install --frozen-lockfile --offline
3853

39-
FROM buildpack-deps:bookworm as builder
40-
ENV PNPM_HOME="/pnpm"
41-
ENV PATH="$PNPM_HOME:$PATH"
42-
WORKDIR /app
54+
# ビルドする => /dist/
55+
FROM --platform=$BUILDPLATFORM base-build as builder
4356
RUN --mount=type=bind,from=fetch-deps,source=/pnpm/,target=/pnpm/ \
44-
--mount=type=bind,from=dev-deps,source=/package/node_modules/,target=node_modules/ \
57+
--mount=type=bind,from=dev-deps,source=/app/node_modules/,target=node_modules/ \
58+
--mount=type=bind,from=change-npmrc,source=/.npmrc,target=.npmrc \
4559
--mount=type=bind,source=package.json,target=package.json \
46-
--mount=type=bind,source=.npmrc,target=.npmrc \
4760
--mount=type=bind,source=build.js,target=build.js \
4861
--mount=type=bind,source=src/,target=src/ \
4962
pnpm build
5063

51-
FROM fetch-deps as prod-deps
64+
# prod用の依存パッケージをインストールする => /node_modules/
65+
FROM base-build as prod-deps
5266
ARG NODE_ENV="production"
53-
RUN --mount=type=cache,target=/.pnpm-store \
67+
RUN --mount=type=bind,from=fetch-deps,source=/pnpm/,target=/pnpm/ \
68+
--mount=type=bind,from=fetch-deps,source=/.pnpm-store,target=.pnpm-store \
69+
--mount=type=bind,from=change-npmrc,source=/.npmrc,target=.npmrc \
70+
--mount=type=bind,source=package.json,target=package.json \
5471
--mount=type=bind,source=pnpm-lock.yaml,target=pnpm-lock.yaml \
5572
pnpm install --frozen-lockfile --offline
5673

@@ -61,8 +78,9 @@ ENV NODE_ENV="production"
6178
WORKDIR /app
6279
COPY --link --from=model-fetch /app/ ./model/
6380
COPY --link --from=fetch-deps /pnpm/ /pnpm/
64-
COPY --link --from=builder /app/dist/ ./dist/
65-
COPY --from=prod-deps /package/node_modules/ ./node_modules/
66-
COPY --link .npmrc package.json ./
81+
COPY --link --from=builder /dist/ ./dist/
82+
COPY --from=prod-deps /node_modules/ ./node_modules/
83+
COPY --link --from=prod-deps /app/.npmrc ./
84+
COPY --link package.json ./
6785
ENTRYPOINT [ "pnpm", "--shell-emulator" ]
6886
CMD [ "start" ]

0 commit comments

Comments
 (0)