Skip to content

Commit

Permalink
fix(docker install): fix it
Browse files Browse the repository at this point in the history
  • Loading branch information
abolfazl8131 committed Dec 8, 2024
1 parent 90bece3 commit 54d507f
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 17 deletions.
19 changes: 19 additions & 0 deletions app/media/Installation_base/Docker/RHEL.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

sudo dnf remove -y \
docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine \
podman \
runc


sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo

sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
16 changes: 16 additions & 0 deletions app/media/Installation_base/Docker/centos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
sudo dnf remove -y \
docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine


sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
19 changes: 19 additions & 0 deletions app/media/Installation_base/Docker/fedora.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
sudo dnf remove -y \
docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine


sudo dnf -y install dnf-plugins-core
sudo dnf-3 config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo


sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
16 changes: 16 additions & 0 deletions app/media/Installation_base/Docker/ubuntu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/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-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
25 changes: 13 additions & 12 deletions app/media/MyBash/bash.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!bin/bash
#!/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

sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
# 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

wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg > /dev/null

echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/hashicorp.list

sudo apt update

sudo apt-get install terraform
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
3 changes: 2 additions & 1 deletion app/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
from .utils import *
from .ansible_models import *
from .jcasc import *
from .compose_models import *
from .compose_models import *
from .docker_installation_models import *
20 changes: 20 additions & 0 deletions app/models/docker_installation_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import Dict, List, Optional,Union
from pydantic import BaseModel, model_validator,validator

class DockerInstallationInput(BaseModel):
os:str = "Ubuntu"
environment:str = "Linux"

@validator("os")
def validate_os(cls, value):
allowed_os = ['Ubuntu', 'Centos', 'Fedora', 'RHEL']
if value not in allowed_os:
raise ValueError(f"OS must be one of {allowed_os}.")
return value

@validator("environment")
def validate_environment(cls, value):
allowed_os = ['Linux']
if value not in allowed_os:
raise ValueError(f"Environment must be one of {allowed_os}.")
return value
13 changes: 9 additions & 4 deletions app/routes/docker.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from app.app_instance import app
from app.gpt_services import gpt_service
from app.services import (write_installation,edit_directory_generator,execute_pythonfile)
from app.models import (DockerCompose,Output)
from app.models import (DockerCompose,DockerInstallationInput,Output)
from app.template_generators.docker.compose import docker_compose_generator
from app.template_generators.docker.installation import docker_installation_selection
import os

@app.post("/api/docker-compose/")
Expand All @@ -13,4 +12,10 @@ async def docker_compose_template(request:DockerCompose) -> Output:
docker_compose_generator(request)

return Output(output='output')


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

docker_installation_selection(request)

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


def create_MyBash_directory():

dir = 'app/media/MyBash'


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



def docker_installation_selection(input):

create_MyBash_directory()

match input.os:

case "Ubuntu":

source = 'app/media/Installation_base/Docker/ubuntu.sh'
dest = 'app/media/MyBash/bash.sh'

shutil.copyfile(source, dest)


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

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

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

0 comments on commit 54d507f

Please sign in to comment.