From ea6816323e567acb4e3bbbba3172e82eea12e5bd Mon Sep 17 00:00:00 2001 From: suhjae Date: Tue, 3 Sep 2024 09:39:00 +0900 Subject: [PATCH] fix: deploy --- .github/workflows/deploy.yml | 1 - Dockerfile | 47 ++++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index cb0d4db..b49ea3d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -28,7 +28,6 @@ jobs: git pull origin main sudo docker stop ${{ secrets.APP_NAME }} || true sudo docker rm ${{ secrets.APP_NAME }} || true - sudo docker system prune -f sudo docker build -t ${{ secrets.APP_NAME }} . sudo docker compose up -d ENDSSH diff --git a/Dockerfile b/Dockerfile index 433018b..13b44aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,44 @@ ARG NODE_VERSION=22.5.1 -FROM node:${NODE_VERSION}-slim AS base +# Create build stage +FROM node:${NODE_VERSION}-slim AS build -ARG PORT=3000 +# Enable pnpm +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" +RUN corepack enable -ENV NODE_ENV=production +# Set the working directory inside the container +WORKDIR /app + +# Copy package.json and pnpm-lock.yaml files to the working directory +COPY ./package.json /app/ +COPY ./pnpm-lock.yaml /app/ -WORKDIR /src +## Install dependencies +RUN pnpm install --shamefully-hoist -# Build -FROM base AS build +# Copy the rest of the application files to the working directory +COPY . ./ -COPY --link package.json package-lock.json ./ -RUN npm install --omit=dev +# Build the application +RUN pnpm run build -COPY --link . . +# Create a new stage for the production image +FROM node:${NODE_VERSION}-slim -RUN npm run build -RUN npm prune --production +# Set the working directory inside the container +WORKDIR /app -# Run -FROM base +# Copy the output from the build stage to the working directory +COPY --from=build /app/.output ./ -ENV PORT=$PORT +# Define environment variables +ENV HOST=0.0.0.0 NODE_ENV=production +ENV NODE_ENV=production -COPY --from=build /src/.output /src/.output +# Expose the port the application will run on +EXPOSE 3000 -CMD [ "node", ".output/server/index.mjs" ] +# Start the application +CMD ["node","/app/server/index.mjs"]