From 9314ceae3657649f442179f81cb9613fe8a1ea30 Mon Sep 17 00:00:00 2001
From: Takuya Yoshida <hawaiianphoto@geekhost.net>
Date: Thu, 22 Dec 2022 14:30:35 +0900
Subject: [PATCH] Improve Dockerfile (#9105)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* Improve Dockerfile

* Update base image

* Add copy layer

* Delete unused RUN

* Update Dockerfile

Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>

Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
---
 Dockerfile | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 7a80739e2c..de9ec3e1c7 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,23 +2,35 @@ FROM node:18.12.1-bullseye AS builder
 
 ARG NODE_ENV=production
 
+RUN apt-get update \
+	&& apt-get install -y --no-install-recommends \
+	build-essential
+
 WORKDIR /misskey
 
+COPY [".yarnrc.yml", "package.json", "yarn.lock", "./"]
+COPY [".yarn", "./.yarn"]
+COPY ["scripts", "./scripts"]
+COPY ["packages/backend/package.json", "./packages/backend/"]
+COPY ["packages/client/package.json", "./packages/client/"]
+COPY ["packages/sw/package.json", "./packages/sw/"]
+
+RUN yarn install --immutable
+
 COPY . ./
 
-RUN apt-get update
-RUN apt-get install -y build-essential
 RUN git submodule update --init
-RUN yarn install --immutable
 RUN yarn build
-RUN rm -rf .git
 
 FROM node:18.12.1-bullseye-slim AS runner
 
 WORKDIR /misskey
 
-RUN apt-get update
-RUN apt-get install -y ffmpeg tini
+RUN apt-get update \
+	&& apt-get install -y --no-install-recommends \
+	ffmpeg tini \
+	&& apt-get -y clean \
+	&& rm -rf /var/lib/apt/lists/*
 
 COPY --from=builder /misskey/.yarn/install-state.gz ./.yarn/install-state.gz
 COPY --from=builder /misskey/node_modules ./node_modules
-- 
GitLab