This repository was archived by the owner on Jun 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild-test-deploy.dhall
More file actions
138 lines (125 loc) · 4.12 KB
/
build-test-deploy.dhall
File metadata and controls
138 lines (125 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
let map =
https://raw.githubusercontent.com/dhall-lang/dhall-lang/0a7f596d03b3ea760a96a8e03935f4baa64274e1/Prelude/List/map -- import the dhall map function from github
let Types = ./types.dhall -- the file that defines the GoCD YAML types
let Service = ./service.dhall -- an type definition specific to this example
let variables = ./variables.dhall
let util = ./util.dhall
--
-- Build the project
--
-- the steps that it takes to build this example project
let buildTasks
: Service → List Types.Task
= λ(service : Service)
→ [ Types.Task.Script { script = "echo 'starting to build ${service.name}'" }
, Types.Task.Script { script = "./scripts/build.sh ${service.name}" }
]
-- Your build artifact. In this example it's a git SHA from written to a file by `./scripts/build.sh`
let versionArtifact : Service -> Optional (List Types.Artifact) =
λ(service : Service) ->
Some [ { build = { source = "${service.name}-version.txt", destination = "artifact-dir" } } ]
-- Wrap these up in a GoCD job
let buildJob
: Service → Types.Job
= λ(service : Service)
-> util.createJob service.name (buildTasks service) (versionArtifact service) variables.elastic_profile_id
--
-- Test the project
--
-- The "tests" that are run
let testTasks
: Service → List Types.Task
= λ(service : Service)
→ [ Types.Task.Script { script = "echo 'testing ${service.name}'" }
, Types.Task.Script { script = "./scripts/test.sh" }
]
-- The test results file
let testArtifact = Some [ { build = { source = "test-results.txt", destination = "artifact-dir" } } ]
-- Wrap these up in a GoCD job
let testJob
: Service → Types.Job
= λ(service : Service)
-> util.createJob service.name (testTasks service) testArtifact variables.elastic_profile_id
--
-- Deploy the project
--
-- Grabs the version from the build job and then runs the deploy script
let deployTasks
: Service → List Types.Task
= λ(service : Service)
→ [ Types.Task.Fetch
{ fetch =
{ pipeline = "${service.name}-release"
, stage = "build"
, job = "${service.name}"
, source = "artifact-dir/${service.name}-version.txt"
, is_file = True
}
}
, Types.Task.Script { script = "echo 'deploying ${service.name}'" }
, Types.Task.Script { script = "./scripts/deploy.sh ${service.name}" }
]
-- Wrap these up in a GoCD job
let deployJob
: Service → Types.Job
= λ(service : Service)
-> util.createJob service.name (deployTasks service) (versionArtifact service) variables.elastic_profile_id
-- function that takes a Service (like from the list in `./variables.dhall`) and
-- and returns a GoCD pipeline
let mkPipelines : Service → Types.Pipeline =
λ(service : Service) →
{ mk = "${service.name}-release"
, mv =
{ stages =
[ [ { mk = "build"
, mv =
{ clean_workspace = False
, approval = util.autoApproval
, jobs =
[ buildJob service ]
}
}
]
, [ { mk =
"test"
, mv =
{ clean_workspace = False
, approval = util.autoApproval
, jobs =
[ testJob service ]
}
}
]
, [ { mk =
"deploy"
, mv =
{ clean_workspace = False
, approval = util.autoApproval
, jobs =
[ deployJob service ]
}
}
]
]
, group = service.name
, environment_variables = None Types.ListKV
, parameters = None Types.ListKV
, materials =
[ { mk = "${service.name}-repo"
, mv =
Types.Material.Source
{ git = service.repo
, branch = "master"
, destination = None Text
, auto_update = True
}
}
]
}
}
-- map over the list of services, and create a pipeline for each
let pipelines =
map Service Types.Pipeline mkPipelines variables.services
# [./end-to-end-test.dhall]
-- export the finished pipelines
in pipelines