-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
187 lines (163 loc) · 5.73 KB
/
Taskfile.yml
File metadata and controls
187 lines (163 loc) · 5.73 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
---
version: '3'
silent: true
env:
ENV: .local/dev
PROFILE: '{{.PROFILE | default ""}}'
# This override is provided so that the generate task can be used to
# quick start consumers of this repository with useful defaults.
K8S_GENERATE_DIR: '{{.K8S_GENERATE_DIR | default "k8s/tmp"}}'
vars:
BUILD_ARTIFACTS: k8s/tmp/skaffold/build-artifacts.json
dotenv: [".env.app", ".env", '{{.ENV}}/.env', '{{.HOME}}/.env']
tasks:
bootstrap:
desc: |
creates the {{.ENV}}/.env file and installs tooling. assumes a debain
like system (but uses python or brew where possible). for other platforms
run `task bootstrap --sumarize` and use the results to find the right
bits. Note that .env (in the directory containing this Taskfile) is
never created or touched in anyway and has the highest precedence
NOTICE: to re-create {{.ENV}}/.env you MUST delete it first (else it will
be re-created with the same values
cmds:
- |
mkdir -p {{.ENV}}
CONTEXT=${CONTEXT:-$(kubectl config current-context)}
CLUSTER=$(kubectl config get-contexts ${CONTEXT} --no-headers=true | tr -s ' ' | cut -d ' ' -f3)
SKAFFOLD_DEFAULT_REPO=${SKAFFOLD_DEFAULT_REPO:-eu.gcr.io/${CONTEXT}}
CONTEXT_NAMESPACE=${CONTEXT_NAMESPACE:-$(echo ${CONTEXT} | cut -d '-' -f1)}
NAMESPACE=${NAMESPACE:-${CONTEXT_NAMESPACE}-${APPNAME}}
DOMAIN=${DOMAIN:-localhost}
cat <<EOF > {{.ENV}}/.env
CONTEXT=${CONTEXT}
CLUSTER=${CLUSTER}
SKAFFOLD_DEFAULT_REPO=${SKAFFOLD_DEFAULT_REPO}
CONTEXT_NAMESPACE=${CONTEXT_NAMESPACE}
NAMESPACE=${NAMESPACE}
APPNAME=${APPNAME}
PYENV=${PYENV}
PORT=${PORT}
HOST=${HOST}
DOMAIN=${DOMAIN}
EOF
env:
CONTEXT: "{{.CONTEXT}}"
CONTEXT_NAMESPACE: "{{.CONTEXT_NAMESPACE}}"
NAMESPACE: "{{.NAMESPACE}}"
TAG: "{{.TAG}}"
SKAFFOLD_DEFAULT_REPO: "{{.SKAFFOLD_DEFAULT_REPO}}"
APPNAME: '{{.APPNAME | default "chaintrap-maptool"}}'
PYENV: '{{.PYENV | default "env"}}'
PROFILE: '{{.PROFILE | default "local"}}'
PORT: '{{.PORT | default "8000"}}'
HOST: '{{.HOST | default "http://127.0.0.1:8000"}}'
DOMAIN: '{{.DOMAIN | default "localhost"}}'
generate:
desc: 'generate context dependent manifests and secrets and so on'
cmds:
- |
mkdir -p {{.K8S_GENERATE_DIR}}/dev
mkdir -p $(dirname {{.BUILD_ARTIFACTS}})
cat <<EOF > {{.K8S_GENERATE_DIR}}/dev/namespace.yaml
kind: Namespace
apiVersion: v1
metadata:
name: ${NAMESPACE}
EOF
cat <<EOF > {{.K8S_GENERATE_DIR}}/dev/kustomization.yaml
namespace: ${NAMESPACE}
resources:
- ./namespace.yaml
- ./../../$APPNAME
EOF
generates:
- "{{.K8S_GENERATE_DIR}}/dev/kustomization.yaml"
- "{{.K8S_GENERATE_DIR}}/dev/namespace.yaml"
build:
desc: 'build the images'
cmds:
- |
skaffold build \
${PROFILE:+-p $PROFILE} \
${TAG:+-t $TAG} \
--file-output {{.BUILD_ARTIFACTS}}
vars:
TAG: '{{.TAG | default (env "TAG") }}'
PROFILE: '{{.PROFILE | default ""}}'
cd-build:
desc: "cd entry point for build (runs generate)"
cmds:
- task: generate
- task: build
helm:test:
desc: "update dependencies and do a test render of the helm charts"
cmds:
- |
helm dependency update helm/chaintrap
helm template chaintrap-$USER helm/chaintrap \
-f helm/chaintrap/project-values.yaml \
-f helm/chaintrap/subsystem-values.yaml \
-f ../ops/hoy-charts/values/platforms/hoy/values.yaml --debug
local:run:
desc: "run the service in local development mode (localhost:8000)"
cmds:
- |
pipenv run uvicorn service.main:app --reload --log-level debug
run:
desc: 'run deploy the app using skaffold'
cmds:
- |
helm dependency update helm/${APPNAME}
skaffold run --namespace ${APPNAME}-$USER
down:
desc: 'delete the resources created by skaffold run'
cmds:
- |
skaffold delete --namespace ${APPNAME}-$USER
deploy:
desc: 'deploy the app using skaffold'
precondition:
- test: -f {{.BUILD_ARTIFACTS}}
msg: "{{.BUILD_ARTIFACTS}} is missing, run `task build` first"
cmds:
- |
skaffold deploy \
${CONTEXT:+--kube-context ${CONTEXT}} \
${NAMESPACE:+-n $NAMESPACE} \
--label=user-deploy=$USER-$APPNAME \
--build-artifacts {{.BUILD_ARTIFACTS}}
down:
desc: 'take the app down and clean up the k8s resources'
cmds:
- |
# -l skaffold.dev/run-id=1ea50cc3-294e-499b-ad59-876378d59ee7
for resource in $(kubectl api-resources --verbs=list --namespaced -o name); do
for target in $(kubectl get \
--show-kind \
-l user-deploy=$USER-$APPNAME \
--ignore-not-found \
-n $NAMESPACE \
-o name ${resource} 2> /dev/null); do
echo $target
kubectl delete $target -n $NAMESPACE
done
done
pf:
desc: 'port forward to $APPNAME'
cmds:
- |
POD=$($KUBECTL -n $NAMESPACE get pod \
--selector=app=$APPNAME \
--no-headers -o custom-columns=":metadata.name")
$KUBECTL -n $NAMESPACE port-forward pod/$POD $PORT
logs:
desc: 'port forward to $APPNAME'
cmds:
- |
POD=$($KUBECTL -n $NAMESPACE get pod \
--selector=app=$APPNAME \
--no-headers -o custom-columns=":metadata.name")
echo $POD
# {{.KUBECTL}} -n {{.N}} port-forward --address localhost pod/$POD 8080
$KUBECTL -n $NAMESPACE logs $POD {{.CLI_ARGS}}