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

change!(build): Corepackを削除, Dockerfileの改修 #327

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM mcr.microsoft.com/devcontainers/javascript-node:0-18
FROM mcr.microsoft.com/devcontainers/javascript-node:22-bookworm

RUN curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash -s -- -b /usr/local/bin
4 changes: 3 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"ghcr.io/devcontainers/features/node:1": {
"version": "22.11.0"
},
"ghcr.io/devcontainers-contrib/features/corepack:1": {},
"ghcr.io/devcontainers-extra/features/pnpm:2": {
"version": "9.6.0"
}
},
"forwardPorts": [3000],
"postCreateCommand": "/bin/bash .devcontainer/init.sh",
Expand Down
2 changes: 0 additions & 2 deletions .devcontainer/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ sudo apt-get update
sudo apt-get -y install libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libnss3 libxss1 libasound2 libxtst6 xauth xvfb
git config --global --add safe.directory /workspace
git submodule update --init
corepack install
corepack enable
pnpm config set store-dir /home/node/.local/share/pnpm/store
pnpm install --frozen-lockfile
cp .devcontainer/devcontainer.yml .config/default.yml
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/check-misskey-js-autogen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ jobs:
fetch-depth: 1
submodules: true

- name: Enable corepack
run: |
corepack enable
- name: Setup pnpm
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
run_install: false

- name: Setup Node.js
uses: actions/[email protected]
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/lint-locales.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ jobs:
ref: ${{ needs.pre-checkout.outputs.sha }}
fetch-depth: 1

- name: Enable corepack
run: |
corepack enable
- name: Setup pnpm
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
run_install: false

- name: Setup Node.js
uses: actions/[email protected]
Expand Down Expand Up @@ -71,9 +72,10 @@ jobs:
ref: ${{ needs.pre-checkout.outputs.sha }}
fetch-depth: 1

- name: Enable corepack
run: |
corepack enable
- name: Setup pnpm
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
run_install: false

- name: Setup Node.js
uses: actions/[email protected]
Expand Down
21 changes: 12 additions & 9 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ jobs:
fetch-depth: 1
submodules: true

- name: Enable corepack
run: |
corepack enable
- name: Setup pnpm
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
run_install: false

- name: Setup Node.js
uses: actions/[email protected]
Expand Down Expand Up @@ -82,9 +83,10 @@ jobs:
fetch-depth: 1
submodules: true

- name: Enable corepack
run: |
corepack enable
- name: Setup pnpm
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
run_install: false

- name: Setup Node.js
uses: actions/[email protected]
Expand Down Expand Up @@ -129,9 +131,10 @@ jobs:
fetch-depth: 1
submodules: true

- name: Enable corepack
run: |
corepack enable
- name: Setup pnpm
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
run_install: false

- name: Setup Node.js
uses: actions/[email protected]
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/test-backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ jobs:
fetch-depth: 1
submodules: true

- name: Enable corepack
run: |
corepack enable
- name: Setup pnpm
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
run_install: false

- name: Setup Node.js
uses: actions/[email protected]
Expand Down Expand Up @@ -119,9 +120,10 @@ jobs:
fetch-depth: 1
submodules: true

- name: Enable corepack
run: |
corepack enable
- name: Setup pnpm
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
run_install: false

- name: Setup Node.js
uses: actions/[email protected]
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/test-federation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ jobs:
fetch-depth: 1
submodules: true

- name: Enable corepack
run: |
corepack enable
- name: Setup pnpm
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
run_install: false

- name: Setup Node.js
uses: actions/[email protected]
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/test-frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ jobs:
fetch-depth: 1
submodules: true

- name: Enable corepack
run: |
corepack enable
- name: Setup pnpm
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
run_install: false

- name: Setup Node.js
uses: actions/[email protected]
Expand Down Expand Up @@ -122,9 +123,10 @@ jobs:
# - uses: browser-actions/setup-firefox@955a5d42b5f068a8917c6a4ff1656a2235c66dfb # v1.5.2
# if: ${{ matrix.browser == 'firefox' }}

- name: Enable corepack
run: |
corepack enable
- name: Setup pnpm
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
run_install: false

- name: Setup Node.js
uses: actions/[email protected]
Expand Down
135 changes: 79 additions & 56 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,72 @@
# syntax = docker/dockerfile:1.4
# syntax=docker/dockerfile:1

ARG NODE_VERSION=22.11.0-bookworm


# download submodules
# [native-base]: setup pnpm, fetch dependencies

FROM --platform=$BUILDPLATFORM node:${NODE_VERSION} AS submodule
FROM --platform=$BUILDPLATFORM node:${NODE_VERSION}-slim AS native-base

WORKDIR /misskey

COPY ./.git/ ./.git/
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean && \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache && \
apt-get update && apt-get install -yqq --no-install-recommends \
build-essential \
git

