Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use cache for building docker #180

Merged
merged 5 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ jobs:

- name: Build and push multi-arch
if: ${{ github.event_name != 'pull_request' }}
timeout-minutes: 20
uses: docker/build-push-action@v5
with:
context: .
Expand Down
21 changes: 12 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=20.11.1
FROM node:${NODE_VERSION}-slim as base
FROM node:20.11.1-slim as base

# Next.js app lives here
WORKDIR /app
Expand All @@ -17,22 +16,27 @@ RUN npm install -g yarn@$YARN_VERSION --force
FROM base as build

# Install packages needed to build node modules
RUN apt-get update -qq && \
RUN --mount=type=cache,target=/var/cache/apt \
apt-get update -qq

RUN --mount=type=cache,target=/var/cache/apt \
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3

# Install node modules
COPY --link package.json yarn.lock ./
RUN yarn install --frozen-lockfile --production=false
RUN --mount=type=cache,target=/root/.cache/yarn \
yarn install --frozen-lockfile --production=false --network-timeout 1000000

# Copy application code
COPY --link . .

# Build application
RUN yarn run build
RUN --mount=type=cache,target=/root/.cache/yarn \
yarn run build

# Remove development dependencies
RUN yarn install --production=true

RUN --mount=type=cache,target=/root/.cache/yarn \
yarn install --production=true --network-timeout 1000000

# Final stage for app image
FROM base
Expand All @@ -42,7 +46,7 @@ ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

# Copy built application
# Copy built application from the previous stage
COPY --from=build /app /app

RUN chown -R nextjs:nodejs /app
Expand All @@ -52,5 +56,4 @@ EXPOSE 3000

USER nextjs


CMD [ "node", "server.js" ]
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.PHONY: all
all: docker-build

.PHONY: docker-build
docker-build:
docker build -f Dockerfile -t saasbuilder .
Loading