Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 8724d43

Browse files
author
Allen Huang
committed
Test dynamic pipelines
1 parent 8ad8d60 commit 8724d43

4 files changed

Lines changed: 52 additions & 2 deletions

File tree

buildkite.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
steps:
2-
- command: "pwd && ls"
3-
- wait
42
- commands:
53
- "echo 'Hello World'"
64
- "docker build . -t test-image"
@@ -12,4 +10,6 @@ steps:
1210
volumes:
1311
- "/var/run/docker.sock:/var/run/docker.sock"
1412
label: "test"
13+
- wait
14+
- command: ./pipelines.sh
1515

pipelines.jsonnet

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
local workspaces = (import 'workspaces.json').workspaces;
2+
3+
local plan_job(script, ws) = {
4+
command: script + ws,
5+
key: 'plan-' + ws,
6+
label: 'plan-' + ws,
7+
};
8+
9+
local apply_job(script, ws) = {
10+
command: [script + ws],
11+
depends_on: ['plan-' + ws],
12+
};
13+
14+
local pipeline(ws) = {
15+
[ws]: {
16+
steps: [
17+
plan_job('echo terraform plan-', ws),
18+
{ block: 'apply-' + ws },
19+
apply_job('echo terraform apply-', ws),
20+
],
21+
},
22+
};
23+
24+
local generate_pipelines(pipelines) =
25+
local append(arr, i, res) =
26+
if i >= std.length(arr) then
27+
res
28+
else
29+
append(arr, i + 1, res + arr[i]) tailstrict;
30+
append(pipelines, 0, {});
31+
32+
{} + generate_pipelines([pipeline(ws) for ws in workspaces])

pipelines.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
rm -rf envs.yml
6+
jsonnet pipelines.jsonnet | yq eval -P - > envs.yml
7+
8+
envs=$(jq -r '.workspaces[]' workspaces.json)
9+
10+
for e in ${envs[@]}; do
11+
echo $e
12+
13+
yq eval ".$e" envs.yml | buildkite-agent pipeline upload
14+
done
15+

workspaces.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"workspaces": ["prod", "dev", "stg"]
3+
}

0 commit comments

Comments
 (0)