Skip to content

Commit

Permalink
build(bun): refine setting for bun
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlking committed Sep 16, 2023
1 parent 8925444 commit c1084bf
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 61 deletions.
2 changes: 0 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
!.npmrc
!turbo.json
!/package.json
!/pnpm-lock.yaml
!/pnpm-workspace.yaml
!/apps
!/packages
!/patches
Expand Down
8 changes: 4 additions & 4 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Closes #{issueNumber}

## Changsets

Instructions: Changesets automate our changelog. If you modify files in `/packages/ui`, run `pnpm changeset` in the root of the monorepo, follow the prompts, then commit the markdown file. Changes that add features should be `minor` while chores and bugfixes should be `patch`. Please prefix the changeset message with `feat:`, `fix:` or `chore:`.
Instructions: Changesets automate our changelog. If you modify files in `/packages/ui`, run `bun run changeset` in the root of the monorepo, follow the prompts, then commit the markdown file. Changes that add features should be `minor` while chores and bugfixes should be `patch`. Please prefix the changeset message with `feat:`, `fix:` or `chore:`.

## Checklist

Expand All @@ -17,9 +17,9 @@ Please read and apply all [contribution requirements](../CODE_OF_CONDUCT.md).
- [ ] This PR targets the `main` branch
- [ ] Documentation reflects all relevant changes
- [ ] Branch is prefixed with: `docs/`, `feat/`, `chore/`, `fix/`
- [ ] Ensure Svelte and Typescript linting is current - run `pnpm check`
- [ ] Ensure Prettier linting is current - run `pnpm format`
- [ ] All test cases are passing - run `pnpm test`
- [ ] Ensure Svelte and Typescript linting is current - run `bun run check`
- [ ] Ensure Prettier linting is current - run `bun run format`
- [ ] All test cases are passing - run `bun run test`
- [ ] Includes a changeset (if relevant; see above)

### Commit message format
Expand Down
104 changes: 64 additions & 40 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,68 @@ jobs:
uses: cocogitto/[email protected]
with:
check-latest-tag-only: true
# linter:
# name: Lint Code Base
# runs-on: ubuntu-latest
# steps:
# - name: Checkout Code
# uses: actions/checkout@v4
# with:
# # Full git history is needed to get a proper list of changed files within `super-linter`
# fetch-depth: 0
# - name: Lint Code Base
# uses: github/super-linter@v5
# env:
# VALIDATE_ALL_CODEBASE: false
# IGNORE_GENERATED_FILES: true
# # FILTER_REGEX_EXCLUDE: CHANGELOG.md
# DEFAULT_BRANCH: main
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# build:
# name: Build and Test
# timeout-minutes: 15
# runs-on: ubuntu-latest
# # To use Remote Caching, uncomment the next lines and follow the steps below.
# env:
# TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
# TURBO_TEAM: ${{ vars.TURBO_TEAM }}
# linter:
# name: Lint Code Base
# runs-on: ubuntu-latest
# steps:
# - name: Checkout Code
# uses: actions/checkout@v4
# with:
# # Full git history is needed to get a proper list of changed files within `super-linter`
# fetch-depth: 0
# - name: Lint Code Base
# uses: github/super-linter@v5
# env:
# VALIDATE_ALL_CODEBASE: false
# IGNORE_GENERATED_FILES: true
# # FILTER_REGEX_EXCLUDE: CHANGELOG.md
# DEFAULT_BRANCH: main
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# build:
# name: Build and Test
# timeout-minutes: 15
# runs-on: ubuntu-latest
# # To use Remote Caching, uncomment the next lines and follow the steps below.
# env:
# TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
# TURBO_TEAM: ${{ vars.TURBO_TEAM }}

