Skip to content

Commit

Permalink
feat(install): add jenkins and gitlab installation
Browse files Browse the repository at this point in the history
  • Loading branch information
abolfazl8131 committed Dec 9, 2024
1 parent 95e8dda commit 3dcf0ee
Show file tree
Hide file tree
Showing 17 changed files with 287 additions and 20 deletions.
4 changes: 3 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
from app.routes.helm import *
from app.routes.ansible import *
from app.routes.jcasc import *
from app.routes.docker import *
from app.routes.docker import *
from app.routes.jenkins import *
from app.routes.gitlab import *
31 changes: 31 additions & 0 deletions app/media/Installation_base/Gitlab/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# sudo mkdir -p /srv/gitlab
# export GITLAB_HOME=/srv/gitlab

version: '3.6'
services:
gitlab:
image: gitlab/gitlab-ee:<version>-ee.0
container_name: gitlab
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
# Add any other gitlab.rb configuration here, each on its own line
external_url 'https://gitlab.example.com'
# you can also use custom HTTP and SSH port. if you you want to do that, follow the below syntax
# external_url 'http://gitlab.example.com:8929'
# gitlab_rails['gitlab_shell_ssh_port'] = 2424
ports:
# - '8929:8929' # Custom HTTP Port
# - '2424:22' # Custom SSH Port
- '80:80'
- '443:443'
- '22:22'
volumes:
- '$GITLAB_HOME/config:/etc/gitlab'
- '$GITLAB_HOME/logs:/var/log/gitlab'
- '$GITLAB_HOME/data:/var/opt/gitlab'
shm_size: '256m'
9 changes: 9 additions & 0 deletions app/media/Installation_base/Jenkins/RHEL.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
sudo yum upgrade -y
# Add required dependencies for the jenkins package
sudo yum install -y fontconfig java-17-openjdk
sudo yum install -y jenkins
sudo systemctl daemon-reload
sudo systemctl enable --now jenkins
15 changes: 15 additions & 0 deletions app/media/Installation_base/Jenkins/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.8'
services:
jenkins:
image: jenkins/jenkins:lts
privileged: true
user: root
ports:
- 8080:8080
- 50000:50000
container_name: jenkins
volumes:
- /home/${myname}/jenkins_compose/jenkins_configuration:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock

# Replace "/home/${myname}/jenkins_compose/jenkins_configuration" with the path you want to use to store your jenkins data
9 changes: 9 additions & 0 deletions app/media/Installation_base/Jenkins/fedora.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
sudo dnf upgrade -y
# Add required dependencies for the jenkins package
sudo dnf install -y fontconfig java-17-openjdk
sudo dnf install -y jenkins
sudo systemctl daemon-reload
sudo systemctl enable --now jenkins
12 changes: 12 additions & 0 deletions app/media/Installation_base/Jenkins/ubuntu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sudo apt update -y
sudo apt install -y fontconfig openjdk-17-jre


sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update -y
sudo apt-get install -y jenkins
sudo systemctl enable --now jenkins
24 changes: 10 additions & 14 deletions app/media/MyBash/bash.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#!/bin/bash
sudo apt-get update -y
sudo apt-get install ca-certificates curl -y
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update -y
sudo apt update -y
sudo apt install -y fontconfig openjdk-17-jre


sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update -y
sudo apt-get install -y jenkins
sudo systemctl enable --now jenkins
31 changes: 31 additions & 0 deletions app/media/MyCompose/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# sudo mkdir -p /srv/gitlab
# export GITLAB_HOME=/srv/gitlab

version: '3.6'
services:
gitlab:
image: gitlab/gitlab-ee:<version>-ee.0
container_name: gitlab
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
# Add any other gitlab.rb configuration here, each on its own line
external_url 'https://gitlab.example.com'
# you can also use custom HTTP and SSH port. if you you want to do that, follow the below syntax
# external_url 'http://gitlab.example.com:8929'
# gitlab_rails['gitlab_shell_ssh_port'] = 2424
ports:
# - '8929:8929' # Custom HTTP Port
# - '2424:22' # Custom SSH Port
- '80:80'
- '443:443'
- '22:22'
volumes:
- '$GITLAB_HOME/config:/etc/gitlab'
- '$GITLAB_HOME/logs:/var/log/gitlab'
- '$GITLAB_HOME/data:/var/opt/gitlab'
shm_size: '256m'
4 changes: 3 additions & 1 deletion app/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
from .ansible_models import *
from .jcasc import *
from .compose_models import *
from .docker_installation_models import *
from .docker_installation_models import *
from .jenkins import *
from .gitlab_models import *
17 changes: 17 additions & 0 deletions app/models/gitlab_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import List, Optional
from pydantic import BaseModel, validator, ValidationError



