Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: meta-trigger support of multiple GCP projects #28

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a58d227
fix: cicd dir structure
jthegedus Jun 2, 2020
ad58843
fix: format everything
jthegedus Jun 2, 2020
bcef6cf
fix: hadolint issues
jthegedus Jun 2, 2020
497abed
feat: download yq on build
jthegedus Jun 3, 2020
6d5fb38
feat: use shfmt to test formatting
jthegedus Jun 3, 2020
fd88fe3
ci: test shfmt in CloudBuild
jthegedus Jun 3, 2020
457886d
ci: shfmt functioned correctly
jthegedus Jun 3, 2020
ac44a93
ci: fix build dir of meta-triggers cb job
jthegedus Jun 3, 2020
e90913a
fix: quote bash env var
jthegedus Jun 3, 2020
2eca200
fix: jq version
jthegedus Jun 3, 2020
a51b7ee
fix: show available jq versions
jthegedus Jun 3, 2020
6071f1c
fix: echo dockerfile output for jq version printing
jthegedus Jun 3, 2020
5ead469
fix: output jq versions after apt update
jthegedus Jun 3, 2020
04b68f4
fix: jq version
jthegedus Jun 3, 2020
ec513d2
fix: show wget version
jthegedus Jun 3, 2020
7f6ebab
fix: pin wget version
jthegedus Jun 3, 2020
26d74d6
fix: meta-cloud-builder yq install and cb job dir
jthegedus Jun 3, 2020
f119c6e
feat: trigger-sync
jthegedus Jun 8, 2020
1a1ddce
fix: lint dir for trigger-sync builder
jthegedus Jun 8, 2020
c7d3f9e
fix: ci for trigger sync builder
jthegedus Jun 8, 2020
3ff8a90
fix: ci trigger for trigger-sync builder
jthegedus Jun 8, 2020
5bff466
fix: use .bash suffix for meta cloud builder entrypoint script
jthegedus Jun 8, 2020
4a7baca
fix: shellcheck .bash files
jthegedus Jun 8, 2020
2fcb358
fix: pass array to function bug
jthegedus Jun 8, 2020
a80c813
ci: uplift test to build file
jthegedus Jun 8, 2020
8484802
fix: required env var check
jthegedus Jun 8, 2020
cc264da
fix: test trigger names
jthegedus Jun 8, 2020
0a44831
fix: array expansion error
jthegedus Jun 8, 2020
ab0ede2
fix: unbound array elements
jthegedus Jun 8, 2020
ea370c6
fix: rm set unbound
jthegedus Jun 8, 2020
fe26ef1
ci: test more cases
jthegedus Jun 8, 2020
8d6662b
ci: test more edge cases
jthegedus Jun 8, 2020
aaa3666
fix: improve logging
jthegedus Jun 8, 2020
c2e6e85
fix: test with no triggers
jthegedus Jun 8, 2020
422f55f
fix: bash struct mode unbound
jthegedus Jun 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
tags:
- "meta-triggers"

steps:
- name: gcr.io/$PROJECT_ID/cancelot
id: "Cancelot"
Expand All @@ -13,4 +16,3 @@ steps:
- "Cancelot"
args:
- .cicd
tags: ["meta-triggers"]
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
tags:
- "cloud-builders"

steps:
- name: gcr.io/$PROJECT_ID/cancelot
id: "Cancelot"
Expand All @@ -15,4 +18,3 @@ steps:
- ".cicd/builders/custom-builders.yaml"
- "--timeout=900"
- "--async"
tags: ["cloud-builders"]
30 changes: 30 additions & 0 deletions .cicd/jobs/lint.cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
tags:
- "lint"

steps:
- name: gcr.io/$PROJECT_ID/cancelot
id: "Cancelot"
waitFor:
- "-"
args:
- "--current_build_id"
- "$BUILD_ID"
- "--branch_name"
- "$BRANCH_NAME"
- "--same_trigger_only"

- name: gcr.io/$PROJECT_ID/shellcheck
id: "Lint: Shellcheck"
waitFor:
- "Cancelot"
args:
- ./meta-cloud-builder/run.bash
- ./trigger-sync/run.bash

- name: mvdan/shfmt:latest-alpine
id: "Lint: shell format"
waitFor:
- "Cancelot"
args:
- "-d"
- "."
17 changes: 0 additions & 17 deletions .cicd/lint.cloudbuild.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions .cicd/triggers/build-meta-triggers.trigger.yaml

This file was deleted.

