|
1 | | -#!/bin/sh |
| 1 | +#!/bin/bash |
2 | 2 |
|
3 | | -set -e |
| 3 | +output_fold() { |
| 4 | + # Exit early if no label provided |
| 5 | + if [ -z "$1" ]; then |
| 6 | + echo "output_fold(): requires a label argument." |
| 7 | + return |
| 8 | + fi |
4 | 9 |
|
5 | | -script/cibuild |
| 10 | + exit_value=0 # exit_value is used to record exit status of the given command |
| 11 | + label=$1 # human-readable label describing what's being folded up |
| 12 | + shift 1 # having retrieved the output_fold()-specific arguments, strip them off $@ |
6 | 13 |
|
7 | | -# Get a fresh directory and make sure to delete it afterwards |
8 | | -build_dir=tmp/build |
9 | | -rm -rf $build_dir |
10 | | -mkdir -p $build_dir |
11 | | -trap "rm -rf $build_dir" EXIT |
| 14 | + # Only echo the tags when in CI_MODE |
| 15 | + if [ "$CI_MODE" ]; then |
| 16 | + echo "%%%FOLD {$label}%%%" |
| 17 | + fi |
12 | 18 |
|
13 | | -commit_sha=$(git rev-parse HEAD) |
| 19 | + # run the remaining arguments. If the command exits non-0, the `||` will |
| 20 | + # prevent the `-e` flag from seeing the failure exit code, and we'll see |
| 21 | + # the second echo execute |
| 22 | + "$@" || exit_value=$? |
14 | 23 |
|
15 | | -if [ $(uname -s) = "Darwin" ]; then |
16 | | - build_arch="$(uname -sr | tr -d ' ' | tr '[:upper:]' '[:lower:]')-$(uname -m)" |
17 | | -else |
18 | | - build_arch="$(lsb_release -sc | tr -d ' ' | tr '[:upper:]' '[:lower:]')-$(uname -m)" |
19 | | -fi |
| 24 | + # Only echo the tags when in CI_MODE |
| 25 | + if [ "$CI_MODE" ]; then |
| 26 | + echo "%%%END FOLD%%%" |
| 27 | + fi |
20 | 28 |
|
21 | | -tarball=$build_dir/${commit_sha}-${build_arch}.tar |
| 29 | + # preserve the exit code from the subcommand. |
| 30 | + return $exit_value |
| 31 | +} |
22 | 32 |
|
23 | | -# Create the tarball |
24 | | -tar cvf $tarball --mode="ugo=rx" bin/ |
| 33 | +function cleanup() { |
| 34 | + echo |
| 35 | + echo "%%%FOLD {Shutting down services...}%%%" |
| 36 | + docker-compose down |
| 37 | + echo "%%%END FOLD%%%" |
| 38 | +} |
25 | 39 |
|
26 | | -# Compress it and copy it to the directory for the CI to upload it |
27 | | -gzip $tarball |
28 | | -mkdir -p "$BUILD_ARTIFACT_DIR"/gh-ost |
29 | | -cp ${tarball}.gz "$BUILD_ARTIFACT_DIR"/gh-ost/ |
| 40 | +trap cleanup EXIT |
30 | 41 |
|
31 | | -### HACK HACK HACK ### |
32 | | -# Blame @carlosmn. In the good way. |
33 | | -# We don't have any jessie machines for building, but a pure-Go binary depends |
34 | | -# on a version of libc and ld which are widely available, so we can copy the |
35 | | -# tarball over with jessie in its name so we can deploy it on jessie machines. |
36 | | -jessie_tarball_name=$(echo $(basename "${tarball}") | sed s/-precise-/-jessie-/) |
37 | | -cp ${tarball}.gz "$BUILD_ARTIFACT_DIR/gh-ost/${jessie_tarball_name}.gz" |
| 42 | +export CI_MODE=true |
| 43 | + |
| 44 | +output_fold "Bootstrapping container..." docker-compose build |
| 45 | +output_fold "Running tests..." docker-compose run --rm app |
| 46 | + |
| 47 | +docker-compose run -e BUILD_ARTIFACT_DIR=$BUILD_ARTIFACT_DIR -v $BUILD_ARTIFACT_DIR:$BUILD_ARTIFACT_DIR app script/build-deploy-tarball |
0 commit comments