Skip to content

Commit cce5ea0

Browse files
waleedlatif1Connor Mulholland
andcommitted
improvement(runners): added blacksmith optimizations to workflows and dockerfiles to enhance performance (#2055)
* added blacksmith optimizations to workflows and dockerfiles to enhance performance. please review before pushing to production * remove cache from and cache to directives from docker based actions, per blacksmith docs --------- Co-authored-by: Connor Mulholland <connormul@Connors-MacBook-Pro.local>
1 parent f5c211e commit cce5ea0

File tree

10 files changed

+155
-27
lines changed

10 files changed

+155
-27
lines changed

.github/workflows/docs-embeddings.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,19 @@ jobs:
2424
with:
2525
node-version: latest
2626

27+
- name: Cache Bun dependencies
28+
uses: actions/cache@v4
29+
with:
30+
path: |
31+
~/.bun/install/cache
32+
node_modules
33+
**/node_modules
34+
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
35+
restore-keys: |
36+
${{ runner.os }}-bun-
37+
2738
- name: Install dependencies
28-
run: bun install
39+
run: bun install --frozen-lockfile
2940

3041
- name: Process docs embeddings
3142
working-directory: ./apps/sim

.github/workflows/i18n.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ jobs:
2828
with:
2929
bun-version: 1.2.22
3030

31+
- name: Cache Bun dependencies
32+
uses: actions/cache@v4
33+
with:
34+
path: |
35+
~/.bun/install/cache
36+
node_modules
37+
**/node_modules
38+
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
39+
restore-keys: |
40+
${{ runner.os }}-bun-
41+
3142
- name: Run Lingo.dev translations
3243
env:
3344
LINGODOTDEV_API_KEY: ${{ secrets.LINGODOTDEV_API_KEY }}
@@ -117,10 +128,21 @@ jobs:
117128
with:
118129
bun-version: 1.2.22
119130

131+
- name: Cache Bun dependencies
132+
uses: actions/cache@v4
133+
with:
134+
path: |
135+
~/.bun/install/cache
136+
node_modules
137+
**/node_modules
138+
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
139+
restore-keys: |
140+
${{ runner.os }}-bun-
141+
120142
- name: Install dependencies
121143
run: |
122144
cd apps/docs
123-
bun install
145+
bun install --frozen-lockfile
124146
125147
- name: Build documentation to verify translations
126148
run: |

.github/workflows/migrations.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,19 @@ jobs:
1818
with:
1919
bun-version: 1.2.22
2020

21+
- name: Cache Bun dependencies
22+
uses: actions/cache@v4
23+
with:
24+
path: |
25+
~/.bun/install/cache
26+
node_modules
27+
**/node_modules
28+
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
29+
restore-keys: |
30+
${{ runner.os }}-bun-
31+
2132
- name: Install dependencies
22-
run: bun install
33+
run: bun install --frozen-lockfile
2334

2435
- name: Apply migrations
2536
working-directory: ./packages/db

.github/workflows/publish-cli.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,20 @@ jobs:
2424
node-version: '18'
2525
registry-url: 'https://registry.npmjs.org/'
2626

27+
- name: Cache Bun dependencies
28+
uses: actions/cache@v4
29+
with:
30+
path: |
31+
~/.bun/install/cache
32+
node_modules
33+
**/node_modules
34+
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
35+
restore-keys: |
36+
${{ runner.os }}-bun-
37+
2738
- name: Install dependencies
2839
working-directory: packages/cli
29-
run: bun install
40+
run: bun install --frozen-lockfile
3041

3142
- name: Build package
3243
working-directory: packages/cli

.github/workflows/publish-ts-sdk.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,19 @@ jobs:
2424
node-version: '22'
2525
registry-url: 'https://registry.npmjs.org/'
2626

27+
- name: Cache Bun dependencies
28+
uses: actions/cache@v4
29+
with:
30+
path: |
31+
~/.bun/install/cache
32+
node_modules
33+
**/node_modules
34+
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
35+
restore-keys: |
36+
${{ runner.os }}-bun-
37+
2738
- name: Install dependencies
28-
run: bun install
39+
run: bun install --frozen-lockfile
2940

3041
- name: Run tests
3142
working-directory: packages/ts-sdk

.github/workflows/test-build.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ jobs:
2323
with:
2424
node-version: latest
2525

26+
- name: Cache Bun dependencies
27+
uses: actions/cache@v4
28+
with:
29+
path: |
30+
~/.bun/install/cache
31+
node_modules
32+
**/node_modules
33+
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
34+
restore-keys: |
35+
${{ runner.os }}-bun-
36+
2637
- name: Install dependencies
2738
run: bun install --frozen-lockfile
2839

.github/workflows/trigger-deploy.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,19 @@ jobs:
2929
with:
3030
bun-version: 1.2.22
3131

32+
- name: Cache Bun dependencies
33+
uses: actions/cache@v4
34+
with:
35+
path: |
36+
~/.bun/install/cache
37+
node_modules
38+
**/node_modules
39+
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
40+
restore-keys: |
41+
${{ runner.os }}-bun-
42+
3243
- name: Install dependencies
33-
run: bun install
44+
run: bun install --frozen-lockfile
3445

3546
- name: Deploy to Trigger.dev (Staging)
3647
if: github.ref == 'refs/heads/staging'

docker/app.Dockerfile

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ FROM base AS deps
1010
RUN apk add --no-cache libc6-compat
1111
WORKDIR /app
1212

13-
# Install turbo globally
13+
# Install turbo globally (cached separately, changes infrequently)
1414
RUN bun install -g turbo
1515

1616
COPY package.json bun.lock turbo.json ./
1717
RUN mkdir -p apps packages/db
1818
COPY apps/sim/package.json ./apps/sim/package.json
1919
COPY packages/db/package.json ./packages/db/package.json
2020

21+
# Install dependencies (this layer will be cached if package files don't change)
2122
RUN bun install --omit dev --ignore-scripts
2223

2324
# ========================================
@@ -26,14 +27,26 @@ RUN bun install --omit dev --ignore-scripts
2627
FROM base AS builder
2728
WORKDIR /app
2829

29-
# Install turbo globally in builder stage
30+
# Install turbo globally (cached separately, changes infrequently)
3031
RUN bun install -g turbo
3132

33+
# Copy node_modules from deps stage (cached if dependencies don't change)
3234
COPY --from=deps /app/node_modules ./node_modules
33-
COPY . .
3435

35-
# Installing with full context to prevent missing dependencies error
36-
RUN bun install --omit dev --ignore-scripts
36+
# Copy package configuration files (needed for build)
37+
COPY package.json bun.lock turbo.json ./
38+
COPY apps/sim/package.json ./apps/sim/package.json
39+
COPY packages/db/package.json ./packages/db/package.json
40+
41+
# Copy workspace configuration files (needed for turbo)
42+
COPY apps/sim/next.config.ts ./apps/sim/next.config.ts
43+
COPY apps/sim/tsconfig.json ./apps/sim/tsconfig.json
44+
COPY apps/sim/tailwind.config.ts ./apps/sim/tailwind.config.ts
45+
COPY apps/sim/postcss.config.mjs ./apps/sim/postcss.config.mjs
46+
47+
# Copy source code (changes most frequently - placed last to maximize cache hits)
48+
COPY apps/sim ./apps/sim
49+
COPY packages ./packages
3750

3851
# Required for standalone nextjs build
3952
WORKDIR /app/apps/sim
@@ -64,15 +77,16 @@ RUN bun run build
6477
FROM base AS runner
6578
WORKDIR /app
6679

67-
# Install Python and dependencies for guardrails PII detection
80+
# Install Python and dependencies for guardrails PII detection (cached separately)
6881
RUN apk add --no-cache python3 py3-pip bash
6982

7083
ENV NODE_ENV=production
7184

72-
# Create non-root user and group
85+
# Create non-root user and group (cached separately)
7386
RUN addgroup -g 1001 -S nodejs && \
7487
adduser -S nextjs -u 1001
7588

89+
# Copy application artifacts from builder (these change on every build)
7690
COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/public ./apps/sim/public
7791
COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/.next/standalone ./
7892
COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/.next/static ./apps/sim/.next/static

docker/db.Dockerfile

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
1+
# ========================================
2+
# Base Stage: Alpine Linux with Bun
3+
# ========================================
4+
FROM oven/bun:1.2.22-alpine AS base
5+
16
# ========================================
27
# Dependencies Stage: Install Dependencies
38
# ========================================
4-
FROM oven/bun:1.2.22-alpine AS deps
9+
FROM base AS deps
510
WORKDIR /app
611

7-
# Copy only package files needed for migrations
12+
# Copy only package files needed for migrations (these change less frequently)
813
COPY package.json bun.lock turbo.json ./
14+
RUN mkdir -p packages/db
915
COPY packages/db/package.json ./packages/db/package.json
1016

11-
# Install dependencies
17+
# Install dependencies (this layer will be cached if package files don't change)
1218
RUN bun install --ignore-scripts
1319

1420
# ========================================
1521
# Runner Stage: Production Environment
1622
# ========================================
17-
FROM oven/bun:1.2.22-alpine AS runner
23+
FROM base AS runner
1824
WORKDIR /app
1925

20-
# Create non-root user and group
26+
# Create non-root user and group (cached separately)
2127
RUN addgroup -g 1001 -S nodejs && \
2228
adduser -S nextjs -u 1001
2329

24-
# Copy only the necessary files from deps
30+
# Copy only the necessary files from deps (cached if dependencies don't change)
2531
COPY --from=deps --chown=nextjs:nodejs /app/node_modules ./node_modules
32+
33+
# Copy package configuration files (needed for migrations)
2634
COPY --chown=nextjs:nodejs packages/db/drizzle.config.ts ./packages/db/drizzle.config.ts
35+
36+
# Copy database package source code (changes most frequently - placed last)
2737
COPY --chown=nextjs:nodejs packages/db ./packages/db
2838

2939
# Switch to non-root user

docker/realtime.Dockerfile

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,34 @@ FROM base AS deps
1010
RUN apk add --no-cache libc6-compat
1111
WORKDIR /app
1212

13-
# Install turbo globally
13+
# Install turbo globally (cached separately, changes infrequently)
1414
RUN bun install -g turbo
1515

1616
COPY package.json bun.lock turbo.json ./
1717
RUN mkdir -p apps packages/db
1818
COPY apps/sim/package.json ./apps/sim/package.json
1919
COPY packages/db/package.json ./packages/db/package.json
2020

21+
# Install dependencies (this layer will be cached if package files don't change)
2122
RUN bun install --omit dev --ignore-scripts
2223

2324
# ========================================
24-
# Builder Stage: Build the Application
25+
# Builder Stage: Prepare source code
2526
# ========================================
2627
FROM base AS builder
2728
WORKDIR /app
2829

30+
# Copy node_modules from deps stage (cached if dependencies don't change)
2931
COPY --from=deps /app/node_modules ./node_modules
30-
COPY . .
32+
33+
# Copy package configuration files (needed for build)
34+
COPY package.json bun.lock turbo.json ./
35+
COPY apps/sim/package.json ./apps/sim/package.json
36+
COPY packages/db/package.json ./packages/db/package.json
37+
38+
# Copy source code (changes most frequently - placed last to maximize cache hits)
39+
COPY apps/sim ./apps/sim
40+
COPY packages ./packages
3141

3242
# ========================================
3343
# Runner Stage: Run the Socket Server
@@ -37,16 +47,22 @@ WORKDIR /app
3747

3848
ENV NODE_ENV=production
3949

40-
# Create non-root user and group
50+
# Create non-root user and group (cached separately)
4151
RUN addgroup -g 1001 -S nodejs && \
4252
adduser -S nextjs -u 1001
4353

44-
# Copy the sim app and the shared db package needed by socket-server
45-
COPY --from=builder --chown=nextjs:nodejs /app/apps/sim ./apps/sim
46-
COPY --from=builder --chown=nextjs:nodejs /app/packages/db ./packages/db
47-
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
54+
# Copy package.json first (changes less frequently)
4855
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json
4956

57+
# Copy node_modules from builder (cached if dependencies don't change)
58+
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
59+
60+
# Copy db package (needed by socket-server)
61+
COPY --from=builder --chown=nextjs:nodejs /app/packages/db ./packages/db
62+
63+
# Copy sim app (changes most frequently - placed last)
64+
COPY --from=builder --chown=nextjs:nodejs /app/apps/sim ./apps/sim
65+
5066
# Switch to non-root user
5167
USER nextjs
5268

0 commit comments

Comments
 (0)