CI and Docker
Run installs and tests in a pipeline, use the official Docker image, and set up CommandBox in GitHub Actions.
Everything you ran by hand works in a pipeline. In this lesson you will see the two commands CI needs, the Docker image, and a GitHub Actions workflow.
The two commands
box install
box testbox run
box install restores the dependencies listed in box.json. box testbox run runs your suite and returns a failing exit code if any test fails, which fails the build. Any command run as box <command> from your native shell passes its exit code straight through.
Docker
Ortus publishes an official image, ortussolutions/commandbox, built from the docker-commandbox repository.
docker pull ortussolutions/commandbox
docker run -p 8080:8080 -p 8443:8443 -v "/path/to/your/app:/app" ortussolutions/commandbox
The /app folder in the container is the CommandBox working directory. The image listens on 8080 by default, and 8443 for SSL if enabled in your server.json. It reads environment variables such as PORT, SSL_PORT, CFENGINE and HEALTHCHECK_URI.
For your own image, use the docker-commandbox repository as the baseline for your Dockerfile.
GitHub Action
Ortus provides Ortus-Solutions/setup-commandbox to install CommandBox on a runner. Minimal usage:
- name: Setup CommandBox
uses: Ortus-Solutions/setup-commandbox@v2.0.0
A workflow
name: Tests
on: [push, pull_request]
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup CommandBox
uses: Ortus-Solutions/setup-commandbox@v2.0.0
- name: Install dependencies
run: box install
- name: Start server
run: box server start
- name: Run tests
run: box testbox run
Pin the action to a release listed in its README. This workflow assumes your project is set up as in the earlier lessons, with CommandBox running on BoxLang and testbox-cli listed in your dependencies.
Recap
- A pipeline needs
box installandbox testbox run, and a red test fails the build. - The official image is
ortussolutions/commandbox, with your app mounted at/app. Ortus-Solutions/setup-commandboxinstalls CommandBox in GitHub Actions.