This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
152 lines (139 loc) · 5.49 KB
/
action.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: "Autodevops deploy"
description: "Autodevops deploy using Helm template and kapp"
inputs:
rancherProjectId:
description: "The Rancher project ID, usually secrets.RANCHER_PROJECT_ID"
required: true
rancherProjectName:
description: "The Rancher project name, usually secrets.RANCHER_PROJECT_NAME, usefull jobs that needs secrets or ci namespaces"
required: true
environment:
description: "The deployment environment (dev | preprod | prod), default to prod on version tag, preprod on master or main, else dev"
kubeconfig:
description: "The Kubernetes authentication configuration"
token:
description: "The Github authentication token"
charts:
description: "comma separated list of charts to enable as standalone"
subcharts:
description: "comma separated list of subcharts to enable as a part of the main chart"
actionName:
description: "override manifests name as manifest-$name.yaml, default to manifest-$environment.yaml"
timeout:
description: "override default kapp --wait-timeout, default to 15m0s"
cwd:
description: "working directory where is located .kw"
kubeconfigContext:
description: "override kubeconfig context, default dev or prod according to environment"
inlineValues:
description: "deep final override of values in yaml format"
inlineSet:
description: "override final values using in yaml format, supporting subkeys"
baseDomain:
description: "set base domain, usually secrets.SOCIALGOUV_BASE_DOMAIN"
registry:
description: "set docker registry uri"
outputs:
url:
description: "Main deployment URL"
value: ${{ steps.environment-url.outputs.url }}
runs:
using: "composite"
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup env
shell: bash
run: |
KW_BUILD_PATH=/tmp/autodevops
mkdir -p $KW_BUILD_PATH
PROJECT_PATH="${{ github.workspace }}/${{ inputs.cwd }}"
echo "KW_BUILD_PATH=$KW_BUILD_PATH" >> $GITHUB_ENV
echo "PROJECT_PATH=$PROJECT_PATH" >> $GITHUB_ENV
- name: Install dependencies
shell: bash
working-directory: "${{ github.action_path }}"
run: |
# yarn --immutable
yarn workspaces focus kube-workflow --production
- name: Build manifests
shell: bash
env:
KW_ENVIRONMENT: ${{ inputs.environment }}
KW_RANCHER_PROJECT_ID: ${{ inputs.rancherProjectId }}
KW_RANCHER_PROJECT_NAME: ${{ inputs.rancherProjectName }}
KW_CHARTS: ${{ inputs.charts }}
KW_SUBCHARTS: ${{ inputs.subcharts }}
KW_INLINE_VALUES: ${{ inputs.inlineValues }}
KW_INLINE_SET: ${{ inputs.inlineSet }}
KW_DEBUG: "true"
working-directory: "${{ github.action_path }}"
run: packages/workflow/bin/kube-workflow build --cwd ${{ env.PROJECT_PATH }}
- name: Archive manifest
uses: actions/upload-artifact@v2
with:
name: manifests-${{ inputs.actionName || inputs.environment }}.yaml
path: ${{ env.KW_BUILD_PATH }}/manifests.yaml
- name: Setup namespace env var
shell: bash
working-directory: ${{ env.KW_BUILD_PATH }}
run: |
NAMESPACE=$(cat manifests.yaml | yq eval-all 'select(.kind=="Namespace").metadata.name')
echo "NAMESPACE=$NAMESPACE" >> $GITHUB_ENV
- name: Notify deployment start
uses: bobheadxi/deployments@v0.4.3
id: deployment
with:
step: start
token: ${{ inputs.token }}
desc: "Deploying environment: ${{ env.NAMESPACE }}"
env: ${{ inputs.environment == 'dev' && env.NAMESPACE || inputs.environment == 'preproduction' && 'preproduction' || 'production' }}
- name: Install Kapp
uses: vmware-tanzu/carvel-setup-action@v1
with:
only: kapp
token: ${{ inputs.token }}
- name: Create kubernetes config
shell: bash
run: |
if [ -z "${{ inputs.kubeconfig }}" ]; then
exit 0
fi
mkdir -p ~/.kube
touch ~/.kube/config
echo ${{ inputs.kubeconfig }} | base64 -d > ~/.kube/config
- name: Deploy manifests
shell: bash
working-directory: "${{ github.action_path }}"
env:
KW_GIT_REPOSITORY: ${{ github.repository }}
KW_ENVIRONMENT: ${{ inputs.environment }}
KW_RANCHER_PROJECT_ID: ${{ inputs.rancherProjectId }}
KW_RANCHER_PROJECT_NAME: ${{ inputs.rancherProjectName }}
KW_KUBECONFIG_CONTEXT: ${{ inputs.kubeconfigContext }}
KW_DEPLOY_TIMEOUT: ${{ inputs.timeout }}
KW_BASE_DOMAIN: ${{ inputs.baseDomain }}
KW_REGISTRY: ${{ inputs.registry }}
run: packages/workflow/bin/kube-workflow deploy --cwd ${{ env.PROJECT_PATH }} -f ${{ env.KW_BUILD_PATH }}/manifests.yaml
- name: Define environment URL
id: environment-url
shell: bash
working-directory: ${{ env.KW_BUILD_PATH }}
run: |
HOSTS=$(cat manifests.yaml | yq eval-all '.spec.rules[] .host')
HOST=$(echo "$HOSTS" | head -n 1)
echo $HOST
echo "::set-output name=url::https://$HOST"
- name: Notify deployment end
uses: bobheadxi/deployments@v0.4.3
with:
step: finish
status: ${{ job.status }}
token: ${{ inputs.token }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env_url: ${{ steps.environment-url.outputs.url }}
- name: Debug manifests
uses: SocialGouv/actions/k8s-manifests-debug@v1
with:
token: ${{ inputs.token }}
path: ${{ env.KW_BUILD_PATH }}/manifests.yaml