github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/examples/0002/04/notes.md (about) 1 ### Notes 2 3 ### Incremental Improvement 4 5 #### Execution profile support 6 7 Add execution profile usage. It is to help the seamless integration with CI/CD pipeline 8 9 For example, normally, for your CI/CD pipeline, you will need a list of env vars as input of your script/cli command 10 11 eg. 12 13 ``` 14 15 export ENV_VAR1=var1 16 export ENV_VAR2=var2 17 ........... 18 export ENV_VAR10=var10 19 20 source ./scripts/aws_access.rc && ./my_cli.sh 21 22 ``` 23 24 Now, with UPcmd, you do it this way: 25 26 in up.yml, you config an exec profile entry: 27 28 ``` 29 eprofiles: 30 - name: dev_test 31 instance: dev 32 taskname: CreateMyAppStack 33 verbose: vvv 34 35 evars: 36 - name: APP_NAME 37 value: my_dev_test_app 38 39 - name: ENV_VAR10 40 value: env_var10 41 42 ``` 43 44 In this case, we simply use one evar: APP_NAME to present as one of a list of env vars as example. 45 46 * instance: this links to the insanceid in the scope, in this case, dev 47 * taskname: optional 48 * verbose: optional 49 50 If you choose to ues optional params: taskname and verbose, you simplify the up cli args 51 52 Now to execute your pipeline, you simply setup one ENV var in your pipeline: 53 54 ``` 55 export EProfileID=dev_test 56 ``` 57 58 then run below entry point cli command: 59 60 ``` 61 ./upngo.sh 62 ``` 63 64 #### Summary 65 66 The exec profile simplifies the pipeline setup by eliminating all environment variable setup either in GUI, or via other mechanisms. Now you only need one ENV var - EProfileID, then just use the entry point script upngo.sh for any task. UPcmd will use the config to pick up right task and use verbose level you prefer. Also, you could just configure your pipeline to be triggered automatically, so that your code push will automatically trigger the pipeline and you don't have to use GUI to click button at all. You can use condition in your workflow to determine how you want to proceed. 67 68 69 #### demo 70 71 Note about the envrc: this is for demo only, in your pipeline, you could use env vars or physical file for the encryption key for strengthened security 72 73 ``` 74 . ./envrc 75 export EProfileID=dev_test 76 ./upngo.sh 77 78 ↑126 0002/04 git:(master) ▶ . ./envrc 79 export EProfileID=dev_test 80 ./upngo.sh 81 82 % Total % Received % Xferd Average Speed Time Time Time Current 83 Dload Upload Total Spent Left Speed 84 100 648 100 648 0 0 1655 0 --:--:-- --:--:-- --:--:-- 1653 85 100 20.9M 100 20.9M 0 0 2649k 0 0:00:08 0:00:08 --:--:-- 4401k 86 eprofileid: dev_test 87 loading [Config]: ./upconfig.yml 88 Main config: 89 Version -> 1.0.0 90 RefDir -> ./ups 91 WorkDir -> cwd 92 AbsWorkDir -> /up-project/up/examples/0002/04 93 TaskFile -> up.yml 94 Verbose -> v 95 ModuleName -> self 96 ShellType -> /bin/sh 97 MaxCallLayers -> 8 98 Timeout -> 3600000 99 MaxModuelCallLayers -> 256 100 EntryTask -> Main 101 work dir: /up-project/up/examples/0002/04 102 -exec task: Main 103 loading [Task]: ./up.yml 104 module: [self], instance id: [dev], exec profile: [dev_test] 105 profile - dev_test envVars: 106 107 (*core.Cache)({ 108 "envVar_APP_NAME": "my_dev_test_app" 109 }) 110 111 loading [./main.yml]: ./ups/./main.yml 112 loading [./utils/encrypt.yml]: ./ups/./utils/encrypt.yml 113 loading [./utils/venv.yml]: ./ups/./utils/venv.yml 114 loading [./myapp/create.yml]: ./ups/./myapp/create.yml 115 Task6: [CreateMyAppStack ==> CreateMyAppStack: ] 116 -Step1: 117 self: final context exec vars: 118 119 (*core.Cache)({ 120 "up_runtime_task_layer_number": 0, 121 "api_password": "Eu6wFdmnoV4gBFpq6lRq/5HU3ATgXa9BbFjaKrXp/pcD+x4WpT3ot1xC9QBGtzVS", 122 "secure_api_password": "the_api_password", 123 "api_ep": "http://httpbin.org/post", 124 "a": "dev-a", 125 "app_name": "my_dev_test_app", 126 "api_username": "ixAvykgdH73SafoaGEGB+WiPH/zwZzYQnDMUrIig7lc=", 127 "secure_api_username": "api_username", 128 "enc_key": "Jb9SVdEy2!!S@WjJ" 129 }) 130 131 =Task5: [CreateMyAppStack ==> set_aws_credential: ] 132 --Step1: 133 self: final context exec vars: 134 135 (*core.Cache)({ 136 "api_username": "ixAvykgdH73SafoaGEGB+WiPH/zwZzYQnDMUrIig7lc=", 137 "up_runtime_task_layer_number": 1, 138 "api_password": "Eu6wFdmnoV4gBFpq6lRq/5HU3ATgXa9BbFjaKrXp/pcD+x4WpT3ot1xC9QBGtzVS", 139 "app_name": "my_dev_test_app", 140 "a": "dev-a", 141 "secure_api_username": "api_username", 142 "enc_key": "Jb9SVdEy2!!S@WjJ", 143 "secure_api_password": "the_api_password", 144 "api_ep": "http://httpbin.org/post" 145 }) 146 147 ~~SubStep1: [virtualEnv: source all needed aws credential and apply accross the full execution session ] 148 -sourcing execution result: 149 start sourcing ..... 150 end sourcing ..... 151 152 -Step2: [create_my_application: fake mock up only ] 153 self: final context exec vars: 154 155 (*core.Cache)({ 156 "secure_api_password": "the_api_password", 157 "api_username": "ixAvykgdH73SafoaGEGB+WiPH/zwZzYQnDMUrIig7lc=", 158 "secure_api_username": "api_username", 159 "api_ep": "http://httpbin.org/post", 160 "enc_key": "Jb9SVdEy2!!S@WjJ", 161 "up_runtime_task_layer_number": 1, 162 "a": "dev-a", 163 "app_name": "my_dev_test_app", 164 "api_password": "Eu6wFdmnoV4gBFpq6lRq/5HU3ATgXa9BbFjaKrXp/pcD+x4WpT3ot1xC9QBGtzVS" 165 }) 166 167 cmd( 1): 168 echo "AWS_SESSION_TOKEN is - ${AWS_SESSION_TOKEN}" 169 170 - 171 AWS_SESSION_TOKEN is - my_aws_session_token 172 173 - 174 .. ok 175 cmd( 2): 176 curl -s -d """ 177 { 178 "name": "tom", 179 "class": "year12-k", 180 "school": "SG" 181 "username": "{{.secure_api_username}}" 182 "password": "{{.secure_api_password}}" 183 "token": "${AWS_SESSION_TOKEN}" 184 }""" \ 185 -X POST \ 186 -H "accept: application/json" \ 187 {{.api_ep}} 188 189 190 - 191 { 192 "args": {}, 193 "data": "", 194 "files": {}, 195 "form": { 196 "\n{\n name: tom,\n class: year12-k,\n school: SG\n username: api_username\n password: the_api_password\n token: my_aws_session_token\n appname: my_dev_test_app\n}": "" 197 }, 198 "headers": { 199 "Accept": "application/json", 200 "Content-Length": "133", 201 "Content-Type": "application/x-www-form-urlencoded", 202 "Host": "httpbin.org", 203 "User-Agent": "curl/7.54.0", 204 "X-Amzn-Trace-Id": "Root=1-5f579add-2039c4c80b917e9004ab1ac8" 205 }, 206 "json": null, 207 "origin": "118.211.180.66", 208 "url": "http://httpbin.org/post" 209 } 210 211 - 212 .. ok 213 . ok 214 215 ```