forked from crackdev-in/static_website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genesis_cmds.txt
205 lines (154 loc) · 6.84 KB
/
genesis_cmds.txt
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# see OpenProject on local Proxmox for more details on this project
#Create repo locally
mkdir -p ./projectslocalrepo/static_website
#Move into repo directory and initialize
cd static_website/
git init
cat .git/config
#Use the github tool to set up the repo remotely with required flags
gh repo create --public -s ~/projectslocalrepo/static_website -r website_static --add-readme -d "test of static website pushed programatically from github"
#Save a record of cmds executed
history | tail -30
history | tail -30 | cat > genesis_cmds.txt
#View your repos with teh github gh tool
gh repo list
#update the to new naming convention master to main
git branch -m master main
#Check the repo's status and logs before & after adding files and committing changes
git status
git log
git add .
git status
git log
git commit -m "added genesis_cmds.txt: repo setup inx"
git status
#Check the repo's config file and add the path to the remote repo on github
cat .git/config
git remote add origin [email protected]:crackdev-in/static_website.git
cat .git/config
#Push changes to the remote repo on github
git push -u origin main
#Check status and logs of repo
git status
git log
#Append and filter new & relevant cmds to this file
history | tail -30 >> genesis_cmds.txt
# added and committed to self cmds documentation genesis_cmds.txt
2101 git commit -am "genesis_cmds.txt: added new cmds master to main, added remote repo path, add,commit,push to remote, check repo status and logs"
2102 git log
# added index and about html pages and placeholder content to index, the about has details of the project. add and commit the index ad about files and push to remote repo
2106 touch index.html about.html
2107 nano index.html
2108 nano about.html
2109 cat index.html > about.html
2110 nano about.html
2111 git status
2112 git add .
2113 git commit -am "added index.html & about.html, about.html: lists purpose and skills usage in this project also content can be used in the README.md index.html: basic hand typed html for demo purpose, serves as a good refresher for long dormant html skills and keeps the code simple as UI is not the focus here"
2114 git push origin main
2115 git log
2120 history | tail -20 >> genesis_cmds.txt
# setup ec2 on aws
# moved .pem key to .ssh and chmod 400
# login to ec2 instance from local with above pem key and Public IP
# on ec2 instance update and upgrade the instance
# cmdline
2001 git log
2002 git status
2003 git diff
2004 git commit -am "genesis_cmds.txt: add comment of ec2 setup, pem key, login to instance, and instance prep update & upgrad"
2005 git diff
2006 git log
2007 git status
2008 git push origin main
2009 ls
2010 history | tail -10 >> genesis_cmds.txt
# Install webserver http2 [apache]
optional - sudo ufw app list
sudo apt install apache2
systemctl status apache2
optional - sudo ufw app list
browse to the public ip to the the "It works" page.
install tmux if not already installed
Browse to var/www/html
save original apache ("It works") landing page to backup and create your own test page
# configure ports 80, 22 under a security group
see OpenProject for security group
# Copy files from local to remote and test if website is publicly accessible
mkdir a dir in ec2 home folder static_website_staging
Copy local html files from static_website to ec2 instance, and then transfer to website at /var/www/html
sudo scp -i ~/.ssh/static_webpage.pem /home/<USER>/projectslocalrepo/static_website/*.html [email protected]:~/static_website_staging
# ec2: copy from staging to webserver folder
sudo cp ./static_website_staging/* /var/www/html/
# Added a text for automation test
nano index.html
git status
git diff
git commit -am "index.html: added test text for local to aws automation"
# automate checking of static_website_staging for changes and copy to webserver folder /var/www/html
# used similar while on piserver(RaspiDash) and similar to 2014-15 IoT server, need to locate and check that code
while true; do sudo diff index.html /var/www/html/index.html >/dev/null 2>&1; if [ $? -eq 0 ]; then echo "No changes"; else sudo cp *.html /var/www/html; echo "files updated"; fi; sleep 10; done
verify website output on public IP
or
sudo cat /var/www/html/index.html
# todo edit the ec2 to run script on boot - cron,systemd,rc.local,init.d
#Create a script
chmod +x /home/ubuntu/startup.sh
# Set a crontab for it:
crontab -e
@reboot /home/ubuntu/startup.sh
# Reboot the ec2 instance and test
success
# edited the script to output to a log and added date and time for every update, tested
----------x---------
#!/bin/bash
while true; do sudo diff /home/ubuntu/static_website_staging/index.html /var/www/html/index.html >/dev/null 2>&1; if [ $? -eq 0 ]; then echo "No changes" >> static_website_update.log; else sudo cp /home/ubuntu/static_website_staging/*.html /var/www/html; echo "files updated `date +'%d-%b-%Y:%T'`" >> static_website_update.log; fi; sleep 10; done &
----------x---------
# check all bash history local and ec2
# post-commit script to automate deployment
31Dec23
cd projectslocalrepo/static_website/
git status
nano about.html
nano index.html
sudo scp -i ~/.ssh/static_webpage.pem /home/chronos/projectslocalrepo/static_website/*.html [email protected]:~/static_website_staging
bash checkstate_select_autologout_shutdown.sh
git status
git diff
git commit -am "checkstate_select_autologin.sh: added the static_webpage.pemto script, need to have an option in script for .pem/credential files"
#create the post-commit hook
cd ../../static_website/
cd .git/hooks/
touch post-commit
ls
nano post-commit
# put in the file transfer script into the hook
#------------------xxx--------------
#!/bin/sh
echo "===== POST-COMMIT CHECKLIST ====="
# Read user input, assign stdin to keyboard
exec < /dev/tty
while read -p "Check if EC2 static_website instance is running ? (Y/n) " yn; do
case $yn in
[Yy] ) break;;
[Nn] ) echo "Please start instance before deploying"; exit 1;;
* ) echo "Please answer y (yes) or n (no):" && continue;
esac
done
read -p "Enter in the correct EC2 instance IP Address " ec2_ip;
while read -p "Do you want to deploy to static_website to EC2 instance ? (Y/n) " yn; do
case $yn in
[Yy] ) sudo scp -i ~/.ssh/static_webpage.pem /home/chronos/projectslocalrepo/static_website/*.html ubuntu@$ec2_ip:~/static_website_staging; sleep 5; break;;
[Nn] ) echo "Please use a descriptive comment"; exit 1;;
* ) echo "Please answer y (yes) or n (no):" && continue;
esac
done
exec <&-
#------------------xxx--------------
git status
git diff
git commit -am "Automation test done yesterday 30thDec, no this commit to test post-commit deployment script"
git commit -am "this commit to test cases in post-commit deplyment script"
nano index.html
git diff
git commit -am "this commit to test cases in post-commit deplyment script"