Skip to content

Commit 69091f6

Browse files
authored
Merge pull request #62 from Heshdude/creating-installer-generator
Improvements to the Installer Generator & Continuous Delivery
2 parents 67e927b + f95bce6 commit 69091f6

File tree

14 files changed

+341
-84
lines changed

14 files changed

+341
-84
lines changed

.github/workflows/deploy.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Build and Deploy
2+
on:
3+
push:
4+
branches:
5+
- master
6+
7+
jobs:
8+
build:
9+
name: Build
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout Repo
13+
uses: actions/checkout@master
14+
- name: Get the list of modified files only
15+
uses: technote-space/get-diff-action@v1
16+
- name: Generate installers
17+
run: pip install toml && python generate.py ${{ env.GIT_DIFF }}
18+
- name: Archive Production Artifact
19+
uses: actions/upload-artifact@master
20+
with:
21+
name: installers
22+
path: installers
23+
deploy:
24+
name: Deploy
25+
needs: build
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout Repo
29+
uses: actions/checkout@master
30+
- name: Download Artifact
31+
uses: actions/download-artifact@master
32+
with:
33+
name: installers
34+
path: installers
35+
- name: Install Dependencies
36+
run: cd functions && npm install
37+
- name: Deploy to Firebase
38+
uses: w9jds/firebase-action@master
39+
with:
40+
args: deploy --project installer-to
41+
env:
42+
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
43+
- name: Deploy to Google Cloud Bucket
44+
uses: actions-hub/gcloud@master
45+
env:
46+
PROJECT_ID: installer-to
47+
APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
48+
with:
49+
args: rsync -r installers gs://installer-to.appspot.com/installers
50+
cli: gsutil

generate.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def get_method_case(method):
2020
logging.error('Unpupported method in the TOML file, method: '+method)
2121
exit(1)
2222

23+
def parse_line(line):
24+
line = line.replace('@sudo', '$SUDO')
25+
return line
26+
2327
def generate(path):
2428

2529
installer_toml_path = path+"/installer.toml"
@@ -38,6 +42,21 @@ def generate(path):
3842
PACMAN_CMD=$(which pacman) # pacman package manager for ArchLinux
3943
APK_CMD=$(which apk) # apk package manager for Alpine
4044
GIT_CMD=$(which git) # to build from source pulling from git
45+
SUDO_CMD=$(which sudo) # check if sudo command is there
46+
47+
USER="$(id -un 2>/dev/null || true)"
48+
SUDO=''
49+
if [ "$USER" != 'root' ]; then
50+
if $SUDO_CMD; then
51+
SUDO='sudo'
52+
else
53+
cat >&2 <<-'EOF'
54+
Error: this installer needs the ability to run commands as root.
55+
We are unable to find "sudo". Make sure its available to make this happen
56+
EOF
57+
exit 1
58+
fi
59+
fi
4160
4261
""")
4362

@@ -47,7 +66,8 @@ def generate(path):
4766
lines = parsed_toml[section]['sh']
4867
installer_sh.write(seperator+" "+get_method_case(section))
4968
for line in lines.split("\n"):
50-
installer_sh.write(" "+line+"\n")
69+
step = parse_line(line)
70+
installer_sh.write(" "+step+"\n")
5171
seperator = "elif"
5272

5373
installer_sh.write("""

installers/dunner/installer.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
3+
[apt]
4+
sh = """
5+
echo "Installing hello"
6+
echo "Installed hello"
7+
"""
8+
9+
[yum]
10+
sh = """
11+
echo "Installing hello"
12+
echo "Installed hello"
13+
"""
14+
15+
16+
[apk]
17+
sh = """
18+
echo "Installing hello"
19+
echo "Installed hello"
20+
"""
21+
22+
[dnf]
23+
sh = """
24+
echo "Installing hello"
25+
echo "Installed hello"
26+
"""

installers/git/installer.sh

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
#!/bin/sh
2-
2+
33
YUM_CMD=$(which yum) # yum package manager for RHEL & CentOS
44
DNF_CMD=$(which dnf) # dnf package manager for new RHEL & CentOS
55
APT_GET_CMD=$(which apt-get) # apt package manager for Ubuntu & other Debian based distributions
66
PACMAN_CMD=$(which pacman) # pacman package manager for ArchLinux
77
APK_CMD=$(which apk) # apk package manager for Alpine
8+
GIT_CMD=$(which git) # to build from source pulling from git
9+
SUDO_CMD=$(which sudo) # check if sudo command is there
810

911
USER="$(id -un 2>/dev/null || true)"
10-
PREFIX=''
12+
SUDO=''
1113
if [ "$USER" != 'root' ]; then
12-
if command_exists sudo; then
13-
PREFIX='sudo'
14+
if [ ! -z $SUDO_CMD ]; then
15+
SUDO='sudo'
1416
else
1517
cat >&2 <<-'EOF'
1618
Error: this installer needs the ability to run commands as root.
@@ -20,20 +22,25 @@ if [ "$USER" != 'root' ]; then
2022
fi
2123
fi
2224

23-
if [ ! -z $APT_GET_CMD ]; then
24-
$PREFIX apt-get update
25-
$PREFIX apt-get install git
26-
elif [ ! -z $DNF_CMD ]; then
27-
$PREFIX dnf install git
28-
elif [ ! -z $YUM_CMD ]; then
29-
$PREFIX yum install git
30-
elif [ ! -z $PACMAN_CMD ]; then
31-
pacman -Sy git
32-
elif [ ! -z $APK_CMD ]; then
33-
$PREFIX apk add git
34-
else
35-
echo "Couldn't find an installer matching to this package"
36-
exit 1;
37-
fi
25+
echo $SUDO
3826