RUN git submodule update --init --recursive
COPY --link ./patches/ ./patches/
COPY --link ./.npmrc ./.node-version ./
COPY --link ./pnpm-lock.yaml ./

RUN npm install -g [email protected]

# build assets & compile TypeScript
RUN --mount=type=cache,target=/.pnpm-store,sharing=locked \
pnpm config set -g store-dir /.pnpm-store && \
pnpm fetch --ignore-scripts

FROM --platform=$BUILDPLATFORM node:${NODE_VERSION} AS native-builder

ENV NODE_ENV=production
# [target-base]: setup pnpm, fetch dependencies

FROM --platform=$TARGETPLATFORM node:${NODE_VERSION}-slim AS target-base

WORKDIR /misskey

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean && \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache && \
apt-get update && \
apt-get install -yqq --no-install-recommends \
build-essential

RUN corepack enable
apt-get update && apt-get install -yqq --no-install-recommends \
build-essential \
git

COPY --link ./patches/ ./patches/
COPY --link ./.npmrc ./.node-version ./
COPY --link ./pnpm-lock.yaml ./

RUN npm install -g [email protected]

RUN --mount=type=cache,target=/.pnpm-store,sharing=locked \
pnpm config set -g store-dir /.pnpm-store && \
pnpm fetch --ignore-scripts


# [native-submodule]: init git submodules

FROM native-base AS native-submodule

COPY --link ./.gitmodules ./
COPY --link ./.git/ ./.git/

RUN git submodule update --init --recursive


# [native-builder]: install dependencies, build

FROM native-base AS native-builder

COPY --link ./packages/sw/package.json ./packages/sw/
COPY --link ./packages/misskey-bubble-game/package.json ./packages/misskey-bubble-game/
COPY --link ./packages/misskey-reversi/package.json ./packages/misskey-reversi/
Expand All @@ -41,10 +75,10 @@ COPY --link ./packages/backend/package.json ./packages/backend/
COPY --link ./packages/frontend-shared/package.json ./packages/frontend-shared/
COPY --link ./packages/frontend/package.json ./packages/frontend/
COPY --link ./packages/frontend-embed/package.json ./packages/frontend-embed/
COPY --link ./pnpm-lock.yaml ./pnpm-workspace.yaml ./package.json ./
COPY --link ./pnpm-workspace.yaml ./package.json ./

RUN --mount=type=cache,target=/root/.local/share/pnpm/store,sharing=locked \
pnpm i --frozen-lockfile --aggregate-output
RUN pnpm install --frozen-lockfile --aggregate-output --offline && \
pnpm rebuild --recursive --aggregate-output

COPY --link ./scripts/ ./scripts/
COPY --link ./packages/sw/build.js ./packages/sw/tsconfig.json ./packages/sw/
Expand Down Expand Up @@ -74,74 +108,61 @@ COPY --link ./packages/frontend/.storybook/.gitignore ./packages/frontend/.story
COPY --link ./packages/frontend/.gitignore ./packages/frontend/
COPY --link ./packages/frontend-embed/.gitignore ./packages/frontend-embed/
COPY --link ./.gitignore ./
COPY --link --from=native-submodule /misskey/fluent-emojis/ ./fluent-emojis/
COPY --link ./.git/ ./.git/
COPY --link --from=submodule /misskey/fluent-emojis/ ./fluent-emojis/

RUN pnpm build

RUN NODE_ENV=production pnpm build

# build native dependencies for target platform

FROM --platform=$TARGETPLATFORM node:${NODE_VERSION} AS target-builder

ENV NODE_ENV=production

RUN apt-get update && \
apt-get install -yqq --no-install-recommends \
build-essential

RUN corepack enable
# [target-builder]: install dependencies

WORKDIR /misskey
FROM target-base AS target-builder

COPY --link ./patches/ ./patches/
COPY --link ./scripts/ ./scripts/
COPY --link ./packages/misskey-bubble-game/package.json ./packages/misskey-bubble-game/
COPY --link ./packages/misskey-reversi/package.json ./packages/misskey-reversi/
COPY --link ./packages/misskey-js/package.json ./packages/misskey-js/
COPY --link ./packages/backend/package.json ./packages/backend/
COPY --link ./pnpm-lock.yaml ./pnpm-workspace.yaml ./package.json ./
COPY --link ./pnpm-workspace.yaml ./package.json ./

RUN --mount=type=cache,target=/root/.local/share/pnpm/store,sharing=locked \
pnpm i --frozen-lockfile --aggregate-output
RUN pnpm install --frozen-lockfile --aggregate-output --offline && \
pnpm rebuild --recursive --aggregate-output


# build final image
# [runner]: build final image

FROM --platform=$TARGETPLATFORM node:${NODE_VERSION}-slim AS runner

WORKDIR /misskey

ARG UID="991"
ARG GID="991"