class GitLabInstallation(BaseModel):


environment:str = 'Docker'


@validator("environment")
def validator_environment(cls, value):
env = ['Docker']
if value not in env:
raise ValueError(f"your selected Environemnt must be in {env}")
return value
24 changes: 24 additions & 0 deletions app/models/jenkins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from typing import List, Optional
from pydantic import BaseModel, validator, ValidationError



class JenkinsInstallation(BaseModel):

os: str = 'Ubuntu'

environment:str = 'Linux'

@validator("os")
def validator_os(cls, value):
valid_oss = ['Ubuntu','Fedora','RHEL']
if value not in valid_oss:
raise ValueError(f"your selected OS must be in {valid_oss}")
return value

@validator("environment")
def validator_environment(cls, value):
env = ['Linux','Docker']
if value not in env:
raise ValueError(f"your selected Environemnt must be in {env}")
return value
1 change: 1 addition & 0 deletions app/routes/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ async def docker_compose_template(request:DockerCompose) -> Output:

return Output(output='output')


@app.post("/api/docker/installation")
async def docker_installation(request:DockerInstallationInput) -> Output:

Expand Down
14 changes: 14 additions & 0 deletions app/routes/gitlab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from app.app_instance import app
from app.models import (GitLabInstallation,Output)
from app.template_generators.gitlab.installation import select_install_gitlab
import os




@app.post("/api/gitlab/installation")
async def gitlab_installation(request:GitLabInstallation) -> Output:

select_install_gitlab(request)

return Output(output='output')
14 changes: 14 additions & 0 deletions app/routes/jenkins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from app.app_instance import app
from app.models import (DockerCompose,JenkinsInstallation,Output)
from app.template_generators.jenkins.installation import select_install_jenkins
import os




@app.post("/api/jenkins/installation")
async def jenkins_installation(request:JenkinsInstallation) -> Output:

select_install_jenkins(request)

return Output(output='output')
35 changes: 35 additions & 0 deletions app/template_generators/gitlab/installation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import shutil


def create_directory(folder:str,filename:str):

dir = f"app/media/{folder}"


if not os.path.exists(dir):
os.makedirs(dir)
os.path.join(dir, filename)


def select_install_gitlab(input):

create_directory("MyCompose","docker-compose.yaml")


match input.environment:

case "Docker":
source = 'app/media/Installation_base/Gitlab/docker-compose.yaml'
dest = 'app/media/MyCompose/docker-compose.yaml'
shutil.copyfile(source, dest)


case _:
raise ValueError()






55 changes: 55 additions & 0 deletions app/template_generators/jenkins/installation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import os
import shutil


def create_directory(folder:str,filename:str):

dir = f"app/media/{folder}"


if not os.path.exists(dir):
os.makedirs(dir)
os.path.join(dir, filename)



def select_install_jenkins(input):

create_directory("MyBash",'bash.sh')
create_directory("MyCompose",'docker-compose.yaml')

if input.environment == 'Docker':

source = 'app/media/Installation_base/Jenkins/docker-compose.yml'
dest = 'app/media/MyCompose/docker-compose.yaml'
shutil.copyfile(source, dest)

else:

match input.os:


case "Ubuntu":
source = 'app/media/Installation_base/Jenkins/ubuntu.sh'
dest = 'app/media/MyBash/bash.sh'
shutil.copyfile(source, dest)

case "Fedora":
source = 'app/media/Installation_base/Jenkins/fedora.sh'
dest = 'app/media/MyBash/bash.sh'
shutil.copyfile(source, dest)


case "RHEL":
source = 'app/media/Installation_base/Jenkins/RHEL.sh'
dest = 'app/media/MyBash/bash.sh'
shutil.copyfile(source, dest)

case _:
raise ValueError()






8 changes: 4 additions & 4 deletions app/template_generators/terraform/Installation/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
import shutil


def create_MyBash_directory():
def create_directory(folder:str,filename:str):

dir = 'app/media/MyBash'
dir = f"app/media/{folder}"


if not os.path.exists(dir):
os.makedirs(dir)
os.path.join(dir, 'bash.sh')
os.path.join(dir, filename)



def select_install(input):
create_MyBash_directory()
create_directory("MyBash","bash.sh")

match input.os:

Expand Down

0 comments on commit 3dcf0ee

Please sign in to comment.