Skip to content

Commit

Permalink
Merge pull request Dokploy#226 from kdurek/fix/husky-on-prod
Browse files Browse the repository at this point in the history
fix: disable husky only on production
  • Loading branch information
Siumauricio authored Jul 17, 2024
2 parents c0587b9 + e249e87 commit 8f1c1e5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
branches:
- main
- canary
env:
HUSKY: 0
jobs:
build-app:
if: github.event_name == 'pull_request'
Expand Down
6 changes: 6 additions & 0 deletions .husky/install.mjs
Original file line number Diff line number Diff line change
@@ -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());
15 changes: 14 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,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 ./

Expand All @@ -23,13 +27,22 @@ 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"
RUN corepack enable && apt-get update && apt-get install -y curl && apt-get install -y apache2-utils && rm -rf /var/lib/apt/lists/*

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
Expand Down Expand Up @@ -61,4 +74,4 @@ RUN curl -sSL "https://github.com/buildpacks/pack/releases/download/v0.32.1/pack
# Expose port
EXPOSE 3000

CMD ["pnpm", "start"]
CMD ["pnpm", "start"]
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 8f1c1e5

Please sign in to comment.