10 changes: 10 additions & 0 deletions .cicd/triggers/build-trigger-sync.trigger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: build-trigger-sync
description: "Build trigger-sync builder on change"
github:
owner: jthegedus
name: meta-cloud-builders
pullRequest:
branch: .*
filename: trigger-sync/cloudbuild.yaml
includedFiles:
- trigger-sync/**
2 changes: 1 addition & 1 deletion .cicd/triggers/lint.trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ github:
name: meta-cloud-builders
pullRequest:
branch: .*
filename: .cicd/lint.cloudbuild.yaml
filename: .cicd/jobs/lint.cloudbuild.yaml
4 changes: 2 additions & 2 deletions .cicd/triggers/run-meta-builder.trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ github:
name: meta-cloud-builders
push:
branch: master
filename: .cicd/build-custom-builders.cloudbuild.yaml
filename: .cicd/jobs/build-custom-builders.cloudbuild.yaml
includedFiles:
- .cicd/build-custom-builders.cloudbuild.yaml # the Cloud Build job file
- .cicd/jobs/build-custom-builders.cloudbuild.yaml # the Cloud Build job file
- .cicd/builders/custom-builders.yaml # the config file
2 changes: 1 addition & 1 deletion .cicd/triggers/run-meta-triggers.trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ github:
name: meta-cloud-builders
push:
branch: master
filename: .cicd/apply-triggers.cloudbuild.yaml
filename: .cicd/jobs/apply-triggers.cloudbuild.yaml
includedFiles:
- .cicd/**
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[*]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true

[*.bash]
indent_style = tab
indent_size = 4
end_of_line = lf
insert_final_newline = true
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ github:
branch: master
filename: .cicd/builders.cloudbuild.yaml
includedFiles:
- .cicd/builders.cloudbuild.yaml # the Cloud Build job file
- .cicd/builders.cloudbuild.yaml # the Cloud Build job file
- .cicd/builders/custom-builders.yaml # the config file
```

Expand Down Expand Up @@ -108,6 +108,7 @@ gcloud scheduler jobs create http \
Just fill in `PROJECTID`, `TRIGGERID` and create a Service Account and fill in the `EMAIL_ADDRESS` accordingly.

Suggested schedule intervals:

- daily: `0 0 * * *`
- every sunday: `0 0 * * SUN`

Expand Down
24 changes: 18 additions & 6 deletions meta-cloud-builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
FROM gcr.io/cloud-builders/git
# hadolint ignore=DL3007
FROM gcr.io/cloud-builders/git:latest

ENV JQ_VERION="1.5+dfsg-1ubuntu0.1"
ENV YQ_VERSION="3.3.0"
ENV WGET_VERSION="1.17.1-1ubuntu1.5"

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# setup jq
RUN apt-get -qq -y update \
&& apt-get -qq -y install jq
&& apt-get -qq -y --no-install-recommends install "jq=${JQ_VERION}" "wget=${WGET_VERSION}" \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

ADD yq /usr/bin
# setup yq
RUN wget -qO- "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" > /usr/bin/yq
RUN chmod +x /usr/bin/yq

ADD run.sh /usr/bin
RUN chmod +x /usr/bin/run.sh
# setup entrypoint script
COPY run.bash /usr/bin
RUN chmod +x /usr/bin/run.bash

ENTRYPOINT [ "/usr/bin/run.sh" ]
ENTRYPOINT [ "/usr/bin/run.bash" ]
12 changes: 10 additions & 2 deletions meta-cloud-builder/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
tags:
- "cloud-builders-community"
- "meta-cloud-builder"

steps:
- name: gcr.io/cloud-builders/docker
id: "Build: meta builder image"
waitFor:
- "-"
args: ["build", "-t", "gcr.io/$PROJECT_ID/meta-cloud-builder", "."]
args:
- "build"
- "-t"
- "gcr.io/$PROJECT_ID/meta-cloud-builder"
- "meta-cloud-builder"

images:
- gcr.io/$PROJECT_ID/meta-cloud-builder
tags: ["cloud-builders-community"]
44 changes: 44 additions & 0 deletions meta-cloud-builder/run.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

config_file=""
workspace_dir="/workspace/builder_repos"

if [ ! -f "$1" ]; then
printf "[error] first arg should be a config file. File %s does NOT exist\n" "$1"
exit 1
fi

if [[ "$1" == *.yaml ]]; then
printf "[info] converting .yaml file to .json\n"
yq r -j "$1" >"${1%.yaml}.json"
config_file="${1%.yaml}.json"
else
config_file="$1"
fi

if [[ "$config_file" != *.json ]]; then
printf "[error] invalid config file %s File must be .json or .yaml\n" "$config_file"
exit 1
fi

printf "[info] loading from config file: %s\n" "$config_file"

# for each repo, clone to workspace
jq -r '.[] | .repo' "$config_file" |
while read -r url; do
printf "[info] cloning repo %s\n" "$url"
final_path="${url//https:\/\/github.com\//}"
git clone "$url" "$workspace_dir/$final_path"

# for each builder in the config for this repo, build with gcloud
jq -r --arg repository "$url" '.[] | select(.repo == $repository) | .builders | .[]' "$config_file" |
while read -r builder; do
printf "\n[info] building %s\n" "$builder"
set -x
gcloud builds submit \
"${@:2}" \
--config "$workspace_dir/$final_path/$builder/cloudbuild.yaml" \
"$workspace_dir/$final_path/$builder"
set +x
done
done
44 changes: 0 additions & 44 deletions meta-cloud-builder/run.sh

This file was deleted.

5 changes: 4 additions & 1 deletion meta-cloud-builder/test/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
tags:
- "cloud-builders-community"
- "test"

steps:
# sanity check
- name: gcr.io/$PROJECT_ID/meta-cloud-builder
Expand Down Expand Up @@ -38,4 +42,3 @@ steps:
- list
- --filter
- cache
tags: ["cloud-builders-community", "test"]
16 changes: 8 additions & 8 deletions meta-cloud-builder/test/test-config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[
{
"builders": [
"cancelot",
"cache"
],
"repo": "https://github.com/GoogleCloudPlatform/cloud-builders-community"
}
]
{
"builders": [
"cancelot",
"cache"
],
"repo": "https://github.com/GoogleCloudPlatform/cloud-builders-community"
}
]
Binary file removed meta-cloud-builder/yq
Binary file not shown.
12 changes: 0 additions & 12 deletions meta-triggers/Dockerfile

This file was deleted.

9 changes: 0 additions & 9 deletions meta-triggers/cloudbuild.yaml

This file was deleted.

Loading