-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental GoCD in a Docker container
- Loading branch information
Showing
5 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
examples/gocd_experimental/agent/scripts/with_test_results.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
set -eo pipefail | ||
|
||
is_successful() { | ||
local outcome="$1" | ||
test "$outcome" -ne 0 | ||
} | ||
|
||
test_results() { | ||
local outcome="$1" | ||
local failure="" | ||
local error="" | ||
|
||
if ! is_successful "$outcome"; then | ||
failure="<failure>Meh</failure>" | ||
error="<error>Argh</error>" | ||
fi | ||
|
||
cat <<EOF | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<testsuites> | ||
<testsuite name="Another Test Suite"> | ||
<testsuite name="Nested Test Suite"> | ||
<testcase classname="some.class" name="A Test" time="0.0021"> | ||
${failure} | ||
</testcase> | ||
<testcase classname="some.class" name="Some Test" time="0.005"> | ||
${error} | ||
</testcase> | ||
<testcase classname="some.class" name="Another Test" time="0.003"> | ||
</testcase> | ||
<testcase classname="some.class" name="Skipped Test" time="0.004"> | ||
<skipped/> | ||
</testcase> | ||
</testsuite> | ||
</testsuite> | ||
</testsuites> | ||
EOF | ||
} | ||
|
||
main() { | ||
local outcome | ||
outcome=$((GO_PIPELINE_COUNTER % 3)) | ||
|
||
test_results "$outcome" > results.xml | ||
is_successful "$outcome" | ||
} | ||
|
||
main "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: "2.4" | ||
|
||
services: | ||
server: | ||
image: gocd/gocd-server:v18.6.0 | ||
volumes: | ||
- ./server/config:/godata/config | ||
ports: | ||
- "8153:8153" | ||
|
||
agent: | ||
image: gocd/gocd-agent-alpine-3.7:v18.6.0 | ||
restart: always | ||
volumes: | ||
- ./agent/scripts:/scripts | ||
environment: | ||
GO_SERVER_URL: "https://server:8154/go" | ||
AGENT_AUTO_REGISTER_KEY: "ab455494-52a3-4ce7-b0cc-d38fbdc0aea9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/bin/bash | ||
set -eo pipefail | ||
|
||
readonly SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
readonly TMP_LOG="/tmp/run.$$.log" | ||
readonly BASE_URL="http://localhost:8153/go" | ||
|
||
wait_for_server() { | ||
local url=$1 | ||
echo -n " waiting for ${url}" | ||
until curl --output /dev/null --silent --head --fail "$url"; do | ||
printf '.' | ||
sleep 5 | ||
done | ||
} | ||
|
||
announce() { | ||
local text="$1" | ||
echo -ne "\033[1;30m" | ||
echo -n "$text" | ||
echo -ne "\033[0m" | ||
} | ||
|
||
hint_at_logs() { | ||
# shellcheck disable=SC2181 | ||
if [[ "$?" -ne 0 ]]; then | ||
echo | ||
echo "Logs are in ${TMP_LOG}" | ||
fi | ||
} | ||
|
||
container_exists() { | ||
if [[ -z $(docker-compose ps -q) ]]; then | ||
return 1 | ||
else | ||
return 0 | ||
fi | ||
} | ||
|
||
goal_start() { | ||
if ! container_exists; then | ||
announce "Provisioning docker image" | ||
echo | ||
|
||
# Wonky workaround for trying to boot up server image with minimal config, but no agent registration | ||
mkdir -p server/config | ||
cp server/*.xml server/config | ||
|
||
docker-compose up --no-start | ||
|
||
echo "done" | ||
fi | ||
|
||
announce "Starting docker image" | ||
docker-compose up -d &> "$TMP_LOG" | ||
|
||
wait_for_server "$BASE_URL" | ||
echo " done" | ||
rm "$TMP_LOG" | ||
} | ||
|
||
|
||
goal_stop() { | ||
announce "Stopping docker image" | ||
docker-compose stop &> "$TMP_LOG" | ||
echo " done" | ||
rm "$TMP_LOG" | ||
} | ||
|
||
goal_destroy() { | ||
announce "Destroying docker container" | ||
docker-compose down &> "$TMP_LOG" | ||
echo " done" | ||
rm "$TMP_LOG" | ||
} | ||
|
||
goal_purge() { | ||
announce "Purging docker images" | ||
docker rmi gocd/gocd-server:v18.6.0 >> "$TMP_LOG" | ||
docker rmi gocd/gocd-agent-alpine-3.7:v18.6.0 >> "$TMP_LOG" | ||
echo " done" | ||
rm "$TMP_LOG" | ||
} | ||
|
||
main() { | ||
trap hint_at_logs EXIT | ||
|
||
if type -t "goal_$1" &>/dev/null; then | ||
"goal_$1" | ||
else | ||
echo "usage: $0 (start|stop|destroy|purge)" | ||
fi | ||
} | ||
|
||
main "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<cruise xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="cruise-config.xsd" schemaVersion="108"> | ||
<server artifactsdir="artifacts" agentAutoRegisterKey="ab455494-52a3-4ce7-b0cc-d38fbdc0aea9" webhookSecret="90198de9-68da-4547-a699-3c4309862f87" commandRepositoryLocation="default" serverId="ce73cbce-3b97-4a11-91a1-45ee51cc5ed1" tokenGenerationKey="72f2db41-0330-406f-9af9-0e6ed3e37680" /> | ||
<pipelines group="defaultGroup"> | ||
<pipeline name="Example"> | ||
<materials> | ||
<git url="https://github.com/cburgmer/buildviz.git" shallowClone="true" autoUpdate="false" /> | ||
</materials> | ||
<stage name="defaultStage" fetchMaterials="false"> | ||
<jobs> | ||
<job name="defaultJob"> | ||
<tasks> | ||
<exec command="/scripts/with_test_results.sh"> | ||
<runif status="passed" /> | ||
</exec> | ||
</tasks> | ||
<artifacts> | ||
<artifact type="test" src="results.xml" dest="results.xml" /> | ||
</artifacts> | ||
</job> | ||
</jobs> | ||
</stage> | ||
</pipeline> | ||
</pipelines> | ||
</cruise> |