-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathDispatchfile
More file actions
124 lines (110 loc) · 4.91 KB
/
Dispatchfile
File metadata and controls
124 lines (110 loc) · 4.91 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
#!mesosphere/dispatch-starlark:v0.6
load("github.com/mesosphere/dispatch-catalog/starlark/stable/pipeline@master", "image_resource", "push", "pull_request")
load("github.com/mesosphere/dispatch-catalog/starlark/stable/git@master", "git_resource")
load("github.com/mesosphere/dispatch-catalog/starlark/stable/k8s@master", "secret_var")
load("github.com/mesosphere/dispatch-catalog/starlark/stable/kaniko@master", "kaniko")
docker_user = "cmays"
github_user = "cmays20"
sonar_url = "https://sonar.cmays-lab.com/"
drone_image = "meltwater/drone-cache:1.0.4"
common_env = [
k8s.corev1.EnvVar(name="AWS_ACCESS_KEY_ID", valueFrom=secret_var("s3-config","AWS_ACCESS_KEY_ID")),
k8s.corev1.EnvVar(name="AWS_SECRET_ACCESS_KEY", valueFrom=secret_var("s3-config","AWS_SECRET_ACCESS_KEY")),
k8s.corev1.EnvVar(name="PLUGIN_PATH_STYLE", value="true"),
k8s.corev1.EnvVar(name="PLUGIN_MOUNT", value="/root/.m2"),
k8s.corev1.EnvVar(name="PLUGIN_BUCKET", value="artifacts"),
k8s.corev1.EnvVar(name="PLUGIN_ENDPOINT", value="http://s3-us-east-1.dispatch"),
k8s.corev1.EnvVar(name="PLUGIN_REGION", value="us-east-1"),
k8s.corev1.EnvVar(name="PLUGIN_CACHE_KEY", value="hello-world")]
git = git_resource("src-git")
gitops = git_resource("src-gitops",url="https://github.com/cmays20/springboot-helloworld-dispatch-gitops",revision="master")
image_name = image_resource("docker-image",url=docker_user + "/hello-world-dispatch")
tag = "$(context.build.name)"
#Setup re-usable steps
restore_cache = k8s.corev1.Container(
name="restore-cache",
image=drone_image,
env=common_env + [k8s.corev1.EnvVar(name="PLUGIN_RESTORE", value="true")],
volumeMounts=[k8s.corev1.VolumeMount(
name="cache-minio",
mountPath="/root/.m2")])
rebuild_cache = k8s.corev1.Container(
name="rebuild-cache",
image=drone_image,
env=common_env + [k8s.corev1.EnvVar(name="PLUGIN_RESTORE", value="false"),
k8s.corev1.EnvVar(name="PLUGIN_REBUILD", value="true")],
volumeMounts=[k8s.corev1.VolumeMount(
name="cache-minio",
mountPath="/root/.m2")])
# Compile and run Unit Tests using Maven
task("test",
inputs=[git],
volumes=[k8s.corev1.Volume(name="cache-minio", volumeSource=k8s.corev1.VolumeSource(emptyDir=k8s.corev1.EmptyDirVolumeSource()))],
steps=[restore_cache,
k8s.corev1.Container(
name="test",
image="maven:3.6-jdk-8-slim",
workingDir="/workspace/src-git",
volumeMounts=[k8s.corev1.VolumeMount(
name="cache-minio",
mountPath="/root/.m2")],
command=["mvn","test"]),
rebuild_cache])
args = [
"--destination=$(resources.outputs.{}.url):{}".format(image_name, tag),
"--context=/workspace/src-git",
"--oci-layout-path=$(resources.outputs.{}.path)".format(image_name),
"--dockerfile=/workspace/src-git/Dockerfile"
]
docker_build = k8s.corev1.Container(
name="build-image",
image="gcr.io/kaniko-project/executor:v0.14.0",
args=args,
workingDir="/workspace/src-git"
)
task("build",
inputs=[git],
outputs=[image_name],
volumes=[k8s.corev1.Volume(name="cache-minio", volumeSource=k8s.corev1.VolumeSource(emptyDir=k8s.corev1.EmptyDirVolumeSource()))],
steps=[
restore_cache,
k8s.corev1.Container(
name="build",
image="maven:3.6-jdk-8-slim",
workingDir="/workspace/src-git",
volumeMounts=[k8s.corev1.VolumeMount(
name="cache-minio",
mountPath="/root/.m2")],
command=["mvn","verify"]),
rebuild_cache,
docker_build])
# Build and push the docker image
#simple_docker = kaniko("build-image",git, docker_user + "/hello-world-dispatch")
task("deploy",
inputs=[image_name, gitops],
steps=[k8s.corev1.Container(
name="update-gitops-repo",
image="mesosphere/update-gitops-repo:v1.0",
workingDir="/workspace/src-gitops",
args=[
"-git-revision=$(context.git.commit)",
"-substitute=imageName=" + docker_user + "/hello-world-dispatch@$(inputs.resources.docker-image.digest)",
"--force-push"]
)])
task("sonar",
inputs=[git],
volumes=[k8s.corev1.Volume(name="cache-minio", volumeSource=k8s.corev1.VolumeSource(emptyDir=k8s.corev1.EmptyDirVolumeSource()))],
steps=[
restore_cache,
k8s.corev1.Container(
name="sonar",
image="maven:3.6-jdk-8-slim",
workingDir="/workspace/src-git",
volumeMounts=[k8s.corev1.VolumeMount(
name="cache-minio",
mountPath="/root/.m2")],
command=["mvn","verify", "sonar:sonar", "-Dsonar.host.url=" + sonar_url ]),
rebuild_cache])
action(tasks=["test"], on=push(branches=["!master","*"]))
action(tasks=["build","deploy"], on=push(branches=["master"]))
action(tasks=["sonar"], on=pull_request(chatops=["sonar"]))