# steps:
# - name: Check out code
# uses: actions/checkout@v4
# with:
# fetch-depth: 2
# - uses: pnpm/action-setup@v2
# with:
# version: 8
# - uses: actions/setup-node@v3
# with:
# node-version: '20'
# cache: 'pnpm'
# - run: pnpm install
# - run: pnpm build
# - run: pnpm test:unit:coverage
# steps:
# - name: Check out code
# uses: actions/checkout@v4
# with:
# fetch-depth: 2
# - uses: pnpm/action-setup@v2
# with:
# version: 8
# - uses: actions/setup-node@v3
# with:
# node-version: '20'
# cache: 'pnpm'
# - run: pnpm install
# - run: pnpm run build --filter=playground
# - run: pnpm run test:unit:coverage --filter=playground

build:
name: Build and Test
timeout-minutes: 15
runs-on: ubuntu-latest
# To use Remote Caching, uncomment the next lines and follow the steps below.
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}

steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install Dependencies
run: bun install
# - run: bun run check --filter=playground
# - run: bun run lint --filter=playground
- run: bun run build --filter=playground
- run: bun run test:unit:coverage --filter=playground
6 changes: 3 additions & 3 deletions .lintstagedrc.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* jshint esversion: 9 */

module.exports = {
'*.{js,ts,json,svelte}': ['pnpm format', 'git add'],
'./src/**/*.{svelte,ts}': ['pnpm format', 'git add', 'pnpm lint:fix'],
'./.{ts,cjs,js}': ['pnpm lint:fix']
'*.{js,ts,json,svelte}': ['bun run format', 'git add'],
'./src/**/*.{svelte,ts}': ['bun run format', 'git add', 'bun run lint:fix'],
'./.{ts,cjs,js}': ['bun run lint:fix']
};
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ Use `.env.local` to override environment variables in `.env` (like API keys) for
Once you've cloned the project and installed dependencies with `bun i`, start a development server:

