-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
including wrapper script from terraform-config repo
- Loading branch information
Dan Buch
committed
Apr 9, 2018
1 parent
24c08b0
commit 7b0a06b
Showing
3 changed files
with
81 additions
and
4 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
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,66 @@ | ||
#!/usr/bin/env bash | ||
set -o errexit | ||
|
||
main() { | ||
local name="${1:-travis-worker}" | ||
|
||
docker stop "${name}" &>/dev/null || true | ||
docker rm -f "${name}" &>/dev/null || true | ||
|
||
local env_file | ||
env_file="$(tfw writeenv travis-worker)" | ||
|
||
set -o allexport | ||
# shellcheck source=/dev/null | ||
source "${env_file}" | ||
|
||
if [[ "${TRAVIS_WORKER_PROVIDER_NAME}" == gce ]]; then | ||
local gce_zone | ||
gce_zone="$(__fetch_gce_zone)" | ||
if [ -z "${gce_zone}" ]; then | ||
gce_zone=us-central1-b | ||
fi | ||
echo "TRAVIS_WORKER_GCE_ZONE=${gce_zone}" >>"${env_file}" | ||
fi | ||
|
||
if [[ ! "${TRAVIS_WORKER_LIBRATO_SOURCE}" ]]; then | ||
local librato_source | ||
librato_source="$(__build_librato_source "$(hostname)" "${name}")" | ||
echo "TRAVIS_WORKER_LIBRATO_SOURCE=${librato_source}" >>"${env_file}" | ||
fi | ||
|
||
if [ -f "${TRAVIS_WORKER_PRESTART_HOOK}" ]; then | ||
"${TRAVIS_WORKER_PRESTART_HOOK}" | ||
fi | ||
|
||
exec docker run \ | ||
--rm \ | ||
--name "${name}" \ | ||
--hostname "$(hostname)" \ | ||
--userns host \ | ||
-v /var/tmp:/var/tmp \ | ||
-v /var/run:/var/run \ | ||
--env-file "${env_file}" \ | ||
"${TRAVIS_WORKER_SELF_IMAGE}" travis-worker | ||
} | ||
|
||
__fetch_gce_zone() { | ||
curl -sSL \ | ||
"http://metadata.google.internal/computeMetadata/v1/instance/zone" \ | ||
-H "Metadata-Flavor: Google" | | ||
awk -F/ '{ print $NF }' | ||
} | ||
|
||
__build_librato_source() { | ||
local host_name="${1}" | ||
local name="${2}" | ||
|
||
if [[ "${name}" == "travis-worker" ]]; then | ||
echo "${host_name}" | ||
return | ||
fi | ||
|
||
echo "${host_name}-${name/travis-worker-/}" | ||
} | ||
|
||
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,13 @@ | ||
# Service definition to be installed somewhere in the systemd load path | ||
[Unit] | ||
Description=Travis Worker | ||
|
||
[Service] | ||
ExecStart=___SYSTEMD_WRAPPER___ | ||
ExecStopPost=/bin/sleep 5 | ||
Restart=always | ||
WorkingDirectory=/ | ||
User=travis | ||
|
||
[Install] | ||
WantedBy=multi-user.target |