Spec file
The spec file is a simple description of your steps. It should be placed in your project, where you want.
The steps are executed in order, in case of failure the deployement is stopped.
Sample
version: '1.0'
from: 'romainlavabrefairfair/deploy-java' # Image of the build container
steps:
- name: '@test' # First step, launch test
script: '/.free-commit/live/test.sh' # Bash script from project root
- name: '@resolve-version' # Resolve the new version of the project
script: '/.free-commit/live/version.sh'
- name: '@build' # Builds the project in docker image and pushes to dockerhub
script: '/.free-commit/live/build.sh'
- name: '@deploy' # Deploys the new version
script: '/.free-commit/live/deploy.sh'
- name: '@tag' # Tags the project with the new version
script: '/.free-commit/live/tag.sh'
- name: '@script-with-arg'
script: /.free-commit/live/script-with-arg.sh arg1 arg2
⚠️ @ is required before the step name
⚠️ Scripts path must start with /
Scripts are called in entrypoint.sh in the Docker container (with bash environment, not sh), they are called with "."
So the deploy.yaml will be converted to :
#!/bin/bash
# Pre built function, always available
assertLastCmdSuccess() {
if [ "$?" != "0" ]; then
echo "$1" && exit 2000
fi
}
# All your build will be launched in /app directory
cd /app
. .free-commit/live/version.sh
assertLastCmdSuccess 'Step @version failed'
. .free-commit/live/build.sh
assertLastCmdSuccess 'Step @build failed'
. .free-commit/live/deploy.sh
assertLastCmdSuccess 'Step @deploy failed'
. .free-commit/live/tag.sh
assertLastCmdSuccess 'Step @tag failed'
. .free-commit/live/script-with-arg.sh arg1 arg2
assertLastCmdSuccess 'Step @script-with-arg failed'
Error detection
As you can see in the entryoint.sh example, free commit will test if the last executed command exited with code 0.
Be careful to creating atomic scripts to avoid undetected errors.
#!/bin/bash
my-bad-cmd
echo "I break error detection"
This script exit with 0
#!/bin/bash
my-bad-cmd
assertLastCmdSuccess 'my-bad-cmd is really bad, oops'
echo "I break error detection"
This script exit with 2000 and print "my-bad-cmd is really bad, oops"
Base image
You can use all images from Dockerhub.
In somes cases, you need to run an installation script, but it's too long (time * number of build), so you can create you own image.
Last updated