Skip to content

Commit

Permalink
Build/dockerize web app (#576)
Browse files Browse the repository at this point in the history
Signed-off-by: Giovanni Ravalico <[email protected]>
  • Loading branch information
suddenlyGiovanni authored Mar 5, 2024
1 parent 43b1e79 commit 235803f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.idea/
.git/
.github/
node_modules/
.DS_Store
.dockerignore
docker-compose.yml
Dockerfile
.github/
2 changes: 1 addition & 1 deletion .github/workflows/deply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
uses: superfly/flyctl-actions/setup-flyctl@master

- name: 🚀Deploy to Production
run: flyctl deploy . --config ./apps/web/fly.toml --dockerfile ./apps/web/Dockerfile --remote-only
run: flyctl deploy . --config ./apps/web/fly.toml --dockerfile ./apps/web/Dockerfile --build-target production --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
50 changes: 27 additions & 23 deletions apps/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,56 +1,60 @@
# base node image
FROM node:21-alpine3.19@sha256:d3271e4bd89eec4d97087060fd4db0c238d9d22fcfad090a73fa9b5128699888 AS base
FROM node:21-alpine3.19 AS base

LABEL authors="suddenlyGiovanni"

# set for base and all layer that inherit from it
ENV PNPM_HOME="/pnpm"

ENV PATH="$PNPM_HOME:$PATH"

RUN apk add --no-cache libc6-compat
RUN corepack enable

RUN apk update
WORKDIR /home/node/

RUN corepack enable
FROM base AS builder

COPY . /app
WORKDIR /home/node/builder

WORKDIR /app
RUN pnpm add --global turbo

#ENTRYPOINT ["sh"]
COPY . .

RUN turbo prune --docker @suddenly-giovanni/web

FROM base AS prod-deps
ENTRYPOINT ["sh"]

RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
FROM base AS build

#ENTRYPOINT ["sh"]
WORKDIR /home/node/build

COPY .gitignore .gitignore

FROM base AS build
COPY --from=builder /home/node/builder/out/json/ .

RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --prod=false

# Build the project
COPY --from=builder /home/node/builder/out/full/ .

ENV NODE_ENV production

RUN pnpm run build
RUN pnpm turbo build --filter=@suddenly-giovanni/web

#ENTRYPOINT ["sh"]
RUN pnpm --filter @suddenly-giovanni/web --prod deploy pruned


FROM base AS runner
FROM base AS production

ENV NODE_ENV production

COPY --from=prod-deps /app/node_modules /app/node_modules
COPY --from=prod-deps /app/apps/web/node_modules /app/apps/web/node_modules
COPY --from=build /app/apps/web/build /app/apps/web/build
WORKDIR /home/node/code

RUN apk add --no-cache dumb-init

COPY --from=build --chown=node:node /home/node/build/pruned .
COPY --from=build --chown=node:node /home/node/build/apps/web/build ./build

USER node

EXPOSE 3000

WORKDIR /app/apps/web

CMD ["pnpm", "run", "start"]
CMD ["dumb-init", "pnpm", "run", "start"]
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
build:
context: .
dockerfile: apps/web/Dockerfile
target: runner
target: production
ports:
- "3000:3000"
init: true

0 comments on commit 235803f

Please sign in to comment.