-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (152 loc) · 6.93 KB
/
deploy-command.yml
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: deploy-command
on:
workflow_dispatch:
inputs:
repository-name:
description: "The name of the repository from which the slash command was dispatched"
required: true
repository-owner:
description: "The owner of the repository from which the slash command was dispatched"
required: true
issue-number:
description: "The issue number in which the slash command was made"
required: true
html-url:
description: "URL where comment was created"
required: true
comment-id:
description: "ID of comment with deploy command"
required: true
chart-name:
description: "Name of Helm chart"
required: true
cluster:
description: "The cluster to deploy to"
required: true
commit:
description: "Commit ID to deploy"
required: false
branch:
description: "Branch to deploy"
required: false
jobs:
prepare-deploy:
runs-on: ubuntu-latest
name: Prepare for deployment
steps:
- name: download and setup path for github actions binary
run: |
mkdir -p github-actions/bin
curl -L -o github-actions/bin/actions https://github.com/dictybase-docker/github-actions/releases/download/v2.3.0/action_2.3.0_Linux_x86_64
chmod +x github-actions/bin/actions
echo "$GITHUB_WORKSPACE/github-actions/bin" >> $GITHUB_PATH
- name: parse deploy command and set vars
id: vars
run: actions --log-level debug pcd -f ${GITHUB_EVENT_PATH}
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
repository: ${{ github.event.inputs.repository-owner }}/${{ github.event.inputs.repository-name }}
ref: ${{ steps.vars.outputs.ref }}
- name: set up docker buildx
uses: docker/setup-buildx-action@v2
- name: cache docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ steps.vars.outputs.ref }}
restore-keys: |
${{ runner.os }}-buildx-
- name: login to dockerhub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: docker build and push
uses: docker/build-push-action@v3
with:
push: true
context: .
file: build/package/Dockerfile
tags: dictybase/${{ github.event.inputs.repository-name }}:${{ steps.vars.outputs.image_tag }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: prepare for deploy
if: ${{ success() }}
id: prepare_deploy
uses: dictybase-docker/prepare-deploy@v2
with:
owner: ${{ github.event.inputs.repository-owner }}
repo: ${{ github.event.inputs.repository-name }}
cluster-name: ${{ github.event.inputs.cluster }}
cluster-zone: "us-central1-a"
namespace: dictybase
chart-name: ${{ github.event.inputs.chart-name }}
chart-path: dictybase/${{ github.event.inputs.chart-name }}
token: ${{ secrets.REPO_ACCESS_TOKEN }}
image-tag: ${{ steps.vars.outputs.image_tag }}
ref: ${{ steps.vars.outputs.ref }}
artifact: ${{ github.event.inputs.repository-name }}
environment: ${{ github.event.inputs.cluster }}
deploy:
runs-on: ubuntu-latest
needs: prepare-deploy
steps:
- name: check out code
uses: actions/checkout@v3
- name: download deployment artifact
uses: actions/download-artifact@v3
with:
name: ${{ github.event.inputs.repository-name }}
- name: download and setup path for github action binary
run: |
mkdir -p github-actions/bin
curl -L -o github-actions/bin/actions https://github.com/dictybase-docker/github-actions/releases/download/v2.1.4/action_2.1.4_Linux_x86_64
chmod +x github-actions/bin/actions
echo "$GITHUB_WORKSPACE/github-actions/bin" >> $GITHUB_PATH
- name: extract information from deployment payload
id: deploy_info
run: actions --log-level debug sdp -f deployment.json
- name: set in_progress deployment status
if: ${{ success() }}
run: actions --log-level debug -t ${{ secrets.REPO_ACCESS_TOKEN }} --owner ${{ github.event.inputs.repository-owner }} -r ${{ github.event.inputs.repository-name }} ds --state in_progress --deployment_id ${{ steps.deploy_info.outputs.id }} --url ${{ steps.deploy_info.outputs.url }}
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v0'
with:
credentials_json: ${{ secrets.DEVENV_SA_KEY }}
- name: setup google cloud sdk
uses: google-github-actions/setup-gcloud@v0
with:
project_id: ${{ secrets.DEVENV_PROJECT_ID }}
- name: set up helm
uses: azure/setup-helm@v3
with:
version: "v2.16.12"
- name: add dictybase helm repo
run: helm init --client-only --stable-repo-url https://charts.helm.sh/stable && helm repo add dictybase https://dictybase-docker.github.io/kubernetes-charts
- name: get gcloud credentials for k8s cluster
run: gcloud container clusters get-credentials --project ${{ secrets.DEVENV_PROJECT_ID }} --zone ${{ steps.deploy_info.outputs.zone }} ${{ steps.deploy_info.outputs.cluster }}
- name: deploy chart
if: ${{ success() }}
run: actions --log-level debug dc --name ${{ steps.deploy_info.outputs.chart }} --namespace ${{ steps.deploy_info.outputs.namespace }} --image-tag ${{ steps.deploy_info.outputs.image_tag }} --path ${{ steps.deploy_info.outputs.path }}
- name: set successful deploy status
if: ${{ success() }}
run: actions --log-level debug -t ${{ secrets.REPO_ACCESS_TOKEN }} --owner ${{ github.event.inputs.repository-owner }} -r ${{ github.event.inputs.repository-name }} ds --state success --deployment_id ${{ steps.deploy_info.outputs.id }} --url ${{ steps.deploy_info.outputs.url }}
- name: set unsuccessful deploy status
if: ${{ failure() }}
run: actions --log-level debug -t ${{ secrets.REPO_ACCESS_TOKEN }} --owner ${{ github.event.inputs.repository-owner }} -r ${{ github.event.inputs.repository-name }} ds --state error --deployment_id ${{ steps.deploy_info.outputs.id }} --url ${{ steps.deploy_info.outputs.url }}
add-reaction:
runs-on: ubuntu-latest
needs: deploy
steps:
- name: Add reaction
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
repository: ${{ github.event.inputs.repository-owner }}/${{ github.event.inputs.repository-name }}
comment-id: ${{ github.event.inputs.comment-id }}
reactions: hooray
body: |
Deployed successfully