-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrone-plugin.sh
More file actions
84 lines (71 loc) · 2.8 KB
/
Copy pathdrone-plugin.sh
File metadata and controls
84 lines (71 loc) · 2.8 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
#!/busybox/sh
set -euo pipefail
#Prepare parameters to be used
if [[ "${PLUGIN_YAML:-}" ]]; then
OF_YAML="--yaml ${PLUGIN_YAML}"
elif [ -f stack.yml ]; then
OF_STACK_YAML="stack.yml"
fi
if [[ "${PLUGIN_TLS_NO_VERIFY:-}" == "true" ]]; then
OF_TLS_NO_VERIFY="--tls-no-verify"
KA_OPTIONS="--skip-tls-verify=true"
fi
if [[ "${PLUGIN_USERNAME:-}" ]]; then
OF_USERNAME="--username ${PLUGIN_USERNAME}"
fi
if [[ "${PLUGIN_TAG:-}" ]]; then
OF_TAG="--tag=${PLUGIN_TAG}"
fi
if [[ "${PLUGIN_IMAGE_NAME:-}" && "${PLUGIN_REGISTRY:-}" ]]; then
OF_IMAGE="--image=${PLUGIN_REGISTRY}/${PLUGIN_IMAGE_NAME}"
if [[ "${PLUGIN_YAML:-}" || "${OF_STACK_YAML:-}"]]; then
OF_IMAGE_NAME_FULL="${PLUGIN_REGISTRY}/${PLUGIN_IMAGE_NAME}"
sed -ie 's/\([[:space:]]*image: *\).*/\1${OF_IMAGE_NAME_FULL}/1' ${PLUGIN_YAML:-}${OF_STACK_YAML:-}
fi
fi
if [[ "${PLUGIN_FUNCTION_NAME:-}" ]]; then
OF_FUNCTION_NAME="${PLUGIN_FUNCTION_NAME}"
else
echo "ERROR: Must provide a OpenFaaS Functions Name (function_name parameter)"
exit 1
fi
if [[ "${PLUGIN_URL:-}" ]]; then
OF_URL="--gateway ${PLUGIN_URL}"
fi
#
#Executing commands!!!
#
#Pull store template if needed
echo "Fetching OpenFaaS Template..."
if [[ "${PLUGIN_TEMPLATE:-}" ]]; then
/usr/local/bin/faas-cli template store pull "${PLUGIN_TEMPLATE}"
else
/usr/local/bin/faas-cli template pull https://github.com/openfaas/templates.git
fi
#Generate Step
echo "Generating Build Files..."
/usr/local/bin/faas-cli build ${OF_YAML:-} --shrinkwrap
#Build & Push Step
echo "Building a Publishing docker image with Kaniko..."
if [[ "${PLUGIN_REGISTRY_USERNAME:-}" && "${PLUGIN_REGISTRY_PASSWORD:-}" && "${PLUGIN_REGISTRY:-}" ]]; then
DOCKER_AUTH="{\"auths\":{\"${PLUGIN_REGISTRY}\":{\"username\":\"${PLUGIN_REGISTRY_USERNAME}\",\"password\":\"${PLUGIN_REGISTRY_PASSWORD}\"}}}"
cat ${DOCKER_AUTH} > /kaniko/.docker/config.json
/kaniko/executor -v info \
--context=./build/${OF_FUNCTION_NAME} \
--dockerfile=./build/${OF_FUNCTION_NAME}/Dockerfile \
--destination=${OF_IMAGE_NAME_FULL} \
${KA_OPTIONS:-}
else
echo "ERROR: Must provide a Docker Registry Username (registry_username or plugin_registry_username secret) and Password (registry_password or plugin_registry_password secret) parameters to Build and Pushish a Docker Image"
exit 1
fi
#Deploy Step
if [[ -n "${PLUGIN_PASSWORD:-}" && -n "${PLUGIN_URL:-}" ]]; then
#Login to OpenFaaS Gateway
echo ${PLUGIN_PASSWORD} | /usr/local/bin/faas-cli login ${OF_USERNAME:-} --password-stdin ${OF_URL:-} ${TLS_NO_VERIFY:-}
#Deploy the function
/usr/local/bin/faas-cli deploy ${OF_YAML:-} ${OF_URL} ${OF_IMAGE:-} ${OF_TAG:-}
else
echo "ERROR: Must provide a OpenFaaS Gateway URL (url or plugin_url secret) and Password (password or plugin_password secret) parameters to Deploy"
exit 1
fi