Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: switch package manager from npm to pnpm #78

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install pnpm
uses: pnpm/action-setup@d882d12c64e032187b2edb46d3a0d003b7a43598 # v2.4.0
- name: Setup Node.js
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
with:
node-version: 20
cache: npm
cache: "pnpm"
node-version-file: ".node-version"
- name: Install dependencies
run: npm install
run: pnpm install --frozen-lockfile
- name: Check types
run: npm run tsc:check
run: pnpm run tsc:check
- name: Check lint rules
run: npm run lint:check
run: pnpm run lint:check
- name: Check format
run: npm run format:check
run: pnpm run format:check
10 changes: 10 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
save-exact=true
auto-install-peers=true
strict-peer-dependencies=true

shell-emulator=true

update-notifier=false

; npm の使用を防ぐ
engine-strict=true
package-lock-only=true
63 changes: 41 additions & 22 deletions Dockerfile
cm-ayf marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,33 +1,52 @@
# syntax=docker/dockerfile:1@sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50032edf31be0021

FROM node:20.10.0-bookworm AS deps
ARG NODE_ENV=production
WORKDIR /app
COPY ./package*.json ./
RUN npm ci

FROM --platform=$BUILDPLATFORM node:20.10.0-bookworm AS builder
ARG NODE_ENV=development
WORKDIR /app
COPY ./build.js ./
COPY ./package*.json ./
RUN npm ci
COPY ./src/ ./src/
RUN npm run build

FROM --platform=$BUILDPLATFORM node:20.10.0-bookworm AS model-fetch
# ビルド時に基礎として使うイメージを定義
FROM buildpack-deps:bookworm as base-build
ENV SHELL="sh"
ENV ENV="/tmp/env"
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
# jqのバイナリを取得する => /jq
FROM ghcr.io/jqlang/jq:1.7 as fetch-jq

# 音声モデルを取得する => /app/
FROM --platform=$BUILDPLATFORM base-build AS model-fetch
WORKDIR /app
RUN wget https://github.com/jpreprocess/jpreprocess/releases/download/v0.6.1/naist-jdic-jpreprocess.tar.gz \
&& tar xzf naist-jdic-jpreprocess.tar.gz \
&& rm naist-jdic-jpreprocess.tar.gz
RUN git clone --depth 1 https://github.com/icn-lab/htsvoice-tohoku-f01.git

FROM gcr.io/distroless/nodejs20-debian12:nonroot@sha256:015be521134f97b5f2b4c1543615eb4be907fadc8c6a52e60fd0c18f7cda0337 AS runner
FROM base-build as deps
WORKDIR /app
COPY --link --from=fetch-jq /jq ./
COPY --link package.json ./
RUN curl -fsSL --compressed https://get.pnpm.io/install.sh | env PNPM_VERSION=$(cat package.json | ./jq -r .packageManager | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') sh -
COPY --link .npmrc .node-version ./
RUN echo "store-dir=/.pnpm-store" >> .npmrc &&\
echo "use-node-version=`cat .node-version`" >> .npmrc
COPY --link pnpm-lock.yaml ./
ARG NODE_ENV="production"
RUN pnpm install --frozen-lockfile

# ビルドする => /app/dist/
FROM --platform=$BUILDPLATFORM deps as builder
ARG NODE_ENV=""
RUN pnpm install --frozen-lockfile
COPY --link build.js ./
COPY --link src/ ./src/
RUN pnpm build

FROM gcr.io/distroless/cc-debian12:nonroot as runner
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
ENV NODE_ENV="production"
WORKDIR /app
ENV NODE_ENV=production
COPY ./package.json ./
COPY --from=builder /app/dist/ ./dist/
COPY --link --from=model-fetch /app/ ./model/
COPY --link --from=deps /app/.npmrc ./
COPY --link --from=deps /pnpm/ /pnpm/
COPY --link --from=builder /app/dist/ ./dist/
COPY --from=deps /app/node_modules/ ./node_modules/
COPY --from=model-fetch /app/ ./model/
CMD ["dist/main.js"]
COPY --link package.json ./
ENTRYPOINT [ "pnpm", "--shell-emulator" ]
CMD [ "start" ]
Loading