```shell
bun run dev --filter=./apps/web
bun run dev --filter=web

# or start the server and open the app in a new browser tab
bun run dev --filter=./apps/web -- --open
bun run dev --filter=web -- --open

# run in debug mode
bun run dev:debug --filter=./apps/web
bun run dev:debug --filter=web

# run with a custom inline config
# inline environment variables has higher precedence than ones loaded from .env and .env.local files
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ npm init svelte my-app

## Developing

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `bun install`), start a development server:

```bash
npm run dev
Expand Down
1 change: 1 addition & 0 deletions apps/web/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
!/package.json
!/pnpm-lock.yaml
!/pnpm-workspace.yaml
!/bun.lockb
!/svelte.config.js
!/tailwind.config.cjs
!/vite.config.js
Expand Down
2 changes: 1 addition & 1 deletion apps/web/houdini.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const defaultMarshall = {
const config = {
watchSchema: {
url: (env) => env.PUBLIC_GRAPHQL_ENDPOINT,
interval: 0, // only pull the schema when you first run `pnpm dev`
interval: 0, // only pull the schema when you first run `bun run dev`
// HINT: we need to generate scheam for highest role level that app support.
headers: {
'x-hasura-admin-secret': 'env:HASURA_GRAPHQL_ADMIN_SECRET',
Expand Down
2 changes: 1 addition & 1 deletion apps/web/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
webServer: {
command: 'pnpm build && pnpm preview',
command: 'bun run build && bun run preview',
port: 4173
},
testDir: 'tests',
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion cog.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ post_bump_hooks = [
[git_hooks.commit-msg]
script = """#!/bin/sh
set -e
pnpm format
bun run format
cog verify -i --file $1
"""
Expand Down
4 changes: 2 additions & 2 deletions docs/turborepo.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ This Turborepo has some additional tools already setup for you:
## Prerequisite

```bash
pnpm add -g turbo@latest
# bun add -g turbo@latest
# pnpm add -g turbo@latest
bun add -g turbo@latest
```

## Setup
Expand Down
116 changes: 116 additions & 0 deletions pnpm.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
ARG SCOPE=playground
###################################################################
# Stage 0: base image #
###################################################################
FROM node:20-slim AS base
ENV GIT_SSL_NO_VERIFY 1
RUN apt-get update && apt-get install -y --no-install-recommends git tini

ARG SCOPE
ENV SCOPE=${SCOPE}

#https://turbo.build/repo/docs/handbook/deploying-with-docker
#https://github.com/vercel/turbo/tree/main/examples/with-docker

# Install pnpm
ENV PNPM_HOME="/root/.local/share/pnpm"
ENV PATH="${PATH}:${PNPM_HOME}"
SHELL ["/bin/bash", "-c"]
RUN npm install --global pnpm \
&& SHELL=bash pnpm setup \
&& source /root/.bashrc

###################################################################
# Stage 1: Prune monorepo #
###################################################################
FROM base AS pruner

WORKDIR /app
RUN pnpm add -g turbo
COPY . .
RUN turbo prune --scope=${SCOPE} --docker

###################################################################
# Stage 2: Install dependencies #
# Add lockfile and package.json's of isolated subworkspace #
###################################################################
FROM base AS builder

WORKDIR /app
# First install the dependencies (as they change less often)
COPY .gitignore .gitignore
COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml

# https://playwright.dev/docs/browsers
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD 1

RUN pnpm install

# Build the project
COPY --from=pruner /app/out/full/ .
COPY --from=pruner /app/.git .git
COPY turbo.json turbo.json

# Uncomment and use build args to enable remote caching
ARG TURBO_TEAM
ENV TURBO_TEAM=$TURBO_TEAM

ARG TURBO_TOKEN
ENV TURBO_TOKEN=$TURBO_TOKEN

# TODO: set any extra ENV needed for build
# ENV ENCRYPTION_SECRET=encryption_secret_placeholder123 NEXTAUTH_URL=http://localhost:3000 NEXT_PUBLIC_VIEWER_URL=http://localhost:3001
RUN pnpm turbo run build --filter=${SCOPE}...

###################################################################
# Stage 4: Run the app (prod) #
###################################################################
# FROM gcr.io/distroless/nodejs:20 as final
# FROM gcr.io/distroless/nodejs:20-debug as final
FROM cgr.dev/chainguard/node:20 AS runner
# FROM base AS runner

WORKDIR /app
ENV NODE_ENV production
ARG SCOPE

# copy tini
COPY --from=builder --chown=node:node /usr/bin/tini /usr/bin/tini
ENTRYPOINT ["/usr/bin/tini", "-s", "--", "/usr/bin/node"]

# copy runtime needed config files???
COPY --from=builder --chown=node:node /app/apps/${SCOPE}/package.json .
# COPY --from=builder --chown=node:node /app/config ./config

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=node:node /app/apps/playground/build ./build


EXPOSE 3000
ENV PORT 3000

# Metadata params
ARG DOCKER_REGISTRY=ghcr.io
ARG VCS_CONTEXT_PATH=xmlking/spectacular
ARG BUILD_TIME
ARG BUILD_VERSION
ARG VCS_REF=1
ARG VENDOR=xmlking

# Metadata
LABEL org.opencontainers.image.created=$BUILD_TIME \
org.opencontainers.image.name="${SCOPE}" \
org.opencontainers.image.title="${SCOPE}" \
org.opencontainers.image.description="Example of SvelteKit multi-stage docker build" \
org.opencontainers.image.url=https://github.com/$VCS_CONTEXT_PATH \
org.opencontainers.image.source=https://github.com/$VCS_CONTEXT_PATH \
org.opencontainers.image.revision=$VCS_REF \
org.opencontainers.image.version=$BUILD_VERSION \
org.opencontainers.image.authors=sumanth \
org.opencontainers.image.vendor=$VENDOR \
org.opencontainers.image.licenses=MIT \
org.opencontainers.image.documentation="docker run -it -e NODE_ENV=production -p 3000:3000 ${DOCKER_REGISTRY:+${DOCKER_REGISTRY}/}${VCS_CONTEXT_PATH}/${SCOPE}:${BUILD_VERSION}"

CMD ["build"]
4 changes: 1 addition & 3 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
"test:watch": {
"cache": false
},
"check": {
"dependsOn": ["format", "lint"]
},
"check": {},
"clean": {
"cache": false
},
Expand Down

0 comments on commit c1084bf

Please sign in to comment.