Skip to content

Commit

Permalink
build: try bun (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregkonush authored Dec 1, 2024
1 parent df50de3 commit 65493d6
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 67 deletions.
60 changes: 51 additions & 9 deletions .github/workflows/docker-build-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,57 @@ jobs:

build-ecran:
needs: [version, build-ecran-migrator]
uses: ./.github/workflows/docker-build-common.yaml
with:
image_name: ecran
dockerfile: ./services/ecran/Dockerfile
context: ./services/ecran
new_tag: ${{ needs.version.outputs.new_tag }}
secrets:
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
runs-on: arc-arm64
defaults:
run:
working-directory: services/ecran
steps:
- uses: actions/checkout@v4

- name: Restore cache
uses: actions/cache/restore@v4
id: cache
with:
path: |
services/ecran/node_modules
services/ecran/.next/cache
key: ${{ runner.os }}-bun-${{ hashFiles('services/ecran/package.json') }}

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install

- name: Build
run: bun run build

- name: Save cache
uses: actions/cache/save@v4
if: steps.cache.outputs.cache-hit != 'true'
with:
path: |
services/ecran/node_modules
services/ecran/.next/cache
key: ${{ runner.os }}-bun-${{ hashFiles('services/ecran/package.json') }}

- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: kalmyk.duckdns.org
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_TOKEN }}

- name: Package into Docker image
uses: docker/build-push-action@v6
with:
push: true
context: services/ecran
file: services/ecran/Dockerfile.package
platforms: linux/arm64
tags: ${{ needs.version.outputs.new_tag }}
cache-from: type=registry,ref=kalmyk.duckdns.org/lab/ecran:latest
cache-to: type=inline

build-ecran-worker:
needs: [version, build-ecran-migrator]
Expand Down
45 changes: 27 additions & 18 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,34 @@ jobs:
run:
working-directory: services/ecran
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Restore cache
uses: actions/cache/restore@v4
id: cache
with:
image: public.ecr.aws/eks-distro-build-tooling/binfmt-misc:qemu-v7.0.0
path: |
services/ecran/node_modules
services/ecran/.next/cache
key: ${{ runner.os }}-bun-${{ hashFiles('services/ecran/package.json') }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install

- name: Build
run: bun run build

- name: Save cache
uses: actions/cache/save@v4
if: steps.cache.outputs.cache-hit != 'true'
with:
driver-opts: |
image=moby/buildkit:v0.18.0
path: |
services/ecran/node_modules
services/ecran/.next/cache
key: ${{ runner.os }}-bun-${{ hashFiles('services/ecran/package.json') }}

- name: Login to Container Registry
uses: docker/login-action@v3
Expand All @@ -38,19 +53,13 @@ jobs:
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_TOKEN }}

- name: Build and push Docker image
- name: Package into Docker image
uses: docker/build-push-action@v6
with:
push: true
context: services/ecran
file: services/ecran/Dockerfile.package
platforms: linux/arm64
push: true
tags: kalmyk.duckdns.org/lab/ecran:${{ github.sha }},kalmyk.duckdns.org/lab/ecran:latest
target: runner
build-args: |
NEXT_PUBLIC_COMMIT_SHA=${{ github.sha }}
tags: kalmyk.duckdns.org/lab/ecran:latest
cache-from: type=registry,ref=kalmyk.duckdns.org/lab/ecran:latest
cache-to: type=inline
secrets: |
github-token=${{ secrets.GITHUB_TOKEN }}
provenance: false
10 changes: 3 additions & 7 deletions services/ecran/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
FROM node:lts-alpine AS base

# Install pnpm
RUN npm install -g pnpm

FROM oven/bun:1 as base
FROM base AS deps
WORKDIR /app
COPY package.json ./
COPY .npmrc ./

RUN pnpm install
RUN bun install

# Rebuild the source code only when needed
FROM base AS builder
Expand All @@ -19,7 +15,7 @@ ENV NEXT_TELEMETRY_DISABLED=1
RUN pnpm run build

# Production image, copy all the files and run next
FROM base AS runner
FROM node:lts-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
Expand Down
38 changes: 6 additions & 32 deletions services/ecran/Dockerfile.package
Original file line number Diff line number Diff line change
@@ -1,42 +1,16 @@
FROM node:lts-alpine AS builder
WORKDIR /app

# Install pnpm
RUN --mount=type=cache,target=/root/.npm \
npm install -g pnpm

# Copy package files
COPY package.json pnpm-lock.yaml ./
COPY .npmrc ./

# Install dependencies with cache
RUN --mount=type=cache,target=/root/.local/share/pnpm/store,id=pnpm-store \
--mount=type=cache,target=/app/node_modules,id=node-modules \
pnpm install --no-frozen-lockfile

# Copy source files
COPY . .

# Build the application with cache
RUN --mount=type=cache,target=/app/.next/cache,id=next-cache \
--mount=type=cache,target=/app/node_modules,id=node-modules \
--mount=type=cache,target=/root/.local/share/pnpm/store,id=pnpm-store \
NEXT_TELEMETRY_DISABLED=1 pnpm run build

# Production image
FROM node:lts-alpine AS runner
FROM node:lts-alpine
WORKDIR /app

ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1

RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
adduser --system --uid 1001 nextjs

# Copy build output from builder
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
# Copy the pre-built application
COPY .next/standalone ./
COPY .next/static ./.next/static
COPY public ./public

USER nextjs

Expand Down
Binary file added services/ecran/bun.lockb
Binary file not shown.
5 changes: 4 additions & 1 deletion services/ecran/src/temporal/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ async function run() {
}
}

run().catch((err) => console.log(err))
run().catch((err) => {
console.error(err)
process.exit(1)
})

0 comments on commit 65493d6

Please sign in to comment.