39-
git --version
27+
if [ ! -z $APT_GET_CMD ]; then
28+
$SUDO apt-get update
29+
$SUDO apt-get install git
30+
31+
elif [ ! -z $YUM_CMD ]; then
32+
$SUDO yum install git
33+
34+
elif [ ! -z $PACMAN_CMD ]; then
35+
pacman -Sy git
36+
37+
elif [ ! -z $DNF_CMD ]; then
38+
$SUDO dnf install git
39+
40+
elif [ ! -z $APK_CMD ]; then
41+
$SUDO apk add git
42+
43+
else
44+
echo "Couldn't install package"
45+
exit 1;
46+
fi

installers/git/installer.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[apt]
2+
sh = """
3+
@sudo apt-get update
4+
@sudo apt-get install git
5+
"""
6+
7+
[yum]
8+
sh = """
9+
@sudo yum install git
10+
"""
11+
12+
[pacman]
13+
sh = """
14+
pacman -Sy git
15+
"""
16+
17+
[dnf]
18+
sh = """
19+
@sudo dnf install git
20+
"""
21+
22+
[apk]
23+
sh = """
24+
@sudo apk add git
25+
"""

installers/hello/installer.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
11
#!/bin/sh
2+
3+
YUM_CMD=$(which yum) # yum package manager for RHEL & CentOS
4+
DNF_CMD=$(which dnf) # dnf package manager for new RHEL & CentOS
5+
APT_GET_CMD=$(which apt-get) # apt package manager for Ubuntu & other Debian based distributions
6+
PACMAN_CMD=$(which pacman) # pacman package manager for ArchLinux
7+
APK_CMD=$(which apk) # apk package manager for Alpine
8+
GIT_CMD=$(which git) # to build from source pulling from git
29

3-
echo "Hello!"
10+
if [ ! -z $APT_GET_CMD ]; then
11+
echo "Installing hello"
12+
echo "Installed hello"
13+
14+
elif [ ! -z $YUM_CMD ]; then
15+
echo "Installing hello"
16+
echo "Installed hello"
17+
18+
elif [ ! -z $APK_CMD ]; then
19+
echo "Installing hello"
20+
echo "Installed hello"
21+
22+
elif [ ! -z $DNF_CMD ]; then
23+
echo "Installing hello"
24+
echo "Installed hello"
25+
26+
else
27+
echo "Couldn't install package"
28+
exit 1;
29+
fi

installers/hello/installer.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,20 @@ echo "Installing hello"
1010
echo "Installed hello"
1111
"""
1212

13+
[pacman]
14+
sh = """
15+
echo "Installing hello"
16+
echo "Installed hello"
17+
"""
1318

1419
[apk]
1520
sh = """
1621
echo "Installing hello"
1722
echo "Installed hello"
1823
"""
24+
25+
[dnf]
26+
sh = """
27+
echo "Installing hello"
28+
echo "Installed hello"
29+
"""

installers/hello/spec/hello_spec.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Describe "Installer script for"
22
Describe "hello"
33
It "should say hello!"
44
When call installers/hello/installer.sh
5-
The output should eq "Hello!"
5+
The output should include "Installed"
66
End
77
End
88
End

installers/nginx/installer.sh

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
#!/bin/sh
2-
2+
33
YUM_CMD=$(which yum) # yum package manager for RHEL & CentOS
44
DNF_CMD=$(which dnf) # dnf package manager for new RHEL & CentOS
55
APT_GET_CMD=$(which apt-get) # apt package manager for Ubuntu & other Debian based distributions
66
PACMAN_CMD=$(which pacman) # pacman package manager for ArchLinux
77
APK_CMD=$(which apk) # apk package manager for Alpine
8+
GIT_CMD=$(which git) # to build from source pulling from git
89

9-
if [ ! -z $APT_GET_CMD ]; then
10-
sudo apt-get update
11-
sudo apt-get install nginx
12-
elif [ ! -z $DNF_CMD ]; then
13-
sudo dnf install nginx
14-
elif [ ! -z $YUM_CMD ]; then
15-
sudo yum install nginx
16-
elif [ ! -z $PACMAN_CMD ]; then
17-
sudo pacman -S nginx
18-
elif [ 1 -z $APK_CMD ]; then
19-
sudo apk update
20-
sudo apk add nginx
21-
else
22-
echo "Couldn't install package"
23-
exit 1;
24-
fi
25-
26-
nginx -v
10+
if [ ! -z $APT_GET_CMD ]; then
11+
sudo apt-get update
12+
sudo apt-get install nginx
13+
14+
elif [ ! -z $YUM_CMD ]; then
15+
sudo yum install nginx
16+
17+
elif [ ! -z $PACMAN_CMD ]; then
18+
sudo pacman -S nginx
19+
20+
elif [ ! -z $APK_CMD ]; then
21+
sudo apk update
22+
sudo apk add nginx
23+
24+
elif [ ! -z $DNF_CMD ]; then
25+
sudo dnf install nginx
26+
27+
else
28+
echo "Couldn't install package"
29+
exit 1;
30+
fi

installers/nginx/installer.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[apt]
2+
sh = """
3+
sudo apt-get update
4+
sudo apt-get install nginx
5+
"""
6+
7+
[yum]
8+
sh = """
9+
sudo yum install nginx
10+
"""
11+
12+
[pacman]
13+
sh = """
14+
@sudo pacman -S nginx
15+
"""
16+
17+
[apk]
18+
sh = """
19+
sudo apk update
20+
sudo apk add nginx
21+
"""
22+
23+
[dnf]
24+
sh = """
25+
sudo dnf install nginx
26+
"""

0 commit comments

Comments
 (0)