vigeeking / homeAutomation

My goal is to create a pipeline that is built exclusively with tools I either already know, or am only learning because they provide added value to the project
https://github.com/vigeeking/homeAutomation
0 stars 0 forks source link

shell script to start #46

Closed vigeeking closed 4 years ago

vigeeking commented 4 years ago

A lot of my dev work starts off the same way. I want to automatically have it happen. This is done when I can run a "koan.sh" file.

additional info: After talking with Max and realizing it's never too early to start testing, I wanted to have some sort of shell script that I use to start everything. At some point I will likely include cloud/local parameters, but for now it assumes everything is local.

vigeeking commented 4 years ago

Notes from Justin: envsubst it take a template file that have environment variables in it and creates a file based on the values of environment variables It will also read a environment variable file. i once used it to make a javascript dynamic in a docker container. everytime the container starts, it runs envsubst and defines a configuration file based on environment variables I have a file env.template.js, and it has a line that has '${API_URL}' --- that gets replaced by envsubst with the API_URL variable, and I run it by... the command that gets run is: envsubst < /usr/share/nginx/html/assets/env.template.js > /usr/share/nginx/html/assets/env.js --- It takes the template and produces the env.js file I am not sure if you are running this inside a container as an automated process or external as part of a script.

vigeeking commented 4 years ago

from justin: You can't use {{ secrets.AMCRESTPASSWORD }}, if you had an environment variable named AMCRESTPASSWORD, you could do ${AMCRESTPASSWORD}

envsubst takes a path to a template file, and a path to the output. So it could be something like: envsubst < /wherever/the/template/exists/secrets.yaml.template > /homeassistant/config/secrets.yaml

vigeeking commented 4 years ago

from justin: yeah it just takes a string and substitutes environment variable values and spits out the results. the < > is feeding in input to the command and directing the output to your desired file

vigeeking commented 4 years ago

I ended up accomplishing this with two scripts. One (koan.sh) takes it from github clone forward. A second script located on the host (currently undocumented, shell script to follow) handles all of the secrets, and takes an input for the branch name you are working on, and then lets you clone into that branch and be ready to run koan.sh.

vigeeking commented 4 years ago

echo "what branch are you trying to modify?" read branch git clone https://github.com/vigeeking/homeAutomation.git cd homeAutomation git checkout remotes/origin/$branch chmod a+x koan.sh

Justin suggested improving to be a cli parameter (start.sh --branch) and I will look into that later.