Cimage/bun

I don’t see an option to select cimage/bun for the environment. Who is responsible for creating this cimage - CircleCI or Bun.js?

There wouldn’t be a separate image for bun, most likely
There’s a feature request open to add it to cimg/node.

All that said, it seems to take about 2 seconds to install it, even with no cache, so another option would be to install it as a step… if you had a lot of projects that needed it, there are various ways to DRY that up.

greta~% docker run -it cimg/node:23.1
circleci@3764767da1b8:~/project$ time npm install bun
[...]
added 2 packages in 2s

real	0m2.213s
user	0m1.339s
sys	0m0.349s
circleci@3764767da1b8:~/project$ npx bun --version
[...]
# Or global install
circleci@3764767da1b8:~/project$ sudo npm -g install bun
[...]
added 2 packages in 2s
$ bun --help
Bun is a fast JavaScript runtime, package manager, bundler, and test runner. (1.1.33+247456b67)

Thanks for your answer, why would not be any separate image for Bun? i’m just curious

What would be the benefit of having a bun-specific image, vs. having bun installed in the regular node images?

Since Bun runs independently of Node.js, why add the extra overhead and possible weird behaviors of having both?

Oh, using it as a runtime not just the package manager? I doubt having both present would cause any major issues, though you probably would want to do something other than bootstrapping it via npm in that case.

I imagine you could open a feature request with CircleCI to create an image, though I imagine using https://hub.docker.com/r/oven/bun/tags (probably the alpine or slim variant) would probably be the way to go there?

There’s no reason you need to use a cimg base image specifically.

Or you could use cimg/base and add a step that installs bun (which I think would also / still be pretty fast), or build a custom image on top of it and use that in your steps (you’d just potentially have to deal with auth if it’s not a public image).

Thanks,
I think I’ll stick to using the package manager side of Bun. I’m trying the following setup, and it works fine for checkout, but for build and test, it complains that Bun is not installed. Is there a way to avoid installing Bun for each job?

# Use the latest 2.1 version of CircleCI pipeline processing engine, see https://circleci.com/docs/2.0/configuration-reference/
version: 2.1

defaults: &defaults
  working_directory: ~/repo
  # https://circleci.com/docs/2.0/circleci-images/#language-image-variants
  docker:
    - image: cimg/node:18.19.0-browsers
      environment:
        TERM: xterm # Enable colors in term

jobs:
  CHECKOUT:
    <<: *defaults
    steps:
      - checkout
      - run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/repo/.npmrc
      - run:
          name: Install Bun
          command: |
            curl -fsSL https://bun.sh/install | bash
            echo 'export BUN_INSTALL="$HOME/.bun"' >> $BASH_ENV
            echo 'export PATH="$BUN_INSTALL/bin:$PATH"' >> $BASH_ENV
      - run: bun install
      - persist_to_workspace:
          root: ~/repo
          paths: .

  BUILD:
    <<: *defaults
    steps:
      - attach_workspace:
          at: ~/repo
      - run:
          name: 'Perform the versioning before build'
          command: node ./version.mjs
      - run: bun run build
      - persist_to_workspace:
          root: ~/repo
          paths:
            - packages/core/dist
            - packages/tools/dist
            - packages/adapters/dist
            - packages/dicomImageLoader/dist
            - packages/nifti-volume-loader/dist
            - version.txt
            - commit.txt
            - version.json

  API_CHECK:
    <<: *defaults
    steps:
      - attach_workspace:
          at: ~/repo
      - run: bun run api-check
  FORMAT_CHECK:
    <<: *defaults
    steps:
      - attach_workspace:
          at: ~/repo
      - run: bun run format-check

  # https://circleci.com/docs/2.0/collect-test-data/#karma
  TEST:
    <<: *defaults
    steps:
      - attach_workspace:
          at: ~/repo
      - run: mkdir ~/junit
      - run:
          command: bun run test:unit:ci
          environment:
            JUNIT_REPORT_PATH: ./junit/
            JUNIT_REPORT_NAME: test-results.xml
          when: always
      - store_test_results:
          path: ./junit
      - store_artifacts:
          path: ./junit
      - persist_to_workspace:
          root: ~/repo
          paths:
            - coverage
            - junit

  NPM_PUBLISH:
    <<: *defaults
    resource_class: small
    steps:
      - attach_workspace:
          at: ~/repo
      - run:
          name: Avoid hosts unknown for github
          command:
            mkdir ~/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking
            no\n" > ~/.ssh/config
      - add_ssh_keys:
          fingerprints: 7e:0f:5b:bb:e3:7a:2e:2f:b4:85:bd:66:09:69:cb:f2
      - run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
      - run: git config --global user.email "contact@ohif.org"
      - run: git config --global user.name "ohif-bot"
      - run:
          name: publish package versions
          command: |
            node ./publish-version.mjs
      - run:
          name: Again set the NPM registry (was deleted in the version script)
          command:
            echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/repo/.npmrc
      - run:
          name: publish package dist
          command: |
            node ./publish-package.mjs

workflows:
  version: 2

  # PULL REQUEST
  PULL_REQUEST:
    jobs:
      - CHECKOUT:
          filters:
            branches:
              ignore:
                - main
                - feature/*
                - hotfix/*
      - BUILD:
          requires:
            - CHECKOUT
      - FORMAT_CHECK:
          requires:
            - BUILD
      - API_CHECK:
          requires:
            - BUILD
      - TEST:
          requires:
            - CHECKOUT # TODO: Also require build?

  # MERGE TO MAIN
  TEST_AND_RELEASE:
    jobs:
      - CHECKOUT:
          filters:
            branches:
              only:
                - main
                # - beta
      - BUILD:
          requires:
            - CHECKOUT
      - TEST:
          requires:
            - CHECKOUT
      - NPM_PUBLISH:
          requires:
            - BUILD

# VS Code Extension Version: 1.5.1

The way you have it now, neither the $BASH_ENV modifications or the software installation will likely persist between jobs.

Since you’re already installing it within your home directory, if you wanted to use the approach you’re using above, one way would be to cache / restore the bun installation by using save_cache and restore_cache and adding home/circleci/.bun (or whatever) to the paths keys to save / restore. One challenge would be figuring out when to update the cache - you’d need a cache key that would reliably change when the bun version updated (maybe do a checksum on the binary).

Alternately, if you used npm to bootstrap bun, you could use the typical npm cache / restore setup, though if you’re doing this with a non-global restore, you might have to run bun with npx.

Using oven/bun or creating a custom image (as mentioned above, using cimg/base as your base, or something else, as you prefer) would probably be other approaches you could take. Is there something from the cimg image families that you really need? The former seems to be a pretty lean image, so you might need a step that installs git or other basic dependencies, but still might work.

If Make installer/package for bun (SNAP, deb/apt, rpm/dnf) · Issue #862 · oven-sh/bun · GitHub were ever resolved, that would be another option.

the save_cache and restore_cache worked great, thanks !

1 Like