Skip to content

Commit dcc3e90

Browse files
author
Shlomi Noach
authored
Merge pull request #778 from github/ci-build-pipelines
CI: adapting to internal builds system
2 parents cc3caff + 36b0adb commit dcc3e90

File tree

7 files changed

+110
-43
lines changed

7 files changed

+110
-43
lines changed

Dockerfile.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM golang:1.12.1
2+
LABEL maintainer="[email protected]"
3+
4+
RUN apt-get update
5+
RUN apt-get install -y lsb-release
6+
RUN rm -rf /var/lib/apt/lists/*
7+
8+
COPY . /go/src/github.com/github/gh-ost
9+
WORKDIR /go/src/github.com/github/gh-ost
10+
11+
CMD ["script/test"]

docker-compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: "3.5"
2+
services:
3+
app:
4+
image: app
5+
build:
6+
context: .
7+
dockerfile: Dockerfile.test

script/bootstrap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set -e
44

55
# Make sure we have the version of Go we want to depend on, either from the
66
# system or one we grab ourselves.
7+
# If executing from within Dockerfile then this assumption is inherently true, since we use a `golang` docker image.
78
. script/ensure-go-installed
89

910
# Since we want to be able to build this outside of GOPATH, we set it

script/build-deploy-tarball

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
script/build
6+
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
12+
13+
commit_sha=$(git rev-parse HEAD)
14+
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
20+
21+
tarball=$build_dir/${commit_sha}-${build_arch}.tar
22+
23+
# Create the tarball
24+
tar cvf $tarball --mode="ugo=rx" bin/
25+
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/
30+
31+
### HACK HACK HACK ###
32+
# blame @carlosmn and @mattr-
33+
# Allow builds on stretch to also be used for jessie
34+
jessie_tarball_name=$(echo $(basename "${tarball}") | sed s/-stretch-/-jessie-/)
35+
cp ${tarball}.gz "$BUILD_ARTIFACT_DIR/gh-ost/${jessie_tarball_name}.gz"

script/cibuild

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
11
#!/bin/bash
22

3-
set -e
4-
5-
. script/bootstrap
6-
7-
echo "Verifying code is formatted via 'gofmt -s -w go/'"
8-
gofmt -s -w go/
9-
git diff --exit-code --quiet
10-
11-
echo "Building"
12-
script/build
13-
14-
cd .gopath/src/github.com/github/gh-ost
15-
16-
echo "Running unit tests"
17-
go test ./go/...
3+
script/test
Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,47 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

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
49

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 $@
613

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
1218

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=$?
1423

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
2028

21-
tarball=$build_dir/${commit_sha}-${build_arch}.tar
29+
# preserve the exit code from the subcommand.
30+
return $exit_value
31+
}
2232

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+
}
2539

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
3041

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

script/test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
. script/bootstrap
6+
7+
echo "Verifying code is formatted via 'gofmt -s -w go/'"
8+
gofmt -s -w go/
9+
git diff --exit-code --quiet
10+
11+
echo "Building"
12+
script/build
13+
14+
cd .gopath/src/github.com/github/gh-ost
15+
16+
echo "Running unit tests"
17+
go test ./go/...

0 commit comments

Comments
 (0)