From 2d64815c12b88bbb6687dbddb163568e17a38e87 Mon Sep 17 00:00:00 2001 From: Krzysztof Durek <21038648+kdurek@users.noreply.github.com> Date: Tue, 16 Jul 2024 12:05:27 +0200 Subject: [PATCH 1/2] fix: disable husky only on production --- .github/workflows/pull-request.yml | 2 ++ .husky/install.mjs | 6 ++++++ Dockerfile | 8 +++++++- package.json | 3 ++- 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .husky/install.mjs diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 278059732..5f8130bb6 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -9,6 +9,8 @@ on: branches: - main - canary +env: + HUSKY: 0 jobs: build-app: if: github.event_name == 'pull_request' diff --git a/.husky/install.mjs b/.husky/install.mjs new file mode 100644 index 000000000..9b13ce1f9 --- /dev/null +++ b/.husky/install.mjs @@ -0,0 +1,6 @@ +// Skip Husky install in production and CI +if (process.env.NODE_ENV === "production" || process.env.CI === "true") { + process.exit(0); +} +const husky = (await import("husky")).default; +console.log(husky()); diff --git a/Dockerfile b/Dockerfile index 6d3e58758..11b66bde4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,9 @@ # Etapa 1: Prepare image for building FROM node:18-slim AS base +# Disable husky +ENV HUSKY=0 + # Install dependencies ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" @@ -23,6 +26,9 @@ RUN pnpm run build # Stage 2: Prepare image for production FROM node:18-slim AS production +# Disable husky +ENV HUSKY=0 + # Install dependencies only for production ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" @@ -61,4 +67,4 @@ RUN curl -sSL "https://github.com/buildpacks/pack/releases/download/v0.32.1/pack # Expose port EXPOSE 3000 -CMD ["pnpm", "start"] \ No newline at end of file +CMD ["pnpm", "start"] diff --git a/package.json b/package.json index 354d85afe..8d55f9478 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "docker:build:canary": "./docker/build.sh canary", "docker:push:canary": "./docker/push.sh canary", "version": "echo $(node -p \"require('./package.json').version\")", - "test": "vitest --config __test__/vitest.config.ts" + "test": "vitest --config __test__/vitest.config.ts", + "prepare": "node .husky/install.mjs" }, "dependencies": { "@aws-sdk/client-s3": "3.515.0", From e249e878f6c8bcfca7c368de4af8847e7ad1b81b Mon Sep 17 00:00:00 2001 From: Krzysztof Durek <21038648+kdurek@users.noreply.github.com> Date: Tue, 16 Jul 2024 14:11:44 +0200 Subject: [PATCH 2/2] fix: disable husky only on production --- Dockerfile | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 11b66bde4..2b2a1ca80 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,6 @@ # Etapa 1: Prepare image for building FROM node:18-slim AS base -# Disable husky -ENV HUSKY=0 - # Install dependencies ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" @@ -11,6 +8,10 @@ RUN corepack enable && apt-get update && apt-get install -y python3 make g++ git WORKDIR /app +# Disable husky +ENV HUSKY=0 +COPY .husky/install.mjs ./.husky/install.mjs + # Copy package.json and pnpm-lock.yaml COPY package.json pnpm-lock.yaml ./ @@ -36,6 +37,12 @@ RUN corepack enable && apt-get update && apt-get install -y curl && apt-get inst WORKDIR /app +ENV NODE_ENV production + +# Disable husky +ENV HUSKY=0 +COPY --from=base /app/.husky/install.mjs ./.husky/install.mjs + # Copy the rest of the source code COPY --from=base /app/.next ./.next COPY --from=base /app/dist ./dist