Skip to content

Commit f5201be

Browse files
committed
fix: optimize Raspberry Pi deployment with parallel builds and build caching
1 parent 21a836f commit f5201be

4 files changed

Lines changed: 64 additions & 24 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ jobs:
2121
host: ${{ secrets.HOST }}
2222
username: ${{ secrets.USERNAME }}
2323
password: ${{ secrets.PASSWORD }}
24+
timeout: 30m
2425
script_stop: true
2526
script: |
2627
cd /home/ericpark/Desktop/apps/bookmarket
2728
git pull origin main
2829
docker compose down
29-
docker compose up -d --build
30+
docker compose build --parallel
31+
docker compose up -d

apps/server/Dockerfile

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,46 @@
1-
FROM node:20
1+
FROM node:20 AS base
22

33
# Set up PNPM
44
ENV PNPM_HOME="/pnpm"
55
ENV PATH="$PNPM_HOME:$PATH"
66
RUN corepack enable
77

8-
# Set the working directory
8+
# Set working directory
99
WORKDIR /app
1010

1111
# Copy root configuration files
1212
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml turbo.json ./
1313

14-
# Copy shared packages source code
15-
# Assuming shared packages are in 'packages/' relative to the root
16-
COPY packages packages
14+
# Install dependencies (cached layer)
15+
RUN pnpm install --frozen-lockfile
1716

18-
# Copy the server app source code
17+
# Copy source code
18+
COPY packages packages
1919
COPY apps/server apps/server
2020

21-
# Install only the server dependencies and its workspace dependencies
22-
RUN pnpm install
23-
2421
# Build the server app
2522
RUN pnpm run build
2623

27-
# Change working directory to the server app's directory
24+
# Production stage
25+
FROM node:20-alpine AS production
26+
27+
# Set up PNPM
28+
ENV PNPM_HOME="/pnpm"
29+
ENV PATH="$PNPM_HOME:$PATH"
30+
RUN corepack enable
31+
32+
WORKDIR /app
33+
34+
# Copy from base stage
35+
COPY --from=base /app/package.json /app/pnpm-lock.yaml /app/pnpm-workspace.yaml /app/turbo.json ./
36+
COPY --from=base /app/node_modules ./node_modules
37+
COPY --from=base /app/packages ./packages
38+
COPY --from=base /app/apps/server/dist ./apps/server/dist
39+
COPY --from=base /app/apps/server/package.json ./apps/server/
40+
2841
WORKDIR /app/apps/server
2942

30-
# Expose the port and define the entry point
43+
# Expose port and define entry point
3144
EXPOSE 8000
3245

3346
ENTRYPOINT ["pnpm", "run", "start"]

apps/web/Dockerfile

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,48 @@
1-
FROM node:20
1+
FROM node:20 AS base
22

33
# Set up PNPM
44
ENV PNPM_HOME="/pnpm"
55
ENV PATH="$PNPM_HOME:$PATH"
66
RUN corepack enable
77

8-
# Set the working directory
98
WORKDIR /app
109

1110
# Copy root configuration files
1211
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml turbo.json ./
1312

14-
# Copy shared packages source code
15-
# Assuming shared packages are in 'packages/' relative to the root
16-
COPY packages packages
13+
# Install dependencies (cached layer)
14+
RUN pnpm install --frozen-lockfile
1715

18-
# Copy the server app source code
16+
# Copy source code
17+
COPY packages packages
1918
COPY apps/web apps/web
2019

21-
# Install only the server dependencies and its workspace dependencies
22-
RUN pnpm install
23-
24-
# Build the server app
20+
# Build the web app
2521
RUN pnpm run build
2622

27-
# Change working directory to the server app's directory
23+
# Production stage
24+
FROM node:20-alpine AS production
25+
26+
# Set up PNPM
27+
ENV PNPM_HOME="/pnpm"
28+
ENV PATH="$PNPM_HOME:$PATH"
29+
RUN corepack enable
30+
31+
WORKDIR /app
32+
33+
# Copy from base stage
34+
COPY --from=base /app/package.json /app/pnpm-lock.yaml /app/pnpm-workspace.yaml /app/turbo.json ./
35+
COPY --from=base /app/node_modules ./node_modules
36+
COPY --from=base /app/packages ./packages
37+
COPY --from=base /app/apps/web/.next ./apps/web/.next
38+
COPY --from=base /app/apps/web/public ./apps/web/public
39+
COPY --from=base /app/apps/web/package.json ./apps/web/
40+
2841
WORKDIR /app/apps/web
2942

30-
# Expose the port and define the entry point
43+
# Expose port
3144
EXPOSE 3000
3245

46+
ENV NODE_ENV=production
47+
3348
ENTRYPOINT ["pnpm", "run", "start"]

docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ services:
1717
build:
1818
context: .
1919
dockerfile: apps/server/Dockerfile
20+
cache_from:
21+
- bookmarket-server:latest
22+
cache_to:
23+
- type=local,dest=/tmp/.buildx-cache,mode=max
24+
image: bookmarket-server:latest
2025
ports:
2126
- 8000:8000
2227
depends_on:
@@ -27,6 +32,11 @@ services:
2732
build:
2833
context: .
2934
dockerfile: apps/web/Dockerfile
35+
cache_from:
36+
- bookmarket-web:latest
37+
cache_to:
38+
- type=local,dest=/tmp/.buildx-cache,mode=max
39+
image: bookmarket-web:latest
3040
ports:
3141
- 5000:3000
3242
depends_on:

0 commit comments

Comments
 (0)