RUN apt-get update && \
apt-get install -y --no-install-recommends \
RUN apt-get update && apt-get install -yqq --no-install-recommends \
ffmpeg tini curl libjemalloc-dev libjemalloc2 && \
ln -s /usr/lib/$(uname -m)-linux-gnu/libjemalloc.so.2 /usr/local/lib/libjemalloc.so && \
corepack enable && \
groupadd -g "${GID}" misskey && \
useradd -l -u "${UID}" -g "${GID}" -m -d /misskey misskey && \
find / -type d -path /sys -prune -o -type d -path /proc -prune -o -type f -perm /u+s -ignore_readdir_race -exec chmod u-s {} \; && \
find / -type d -path /sys -prune -o -type d -path /proc -prune -o -type f -perm /g+s -ignore_readdir_race -exec chmod g-s {} \; && \
apt-get clean && \
rm -rf /var/lib/apt/lists

USER misskey
WORKDIR /misskey

COPY --chown=misskey:misskey ./packages/sw/package.json ./packages/sw/
COPY --chown=misskey:misskey ./packages/misskey-bubble-game/package.json ./packages/misskey-bubble-game/
COPY --chown=misskey:misskey ./packages/misskey-reversi/package.json ./packages/misskey-reversi/
COPY --chown=misskey:misskey ./packages/misskey-js/package.json ./packages/misskey-js/
COPY --chown=misskey:misskey ./packages/backend/package.json ./packages/backend/ormconfig.js ./packages/backend/
COPY --chown=misskey:misskey ./packages/backend/assets/ ./packages/backend/assets/
COPY --chown=misskey:misskey ./packages/backend/scripts/ ./packages/backend/scripts/
COPY --chown=misskey:misskey ./packages/backend/nsfw-model/ ./packages/backend/nsfw-model/
COPY --chown=misskey:misskey ./packages/backend/migration/ ./packages/backend/migration/
COPY --chown=misskey:misskey ./packages/frontend/assets/ ./packages/frontend/assets/
COPY --chown=misskey:misskey ./packages/frontend-embed/assets/ ./packages/frontend-embed/assets/
COPY --chown=misskey:misskey ./.node-version ./package.json ./pnpm-workspace.yaml ./
COPY --chown=misskey:misskey ./healthcheck.sh ./
COPY --chown=misskey:misskey --from=submodule /misskey/fluent-emojis/ ./fluent-emojis/
COPY --chown=misskey:misskey --link ./packages/sw/package.json ./packages/sw/
COPY --chown=misskey:misskey --link ./packages/misskey-bubble-game/package.json ./packages/misskey-bubble-game/
COPY --chown=misskey:misskey --link ./packages/misskey-reversi/package.json ./packages/misskey-reversi/
COPY --chown=misskey:misskey --link ./packages/misskey-js/package.json ./packages/misskey-js/
COPY --chown=misskey:misskey --link ./packages/backend/package.json ./packages/backend/ormconfig.js ./packages/backend/
COPY --chown=misskey:misskey --link ./packages/backend/assets/ ./packages/backend/assets/
COPY --chown=misskey:misskey --link ./packages/backend/scripts/ ./packages/backend/scripts/
COPY --chown=misskey:misskey --link ./packages/backend/nsfw-model/ ./packages/backend/nsfw-model/
COPY --chown=misskey:misskey --link ./packages/backend/migration/ ./packages/backend/migration/
COPY --chown=misskey:misskey --link ./packages/frontend/assets/ ./packages/frontend/assets/
COPY --chown=misskey:misskey --link ./packages/frontend-embed/assets/ ./packages/frontend-embed/assets/
COPY --chown=misskey:misskey --link ./.npmrc ./.node-version ./
COPY --chown=misskey:misskey --link ./pnpm-workspace.yaml ./package.json ./
COPY --chown=misskey:misskey --link ./healthcheck.sh ./
COPY --chown=misskey:misskey --link --from=native-submodule /misskey/fluent-emojis/ ./fluent-emojis/
COPY --chown=misskey:misskey --from=native-builder /misskey/packages/misskey-bubble-game/built/ ./packages/misskey-bubble-game/built/
COPY --chown=misskey:misskey --from=native-builder /misskey/packages/misskey-reversi/built/ ./packages/misskey-reversi/built/
COPY --chown=misskey:misskey --from=native-builder /misskey/packages/misskey-js/built/ ./packages/misskey-js/built/
Expand All @@ -153,7 +174,9 @@ COPY --chown=misskey:misskey --from=target-builder /misskey/packages/misskey-js/
COPY --chown=misskey:misskey --from=target-builder /misskey/packages/backend/node_modules/ ./packages/backend/node_modules/
COPY --chown=misskey:misskey --from=target-builder /misskey/node_modules/ ./node_modules/

RUN corepack install
RUN npm install -g [email protected]

USER misskey

ENV LD_PRELOAD=/usr/local/lib/libjemalloc.so
ENV NODE_ENV=production
Expand Down
Loading
Loading