Created
September 14, 2020 17:46
-
-
Save m4r10k/08298b958b6d083c21e2354387406dbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export TERM=ansi | |
export BASEPATH=kploy | |
export CUSTOMIZEPATH=kploy-customize | |
# Kubernetes deploy | |
# Export the provided image name as IMAGE | |
export IMAGE=$1 | |
# If the kploy_deploy_template is not set, exit | |
{{ if not (has (ds "data") "kploy_deploy_template")}} | |
echo "KPLOY_DEPLOY_TEMPLATE NOT SET" | |
exit 1 | |
{{end}} | |
# Create the result folder which will be transmitted to k8s-deployer | |
mkdir ./tmp/artifact | |
# Process environment config | |
echo "Processing environment config" | |
echo "------------------------------------" | |
./gomplate -f ./$BASEPATH/deploy_type/{{ (ds "data").kploy_deploy_template }}/environments/{{(ds "data").kploy_environment }}.yaml -o ./tmp/environment.yaml | |
# Process customize files | |
if [ -d ../$CUSTOMIZEPATH/yaml ]; then | |
# Processing custom template deployment files | |
echo "Processing custom template deployment files" | |
echo "-------------------------------------------" | |
./gomplate --input-dir=../$CUSTOMIZEPATH/yaml --output-dir=./tmp/$CUSTOMIZEPATH/yaml -d config=./tmp/environment.yaml -d data=../$CUSTOMIZEPATH/data.yaml | |
FILES=./tmp/$CUSTOMIZEPATH/yaml/*.yaml | |
# Copy processed files to artifact folder | |
echo "Copy custom result files to artifact folder" | |
echo "-------------------------------------------" | |
for f in $FILES | |
do | |
cp -n -v $f ./tmp/artifact/ | |
done | |
echo "--------------------------------------" | |
fi | |
# Processing template deployment files | |
echo "Processing template deployment files" | |
echo "------------------------------------" | |
./gomplate --input-dir=$BASEPATH/deploy_type/{{ (ds "data").kploy_deploy_template }}/components/{{(ds "data").kploy_environment }} --output-dir=./tmp/{{ (ds "data").kploy_environment }} -d config=./tmp/environment.yaml -d data=../$CUSTOMIZEPATH/data.yaml | |
# Apply all genereated Kubernetes yaml files | |
echo "Copy template result files to artifact folder" | |
echo "--------------------------------------------" | |
FILES=./tmp/{{ (ds "data").kploy_environment }}/*.yaml | |
for f in $FILES | |
do | |
cp -n -v $f ./tmp/artifact/ | |
done | |
echo "--------------------------------------" | |
# create the artifact tar ball | |
tar -zcvf ./tmp/artifact.tar.gz ./tmp/artifact/ | |
tput setaf 2 | |
echo "apikey: {{(ds "data").k8s_deployer_apikey }} dryrun: {{(ds "data").kploy_dry_run}}" | |
response=$(curl -i -s -H "apikey: {{(ds "data").k8s_deployer_apikey }}" -H "dryrun: {{(ds "data").kploy_dry_run}}" -XPUT {{(ds "data").k8s_deployer_endpoint}} -F "file=@./tmp/artifact.tar.gz") | |
echo "$response" | |
tput sgr0 | |
# copy script over to tmp to save it in artifact | |
tput setaf 3 | |
mv -v ./run.sh tmp/ | |
tput sgr0 | |
# check the response code | |
response_code=$(echo $response | head -n 1 | grep -c 200) | |
if [ "$response_code" == "1" ]; then | |
exit 0 | |
else | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment