Skip to content

Commit

Permalink
ref(*): remove label for commit_id
Browse files Browse the repository at this point in the history
This is unused and can be confusing.
  • Loading branch information
adamreese committed Mar 1, 2018
1 parent 5166f14 commit 73da3c1
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 92 deletions.
2 changes: 0 additions & 2 deletions brigade-worker/src/k8s.ts
Expand Up @@ -172,13 +172,11 @@ export class JobRunner implements jobs.JobRunner {

this.runner.metadata.labels.jobname = job.name;
this.runner.metadata.labels.project = project.id;
this.runner.metadata.labels.commit = commit;
this.runner.metadata.labels.worker = e.workerID;
this.runner.metadata.labels.build = e.buildID;

this.secret.metadata.labels.jobname = job.name;
this.secret.metadata.labels.project = project.id;
this.secret.metadata.labels.commit = commit;
this.secret.metadata.labels.expires = String(expiresAt);
this.secret.metadata.labels.worker = e.workerID;
this.secret.metadata.labels.build = e.buildID;
Expand Down
14 changes: 0 additions & 14 deletions brigade-worker/test/k8s.ts
Expand Up @@ -76,9 +76,6 @@ describe("k8s", function() {
assert.equal(jr.secret.metadata.name, jr.name)
assert.equal(jr.runner.spec.containers[0].image, "whaler")

assert.equal(jr.runner.metadata.labels.commit, e.revision.commit)
assert.equal(jr.secret.metadata.labels.commit, e.revision.commit)

assert.equal(jr.runner.metadata.labels.worker, e.workerID)
assert.equal(jr.secret.metadata.labels.worker, e.workerID)

Expand Down Expand Up @@ -109,17 +106,6 @@ describe("k8s", function() {
assert.equal(found, 2)
})
})
context("when event is missing commit", function() {
beforeEach(function() {
e.revision.commit = null
})
it("sets 'master' as the commit", function() {
let jr= new k8s.JobRunner(j, e, p)

assert.equal(jr.runner.metadata.labels.commit, "master")
assert.equal(jr.secret.metadata.labels.commit, "master")
})
})
context("when service account is specified", function() {
beforeEach(function() {
j.serviceAccount = "svcAccount"
Expand Down
21 changes: 11 additions & 10 deletions docs/topics/examples/simple-event/cron/cron-event.sh
Expand Up @@ -7,7 +7,8 @@ namespace=${NAMESPACE:-default}
event_provider="simple-event"
event_type="my_event"
project_id="brigade-830c16d4aaf6f5490937ad719afd8490a5bcbef064d397411043ac"
commit="master"
commit_ref="master"
commit_id="589e15029e1e44dee48de4800daf1f78e64287c0"
uuid="$(uuidgen | tr '[:upper:]' '[:lower:]')"
name="simple-event-$uuid"

Expand All @@ -20,7 +21,6 @@ events.on("my_event", (e) => {
EOF
)


cat <<EOF | kubectl --namespace ${namespace} create -f -
apiVersion: v1
kind: Secret
Expand All @@ -30,15 +30,16 @@ metadata:
heritage: brigade
project: ${project_id}
build: ${uuid}
commit: ${commit}
component: build
type: "brigade.sh/build"
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)
revision:
commit: $(base64 -w 0 <<<"${commit_id}")
ref: $(base64 -w 0 <<<"${commit_ref}")
event_provider: $(base64 -w 0 <<<"${event_provider}")
event_type: $(base64 -w 0 <<<"${event_type}")
project_id: $(base64 -w 0 <<<"${project_id}")
build_id: $(base64 -w 0 <<<"${uuid}")
payload: $(base64 -w 0 <<<"${payload}")
script: $(base64 -w 0 <<<"${script}")
EOF
39 changes: 19 additions & 20 deletions docs/topics/examples/simple-event/simple-event.sh
Expand Up @@ -9,17 +9,16 @@ event_type="my_event"

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

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


# This is the brigade script to execute
script=$(cat <<EOF
const { events } = require("brigadier");
Expand All @@ -29,11 +28,11 @@ events.on("my_event", (e) => {
EOF
)

# Now we will generate a new event evrey 60 seconds.
while : ; do
# Now we will generate a new event every 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:]')"
uuid="$("${uuidgen[@]}" | tr '[:upper:]' '[:lower:]')"

# We can use the UUID to make sure we get a unique name
name="simple-event-$uuid"
Expand All @@ -50,18 +49,18 @@ while : ; do
heritage: brigade
project: ${project_id}
build: ${uuid}
commit: ${commit}
component: build
type: "brigade.sh/build"
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)
revision:
commit: $("${base64[@]}" <<<"${commit_id}")
ref: $("${base64[@]}" <<<"${commit_ref}")
event_provider: $("${base64[@]}" <<<"${event_provider}")
event_type: $("${base64[@]}" <<<"${event_type}")
project_id: $("${base64[@]}" <<<"${project_id}")
build_id: $("${base64[@]}" <<<"${uuid}")
payload: $("${base64[@]}" <<<"${payload}")
script: $("${base64[@]}" <<<"${script}")
EOF
sleep 60
done

62 changes: 31 additions & 31 deletions docs/topics/gateways.md
Expand Up @@ -13,7 +13,7 @@ into a Brigade event.
Brigade ships with two gateways that translate webhook requests into Brigade
events: The [GitHub gateway](github.md) and the
[container registry gateway](dockerhub.md).
These both provide HTTP-based listeners that receive incomming requests
These both provide HTTP-based listeners that receive incoming requests
and generate Brigade events as a result.

But the gateway system works with more than just webhooks.
Expand All @@ -33,7 +33,7 @@ gateways.
## An Event Is A Secret

The most important thing to understand about a Brigade event is that it is simply
a [Kuberetes Secret](https://kubernetes.io/docs/concepts/configuration/secret/)
a [Kubernetes Secret](https://kubernetes.io/docs/concepts/configuration/secret/)
with special labels and data.

When a new and appropriately labeled secret is created in Kubernetes, the Brigade
Expand Down Expand Up @@ -76,10 +76,6 @@ metadata:
# expected. (A UUID v1 will be sortable like ULIDs, but longer).
build: 01C1R2SYTYAR2WQ2DKNTW8SH08

# Commit is the commitish/reference for any associated VCS repository. By
# default, this should be `master` for Git.
commit: 6913b2703df943fed7a135b671f3efdafd92dbf3

# 'component: build' is REQUIRED and tells brigade to create a new build
# record (and trigger a new worker run).
component: build
Expand All @@ -100,7 +96,8 @@ data:
# Revision describes a vcs revision.
revision:

# This should be the same as the `commit` label.
# Commit is the commitish/reference for any associated VCS repository. By
# default, this should be `master` for Git.
commit: 6913b2703df943fed7a135b671f3efdafd92dbf3

# Ref is the symbolic ref name. (refs/heads/master, refs/pull/12/head, refs/tags/v0.1.0)
Expand Down Expand Up @@ -154,9 +151,15 @@ event_type="my_event"

# This is github.com/deis/empty-testbed
project_id="brigade-830c16d4aaf6f5490937ad719afd8490a5bcbef064d397411043ac"
commit_id="6913b2703df943fed7a135b671f3efdafd92dbf3"
commit_ref="master"
commit_id="589e15029e1e44dee48de4800daf1f78e64287c0"

base64=(base64)
uuidgen=(uuidgen)
if [[ "$(uname)" != "Darwin" ]]; then
base64+=(-w 0)
uuidgen+=(-t) # generate UUID v1 for sortability
fi

# This is the brigade script to execute
script=$(cat <<EOF
Expand All @@ -167,11 +170,11 @@ events.on("my_event", (e) => {
EOF
)

# Now we will generate a new event evrey 60 seconds.
while : ; do
# Now we will generate a new event every 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 | tr '[:upper:]' '[:lower:]')"
uuid="$("${uuidgen[@]}" | tr '[:upper:]' '[:lower:]')"

# We can use the UUID to make sure we get a unique name
name="simple-event-$uuid"
Expand All @@ -188,19 +191,18 @@ while : ; do
heritage: brigade
project: ${project_id}
build: ${uuid}
commit: ${commit_id}
component: build
type: "brigade.sh/build"
data:
revision:
commit: $(base64 -w 0 <<< "$commit_id")
ref: $(base64 -w 0 <<< "${commit_ref}")
event_provider: $(base64 -w 0 <<< "${event_provider}")
event_type: $(base64 -w 0 <<< "${event_type}")
project_id: $(base64 -w 0 <<< "${project_id}")
build_id: $(base64 -w 0 <<< "${uuid}")
payload: $(base64 -w 0 <<< "${payload}")
script: $(base64 -w 0 <<< "${script}")
commit: $("${base64[@]}" <<<"${commit_id}")
ref: $("${base64[@]}" <<<"${commit_ref}")
event_provider: $("${base64[@]}" <<<"${event_provider}")
event_type: $("${base64[@]}" <<<"${event_type}")
project_id: $("${base64[@]}" <<<"${project_id}")
build_id: $("${base64[@]}" <<<"${uuid}")
payload: $("${base64[@]}" <<<"${payload}")
script: $("${base64[@]}" <<<"${script}")
EOF
sleep 60
done
Expand Down Expand Up @@ -231,8 +233,8 @@ namespace=${NAMESPACE:-default}
event_provider="simple-event"
event_type="my_event"
project_id="brigade-830c16d4aaf6f5490937ad719afd8490a5bcbef064d397411043ac"
commit_id="6913b2703df943fed7a135b671f3efdafd92dbf3"
commit_ref="master"
commit_id="589e15029e1e44dee48de4800daf1f78e64287c0"
uuid="$(uuidgen | tr '[:upper:]' '[:lower:]')"
name="simple-event-$uuid"

Expand All @@ -245,7 +247,6 @@ events.on("my_event", (e) => {
EOF
)


cat <<EOF | kubectl --namespace ${namespace} create -f -
apiVersion: v1
kind: Secret
Expand All @@ -255,19 +256,18 @@ metadata:
heritage: brigade
project: ${project_id}
build: ${uuid}
commit: ${commit}
component: build
type: "brigade.sh/build"
data:
revision:
commit: $(base64 -w 0 <<< "$commit_id")
ref: $(base64 -w 0 <<< "${commit_ref}")
event_provider: $(base64 -w 0 <<< "${event_provider}")
event_type: $(base64 -w 0 <<< "${event_type}")
project_id: $(base64 -w 0 <<< "${project_id}")
build_id: $(base64 -w 0 <<< "${uuid}")
payload: $(base64 -w 0 <<< "${payload}")
script: $(base64 -w 0 <<< "${script}")
commit: $(base64 -w 0 <<<"${commit_id}")
ref: $(base64 -w 0 <<<"${commit_ref}")
event_provider: $(base64 -w 0 <<<"${event_provider}")
event_type: $(base64 -w 0 <<<"${event_type}")
project_id: $(base64 -w 0 <<<"${project_id}")
build_id: $(base64 -w 0 <<<"${uuid}")
payload: $(base64 -w 0 <<<"${payload}")
script: $(base64 -w 0 <<<"${script}")
EOF
```

Expand Down
1 change: 0 additions & 1 deletion pkg/storage/kube/build.go
Expand Up @@ -47,7 +47,6 @@ func (s *store) CreateBuild(build *brigade.Build) error {
Name: buildName,
Labels: map[string]string{
"build": build.ID,
"commit_id": build.Revision.Commit,
"component": "build",
"heritage": "brigade",
"project": build.ProjectID,
Expand Down
5 changes: 2 additions & 3 deletions pkg/storage/kube/build_test.go
Expand Up @@ -14,9 +14,8 @@ func TestNewBuildFromSecret(t *testing.T) {
secret := v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"build": "#1",
"project": "myproject",
"commit_id": "abc123",
"build": "#1",
"project": "myproject",
},
},
Data: map[string][]byte{
Expand Down
28 changes: 17 additions & 11 deletions scripts/functional-test-secret.sh
Expand Up @@ -8,14 +8,15 @@ uuid="$(uuidgen)"
name="brigade-worker-${uuid,,}"

namespace="default"
commit="9c75584920f1297008118915024927cc099d5dcc"
commit_ref="master"
commit_id="9c75584920f1297008118915024927cc099d5dcc"
event_provider="github"
event_type="push"
project_id="brigade-830c16d4aaf6f5490937ad719afd8490a5bcbef064d397411043ac"
payload="{}"
script="_cache/github.com/deis/empty-testbed/brigade.js"

while (( "$#" > 0 )); do
while (($# > 0)); do
case "$1" in
--namespace) namespace="$2"; shift ;;
--script) script="$2"; shift ;;
Expand All @@ -25,6 +26,11 @@ while (( "$#" > 0 )); do
shift
done

base64=(base64)
if [[ "$(uname)" != "Darwin" ]]; then
base64+=(-w 0)
fi

cat <<EOF | kubectl --namespace ${namespace} create -f -
apiVersion: v1
kind: Secret
Expand All @@ -34,16 +40,16 @@ metadata:
heritage: brigade
project: ${project_id}
build: ${uuid}
commit: ${commit}
jobname: ${name}
component: build
type: "brigade.sh/build"
data:
commit: $(echo -n "${commit}" | base64)
event_provider: $(echo -n "${event_provider}" | base64)
event_type: $(echo -n "${event_type}" | base64)
project_id: $(echo -n "${project_id}" | base64)
build_id: $(echo -n "${uuid}" | base64)
payload: $(echo -n "${payload}" | base64)
script: $(base64 < "${script}")
revision:
commit: $("${base64[@]}" <<<"${commit_id}")
ref: $("${base64[@]}" <<<"${commit_ref}")
event_provider: $("${base64[@]}" <<<"${event_provider}")
event_type: $("${base64[@]}" <<<"${event_type}")
project_id: $("${base64[@]}" <<<"${project_id}")
build_id: $("${base64[@]}" <<<"${uuid}")
payload: $("${base64[@]}" <<<"${payload}")
script: $("${base64[@]}" <"${script}")
EOF

0 comments on commit 73da3c1

Please sign in to comment.