forked from devopshobbies/devops-gpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(install): add jenkins and gitlab installation
- Loading branch information
1 parent
95e8dda
commit 3dcf0ee
Showing
17 changed files
with
287 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters