-
Notifications
You must be signed in to change notification settings - Fork 74
/
main.workflow
86 lines (75 loc) · 2.33 KB
/
main.workflow
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
workflow "Build and Deploy" {
on = "push"
resolves = [
"Verify GKE deployment",
]
}
# Build
action "Build Docker image" {
uses = "actions/docker/cli@master"
args = ["build", "-t", "gcloud-example-app", "."]
}
# Deploy Filter
action "Deploy branch filter" {
needs = ["Set Credential Helper for Docker"]
uses = "actions/bin/filter@master"
args = "branch master"
}
# GKE
action "Setup Google Cloud" {
uses = "actions/gcloud/auth@master"
secrets = ["GCLOUD_AUTH"]
}
action "Tag image for GCR" {
needs = ["Setup Google Cloud", "Build Docker image"]
uses = "actions/docker/tag@master"
env = {
PROJECT_ID = "fifth-byte-211221"
APPLICATION_NAME = "gcloud-example-app"
}
args = ["gcloud-example-app", "gcr.io/$PROJECT_ID/$APPLICATION_NAME"]
}
action "Set Credential Helper for Docker" {
needs = ["Setup Google Cloud", "Tag image for GCR"]
uses = "actions/gcloud/cli@master"
args = ["auth", "configure-docker", "--quiet"]
}
action "Push image to GCR" {
needs = ["Setup Google Cloud", "Deploy branch filter"]
uses = "actions/gcloud/cli@master"
runs = "sh -c"
env = {
PROJECT_ID = "fifth-byte-211221"
APPLICATION_NAME = "gcloud-example-app"
}
args = ["docker push gcr.io/$PROJECT_ID/$APPLICATION_NAME"]
}
action "Load GKE kube credentials" {
needs = ["Setup Google Cloud", "Push image to GCR"]
uses = "actions/gcloud/cli@master"
env = {
PROJECT_ID = "fifth-byte-211221"
CLUSTER_NAME = "workflow-example-cluster"
}
args = "container clusters get-credentials $CLUSTER_NAME --zone us-central1-a --project $PROJECT_ID"
}
# TODO Add Action to start GitHub Deploy
action "Deploy to GKE" {
needs = ["Push image to GCR", "Load GKE kube credentials"]
uses = "docker://gcr.io/cloud-builders/kubectl"
env = {
PROJECT_ID = "fifth-byte-211221"
APPLICATION_NAME = "gcloud-example-app"
DEPLOYMENT_NAME = "app-example"
}
runs = "sh -l -c"
args = ["SHORT_REF=$(echo ${GITHUB_SHA} | head -c7) && cat $GITHUB_WORKSPACE/config.yml | sed 's/PROJECT_ID/'\"$PROJECT_ID\"'/' | sed 's/APPLICATION_NAME/'\"$APPLICATION_NAME\"'/' | sed 's/TAG/'\"$SHORT_REF\"'/' | kubectl apply -f - "]
}
action "Verify GKE deployment" {
needs = ["Deploy to GKE"]
uses = "docker://gcr.io/cloud-builders/kubectl"
env = {
DEPLOYMENT_NAME = "app-example"
}
args = "rollout status deployment/app-example"
}