Skip to content

Commit

Permalink
build: switch package manager from npm to pnpm
Browse files Browse the repository at this point in the history
Signed-off-by: Mogyuchi <[email protected]>
  • Loading branch information
Mogyuchi committed Dec 19, 2023
1 parent 84ad44e commit a7265bd
Show file tree
Hide file tree
Showing 9 changed files with 2,934 additions and 4,785 deletions.
26 changes: 18 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Node.js
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
- name: Install pnpm
uses: pnpm/action-setup@d882d12c64e032187b2edb46d3a0d003b7a43598 # v2.4.0
with:
node-version: 20
cache: npm
standalone: true
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: npm install
run: pnpm install --frozen-lockfile --strict-peer-dependencies
- 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
12 changes: 12 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
use-node-version=20.10.0

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
9 changes: 9 additions & 0 deletions .renovaterc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
],
"dependencyDashboardAutoclose": true,
"prConcurrentLimit": 3,
"customManagers": [
{
"customType": "regex",
"fileMatch": ["(^|/)\\.npmrc$"],
"matchStrings": ["use-node-version=(?<currentValue>.*?)\\n"],
"depNameTemplate": "node",
"datasourceTemplate": "node-version"
}
],
"packageRules": [
{
"matchDepTypes": ["dependencies", "require"],
Expand Down
2 changes: 1 addition & 1 deletion .simple-git-hooks.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"pre-commit": "npx lint-staged"
"pre-commit": "pnpm exec lint-staged"
}
84 changes: 60 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,69 @@
# 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 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 ghcr.io/jqlang/jq:1.7 as fetch-jq

FROM quay.io/curl/curl-base:8.4.0 as fetch-pnpm
ENV SHELL="sh"
ENV ENV="/tmp/env"
ENV PNPM_HOME="/pnpm"
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 -

FROM buildpack-deps:bookworm as fetch-deps
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
WORKDIR /package
COPY --link --from=fetch-pnpm /pnpm/ /pnpm/
RUN pnpm config set store-dir /.pnpm-store
COPY --link .npmrc ./
RUN --mount=type=cache,target=/.pnpm-store \
# package.json: for simple-git-hooks
--mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=pnpm-lock.yaml,target=pnpm-lock.yaml \
pnpm fetch
COPY --link package.json ./

FROM fetch-deps as dev-deps
RUN --mount=type=cache,target=/.pnpm-store \
--mount=type=bind,source=pnpm-lock.yaml,target=pnpm-lock.yaml \
pnpm install --frozen-lockfile --offline

FROM buildpack-deps:bookworm as builder
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
WORKDIR /app
RUN --mount=type=bind,from=fetch-deps,source=/pnpm/,target=/pnpm/ \
--mount=type=bind,from=dev-deps,source=/package/node_modules/,target=node_modules/ \
--mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=.npmrc,target=.npmrc \
--mount=type=bind,source=build.js,target=build.js \
--mount=type=bind,source=src/,target=src/ \
pnpm build

FROM fetch-deps as prod-deps
ARG NODE_ENV="production"
RUN --mount=type=cache,target=/.pnpm-store \
--mount=type=bind,source=pnpm-lock.yaml,target=pnpm-lock.yaml \
pnpm install --frozen-lockfile --offline

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 --from=deps /app/node_modules/ ./node_modules/
COPY --from=model-fetch /app/ ./model/
CMD ["dist/main.js"]
COPY --link --from=model-fetch /app/ ./model/
COPY --link --from=fetch-deps /pnpm/ /pnpm/
COPY --link --from=builder /app/dist/ ./dist/
COPY --from=prod-deps /package/node_modules/ ./node_modules/
COPY --link .npmrc package.json ./
ENTRYPOINT [ "pnpm", "--shell-emulator" ]
CMD [ "start" ]
7 changes: 7 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
discordbot-om:
image: discordbot-om
container_name: discordbot-om
build: .
env_file: .env
pull_policy: build
Loading

0 comments on commit a7265bd

Please sign in to comment.