-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmigrate.Dockerfile
58 lines (51 loc) · 2.44 KB
/
migrate.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
# syntax=docker/dockerfile:1.12.1@sha256:93bfd3b68c109427185cd78b4779fc82b484b0b7618e36d0f104d4d801e66d25
# ベースとするイメージを定義
FROM ubuntu:devel@sha256:008b026f11c0b5653d564d0c9877a116770f06dfbdb36ca75c46fd593d863cbc AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
# jqのバイナリを取得する => /jq
FROM ghcr.io/jqlang/jq:1.7@sha256:12f998e5a6f3f6916f744ba6f01549f156f624b42f7564e67ec6dd4733973146 AS fetch-jq
# pnpmを取得する => /pnpm/
FROM quay.io/curl/curl-base:8.11.1@sha256:e4944acb33bc89f4ee28246f84e6ff8f967bb62f63db79f9b577e1b1f2d8f006 AS fetch-pnpm
ENV SHELL="sh"
ENV ENV="/tmp/env"
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
WORKDIR /dist
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,from=fetch-jq,source=/jq,target=/mounted-bin/jq \
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 -
# .npmrcに設定を追記する => /_/.npmrc
FROM base AS change-npmrc
WORKDIR /_
COPY --link .npmrc ./
RUN echo "store-dir=/.pnpm-store" >> .npmrc
# Node.jsとdevDependenciesを取得する => /pnpm/,/.pnpm-store/,/_/node_modules/
FROM base AS fetch-deps
WORKDIR /_
COPY --link --from=fetch-pnpm /pnpm/ /pnpm/
ARG TARGETPLATFORM
RUN --mount=type=cache,id=pnpm-$TARGETPLATFORM,target=/.pnpm-store/ \
--mount=type=bind,from=change-npmrc,source=/_/.npmrc,target=.npmrc \
--mount=type=bind,source=pnpm-lock.yaml,target=pnpm-lock.yaml \
pnpm fetch --dev
# devDependenciesをインストールする => /_/node_modules/
FROM base AS dev-deps
WORKDIR /_
COPY --link --from=fetch-deps /_/node_modules/ ./node_modules/
ARG BUILDPLATFORM
RUN --mount=type=cache,id=pnpm-$BUILDPLATFORM,target=/.pnpm-store/ \
--mount=type=bind,from=fetch-deps,source=/pnpm/,target=/pnpm/ \
--mount=type=bind,from=change-npmrc,source=/_/.npmrc,target=.npmrc \
--mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=pnpm-lock.yaml,target=pnpm-lock.yaml \
--mount=type=bind,source=.husky/install.mjs,target=.husky/install.mjs \
pnpm install --frozen-lockfile --offline --dev
FROM base AS runner
WORKDIR /app
COPY --link prisma/ prisma/
COPY --link --from=fetch-deps /pnpm/ /pnpm/
COPY --link --from=dev-deps /_/node_modules/ ./node_modules/
COPY --link .npmrc package.json ./
ENTRYPOINT [ "pnpm", "--shell-emulator" ]
CMD [ "db:deploy" ]