Skip to content
Permalink
Browse files

docs(gateways): add doc on creating Brigade gateways

  • Loading branch information
technosophos committed Dec 19, 2017
1 parent 8346887 commit 64e921e996b8c311f332c8e0943ebd6a68f8672a
@@ -0,0 +1,6 @@
FROM debian:jessie-slim
RUN apt-get update && apt-get install -y uuid-runtime curl
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl \
&& mv kubectl /usr/local/bin/kubectl && chmod 755 /usr/local/bin/kubectl
COPY ./cron-event.sh /usr/local/bin/cron-event.sh
CMD /usr/local/bin/cron-event.sh
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
set -euo pipefail

# The Kubernetes namespace in which Brigade is running.
namespace=${NAMESPACE:-default}

event_provider="simple-event"
event_type="my_event"
project_id="brigade-830c16d4aaf6f5490937ad719afd8490a5bcbef064d397411043ac"
commit="master"
uuid="$(uuidgen | tr '[:upper:]' '[:lower:]')"
name="simple-event-$uuid"

payload=$(date)
script=$(cat <<EOF
const { events } = require("brigadier");
events.on("my_event", (e) => {
console.log("The system time is " + e.payload);
});
EOF
)


cat <<EOF | kubectl --namespace ${namespace} create -f -
apiVersion: v1
kind: Secret
metadata:
name: ${name}
labels:
heritage: brigade
project: ${project_id}
build: ${uuid}
commit: ${commit}
component: build
type: Opaque
data:
commit: $(echo -n "${commit}" | base64 -w 0)
event_provider: $(echo -n "${event_provider}" | base64 -w 0)
event_type: $(echo -n "${event_type}" | base64 -w 0)
project_id: $(echo -n "${project_id}" | base64 -w 0)
build_id: $(echo -n "${uuid}" | base64 -w 0)
payload: $(echo -n "${payload}" | base64 -w 0)
script: $(echo -n "${script}" | base64 -w 0)
EOF
@@ -0,0 +1,18 @@
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: example-cron-gateway
labels:
heritage: brigade
component: gateway
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: cron-example
image: technosophos/example-cron:latest
imagePullPolicy: IfNotPresent
@@ -0,0 +1,67 @@
#!/usr/bin/env bash
set -euo pipefail

# The Kubernetes namespace in which Brigade is running.
namespace="default"

event_provider="simple-event"
event_type="my_event"

# This is github.com/deis/empty-testbed
project_id="brigade-830c16d4aaf6f5490937ad719afd8490a5bcbef064d397411043ac"
commit="master"

b64flags=""
uuidflags=""
system=$(uname)
if [[ $system != "Darwin" ]]; then
b64flags="-w 0" # Turn off line wrapping
uuidflags="-t" # generate UUID v1 for sortability
fi


# This is the brigade script to execute
script=$(cat <<EOF
const { events } = require("brigadier");
events.on("my_event", (e) => {
console.log("The system time is " + e.payload);
});
EOF
)

# Now we will generate a new event evrey 60 seconds.
while : ; do
# We'll use a UUID instead of a ULID. But if you want a ULID generator, you
# can grab one here: https://github.com/technosophos/ulid
uuid="$(uuidgen $uuidflags | tr '[:upper:]' '[:lower:]')"

# We can use the UUID to make sure we get a unique name
name="simple-event-$uuid"

# This will just print the system time for the system running the script.
payload=$(date)

cat <<EOF | kubectl --namespace ${namespace} create -f -
apiVersion: v1
kind: Secret
metadata:
name: ${name}
labels:
heritage: brigade
project: ${project_id}
build: ${uuid}
commit: ${commit}
component: build
type: Opaque
data:
commit: $(echo -n "${commit}" | base64 $b64flags)
event_provider: $(echo -n "${event_provider}" | base64 $b64flags)
event_type: $(echo -n "${event_type}" | base64 $b64flags)
project_id: $(echo -n "${project_id}" | base64 $b64flags)
build_id: $(echo -n "${uuid}" | base64 $b64flags)
payload: $(echo -n "${payload}" | base64 $b64flags)
script: $(echo -n "${script}" | base64 $b64flags)
EOF
sleep 60
done

0 comments on commit 64e921e

Please sign in to comment.
You can’t perform that action at this time.