11#! /bin/bash
2- # set -x
2+
3+ version=0.6.0
34source /opt/k8comp/k8comp.conf
45
56k8comp_home=$k8comp_dir /bin
67mapping=$k8comp_dir /extras/mapping
78
8- source $k8comp_home /usage
9-
109programname=$0
1110red=" $( tput setaf 1) "
1211green=" $( tput setaf 2) "
@@ -33,6 +32,86 @@ MAIN() {
3332 fi
3433}
3534
35+ usage () {
36+ message_green "
37+ Usage: $programname [-h | pull | -p <project_name> -a <application> -e <environment> -b <git_branch>]
38+
39+ Supported formats: yaml, yml, json
40+
41+ Mandatory variables -p <project_name>
42+
43+ -h | --help : Display usage information.
44+ -p | --project <project_name> : Project name as specified on the projects folder.
45+ Configuration specified in k8comp.conf.
46+ Current projects path ${projects_path} .
47+ If only <project> or <project> and <environment> are
48+ specified the deployment will be from
49+ ${projects_path} /<project>.* file
50+
51+ -a | --application <application> : The name of the application which need to be deployed.
52+ <application> file has priority over <application> folder.
53+ If ${projects_path} /<project>/<application>.* file is present
54+ the deployment will be from that file.
55+ If there is no file in the above mentioned location the
56+ deployment will be from
57+ ${projects_path} /<project>/<application>/ folder.
58+ There are no naming restrictions for the files from
59+ ${projects_path} /<project>/<application>/ folder.
60+ If no <application> is specified in the cmd the deployment
61+ will be from ${projects_path} /<project>.* file.
62+ An application folder or file can be located also
63+ at the projects folder root. The hiera config requires
64+ changes for this to work as expected.
65+
66+ -e | --environment <environment> : The environment will be checked from hiera. If no values are
67+ found in hiera the variables will not be replaced.
68+ NOT PART OF projects FILE STRUCTURE but can be added as
69+ variable in the yaml|yml|json template.
70+ Available only in hiera
71+
72+ -l | --location <location> : The location will be checked from hiera. If no values are
73+ found in hiera the variables will not be replaced.
74+ NOT PART OF projects FILE STRUCTURE but can be added as
75+ variable in the yaml|yml|json template.
76+ Available only in hiera
77+
78+ -x | --xtra <variable> : The variable specified on the cmd run will be used to update
79+ a value on the final deployment file.
80+ This will have priority over hiera value. Is not mandatory
81+ to be specified.
82+ The format is variable=value.
83+
84+ -b | --branch <variable> : Specify a branch from where to do the deployment.
85+ It requires k8comp_environments to be
86+
87+ pull | --pull : If k8comp_environments is enabled and auto_git_pull is false
88+ use >k8comp pull< without any arguments to pull main_deployment_branch or >k8comp pull -b your_branch< for
89+ a specific git branch.
90+ For pulling via ssh make sure the private key is available
91+ on the server/container.
92+
93+ Examples:
94+ k8comp pull
95+ k8comp pull -b test_branch
96+
97+ k8comp -p project -a application -e development -b test_branch | kubectl apply -f -
98+ k8comp -p project -a application/rc
99+ k8comp -p project -e development
100+ k8comp -p project
101+
102+ k8comp -a application -e environment
103+ k8comp -a application
104+
105+ k8comp -p project -a application -e development -x var1=value1 -x var2=value2 | kubectl create -f -
106+ k8comp -p project -a application -x var1=value1 -x var2=value2 | kubectl apply -f -
107+
108+ Dry run:
109+
110+ k8comp -p project -a application -e development
111+ k8comp -p project -a application -e development -x var1=value1
112+ "
113+ }
114+
36115error () {
37116 echo -e " ${red} [ ERROR ] - $@ $( tput sgr0) "
38117}
@@ -107,6 +186,10 @@ while [ $# -gt 0 ]; do
107186 usage
108187 exit 0
109188 ;;
189+ -v|--version)
190+ echo " $version "
191+ exit 0
192+ ;;
110193 esac
111194 shift
112195done
0 commit comments