Skip to content

Commit

Permalink
Fill in tfw-ized app compat bits
Browse files Browse the repository at this point in the history
including wrapper script from terraform-config repo
  • Loading branch information
Dan Buch committed Apr 9, 2018
1 parent 24c08b0 commit 7b0a06b
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ RUN make deps
ENV CGO_ENABLED 0
RUN make build

#################################
### linux/amd64/travis-worker ###
#################################

FROM alpine:latest
RUN apk --no-cache add ca-certificates curl bash

COPY --from=builder /go/bin/travis-worker /usr/local/bin/travis-worker
COPY --from=builder /go/src/github.com/travis-ci/worker/systemd.service /app/systemd.service
COPY --from=builder /go/src/github.com/travis-ci/worker/systemd-wrapper /app/systemd-wrapper
COPY --from=builder /go/src/github.com/travis-ci/worker/.docker-entrypoint.sh /docker-entrypoint.sh

VOLUME ["/var/tmp"]
Expand Down
66 changes: 66 additions & 0 deletions systemd-wrapper
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 "$@"
13 changes: 13 additions & 0 deletions systemd.service
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

0 comments on commit 7b0a06b

Please sign in to comment.