Buildsh is docker powered shell that makes it easy to run a script in isolated environment for building, testing and deploying softwares. Internally, buildsh is a wrapper of
docker run command that is implemented in Go.
After installing buildsh, run
buildsh -h to check working.
$ buildsh -h Usage: buildsh [<options...>] -- [<commands...>] ...
Try to run
buildsh without any options.
Buildsh boots a docker container using the default image
kohkimakimoto/buildsh:latest, and starts a bash process with interactive mode.
Your current working direcotory is automatically mounted to
/build directory in the container, and several programming language runtimes (Go, Ruby, PHP, etc...) already be installed in the container.
So you can run your project's tests by the following commands.
# php $ php phpunit # go $ go test ./... # shell script $ bash ./tests.sh
When you exit the shell, the container will be removed automatically.
If you use buildsh in non interactive mode, you use it with '-c' option and an argument that is the commands executed in the container.
$ buildsh -c 'php phpunit'
Buildsh loads configuration from
.buildsh.yml in your current working directory.
You can also specify the configuration by using
--config CLI option.
use_cache: true docker_image: kohkimakimoto/buildsh:latest additional_docker_options: --net=host -v=/var/run/docker.sock:/var/run/docker.sock environment: FOO: bar FOO2: bar2 home_in_container: /build/src/github.com/kohkimakimoto/buildsh script: | # 'buildbot' is a defaut user in the container for the buildsh. chown buildbot \ /build \ /build/src/ \ /build/src/github.com/ \ /build/src/github.com/kohkimakimoto
use_cache: If you set it, buildsh creates
.buildsh/cachedirectory in a current directory. It also set the environment variable
BUILDSH_CACHEDIRwhich stores the path to the cache directory.
docekr_image: Specifies a docker image to run. Default
docker_options: Options that are passed to the
docker runcommand that is executed by bashsh internally. Default
--rm -e TZ=Asia/Tokyo.
additional_docker_options: Options that are appended to the
environment: Specifies environment variables in a container.
home_in_container: Changes mount point and current working directory in a container. Default
script: Runs arbitrary script in a container before starting the shell. This script executed by root user. So you can use it to customize the container environment.
You can also change default configuration by using environment variable.
BUILDSH_USE_CACHE: Default value of
BUILDSH_DOCKER_IMAGE: Default value of
BUILDSH_DOCKER_OPTIONS: Default value of
BUILDSH_ADDITIONAL_DOCKER_OPTIONS: Default value of
BUILDSH_HOME_IN_CONTAINER: Default value of
Using Wrapper Script
You can use buildsh with a wrapper script. It may be convenient for using specific containers.
#!/bin/sh exec buildsh --config=' docker_image: centos:centos7 script: | echo "root:password" | chpasswd ' "$@"
If you create the above script as
buildsh-centos7, you can run it like the following.
$ ./buildsh-centos7 -c 'ls -la'
see also wrappers
Using With Shebang
If you want to create a script file that are executed by buildsh, you can use a trick to interpret shebang with buildsh. See the following example code.
#!/usr/bin/env bash [ -z "$BUILDSH" ] && exec buildsh "$0" "$@" # your code is after here... echo "I'm in a container!"
You can run it directly after adding an execution permission.
$ chmod 755 your_script.sh $ ./your_script.sh I'm in a container!
Using In Travis CI
If you use buildsh in Travis CI. See the below
services: - docker language: go go: - 1.8 before_install: - go get github.com/kohkimakimoto/buildsh script: - buildsh ./your/script.sh
Kohki Makimoto firstname.lastname@example.org
The MIT License (MIT)