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

Updated README instruction #1

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions .github/workflows/buildpack-bun.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: buildpack-bun

on: push

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Run Buildpack Compile
run: ./bin/compile . . .
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

Heroku buildpack for Bun.js

Largely copied from https://github.com/chibat/heroku-buildpack-deno
You can optionally control the specific version by setting the `BUN_VERSION` environment-level variable to an explicit version e.g. 1.0.16
<img width="956" alt="Screenshot 2024-01-09 at 3 16 03 pm" src="https://github.com/callumfrance/heroku-buildpack-bun/assets/13757101/257737dc-7f04-4fae-9cc5-30ed69b30aa6">

Pin a certain Bun version with a `runtime.bun.txt` or `runtime.txt` with e.g. `v0.5.9` in it.
## How do I use this?
This is a third party heroku buildpack, so you will need to follow [the instructions provided by Heroku](https://devcenter.heroku.com/articles/buildpacks#using-a-third-party-buildpack) to enable it for your app.
You will need to assign the buildpack via the `heroku buildpacks:set` command.

Be aware that Heroku doesn't use a new enough version of the Linux kernel to support `io_uring`, which is needed for `Bun.write()`. Use `node:fs.writeFile()` instead.
If your app's entrypoint is at `src/index.ts`, here's an example `Procfile` you could potentially use:

```Procfile
web: bun install --frozen-lockfile && bun src/index.ts
```
36 changes: 32 additions & 4 deletions bin/compile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,48 @@
# bin/compile <build-dir> <cache-dir> <env-dir>
# $HOME: /app

set -e
set -o errexit
set -o pipefail
set -o nounset
unset GIT_DIR

function topic() {
echo "-----> $*..."
}

function indent() {
c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c" ;;
*) sed -u "$c" ;;
esac
}

BUILD_DIR=${1:-.}
CACHE_DIR=${2:-}
ENV_DIR=${3:-}

# determine version to install
if [ -f $ENV_DIR/BUN_VERSION ]; then
PROVIDED_VERSION_NUMBER=$(cat $ENV_DIR/BUN_VERSION)
VERSION="-s bun-v$PROVIDED_VERSION_NUMBER"
topic "Using bun v${PROVIDED_VERSION_NUMBER} (set by the env var 'BUN_VERSION')"
else
VERSION=""
topic "Defaulting to latest version of bun"
fi
indent "Version $VERSION"

# install bun
export BUN_INSTALL=$BUILD_DIR/.bun
curl -fsSL https://bun.sh/install | bash
curl -fsSL https://bun.sh/install | bash $VERSION

# set environment variables
export PATH=$BUN_INSTALL/bin:$PATH
PROFILE_PATH="$BUILD_DIR/.profile.d/bun.sh"
mkdir -p $(dirname $PROFILE_PATH)
echo 'export PATH="$HOME/.bun/bin:$PATH"' >> $PROFILE_PATH
echo 'export PATH="$HOME/.bun/bin:$PATH"' >>$PROFILE_PATH

bun --version

set +e
indent "Created"