Skip to content

GDRCD Installer #2

Description

@egodi99

la modifica che vorrei proporre è molto ampia e andrebbe ad influire su più aspetti del software, perché quello che mi piacerebbe raggiungere è avere un sistema configurabile da chiunque anche da chi, di software non ne sa nulla, ma partiamo dal principio.
Sicuramente la prima cosa in cui si imbatte un neofita è cosa ci faccio con lo zip di GDRCD e dove lo devo mettere?
Per risolvere questo problema la cosa più semplice che mi è venuta in mente è quella di rendere all'utente finale l'installazione di GDRCD come un wizard di un qualsiasi altro software "fai due clic ed hai fatto", quindi quello che proporrei è l'aggiunta di questi due componenti, che ho già testato in locale attualmente solo per windows poi naturalmente sarebbe da integrare anche macOS e linux.
Il primo file che sarà START.bat

@echo off
setlocal

REM Avvia il bootstrapper PowerShell
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0START.ps1"

pause

che non farà altro che avviare il vero e proprio bootstrapper powershell: START.ps1

 $ErrorActionPreference = "Stop"

# ============================================================
# GDRCD BOOTSTRAPPER - WINDOWS
# ============================================================

$ProjectPath = Split-Path -Parent $MyInvocation.MyCommand.Path
$ComposeFile = Join-Path $ProjectPath "docker-compose.yml"

Write-Host ""
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "       GDRCD DEVELOPMENT BOOTSTRAPPER" -ForegroundColor Cyan
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""

# ============================================================
# FUNZIONE: Verifica comando
# ============================================================

function Test-CommandExists {
    param (
        [string]$Command
    )

    return $null -ne (Get-Command $Command -ErrorAction SilentlyContinue)
}


# ============================================================
# VERIFICA DOCKER
# ============================================================

Write-Host "[1/4] Controllo installazione Docker..." -ForegroundColor Yellow

if (-not (Test-CommandExists "docker")) {

    Write-Host ""
    Write-Host "Docker non trovato." -ForegroundColor Red
    Write-Host ""

    $choice = Read-Host "Vuoi aprire la pagina per installare Docker Desktop? (S/N)"

    if ($choice -match "^[sS]$") {

        Write-Host ""
        Write-Host "Apertura pagina Docker Desktop..." -ForegroundColor Cyan

        Start-Process "https://www.docker.com/products/docker-desktop/"

        Write-Host ""
        Write-Host "Installa Docker Desktop e riavvia questo script." -ForegroundColor Yellow

    }

    exit 1
}

Write-Host "Docker trovato:" -ForegroundColor Green
docker --version


# ============================================================
# VERIFICA DOCKER COMPOSE
# ============================================================

Write-Host ""
Write-Host "[2/4] Controllo Docker Compose..." -ForegroundColor Yellow

try {

    docker compose version | Out-Null

}
catch {

    Write-Host "Docker Compose non disponibile." -ForegroundColor Red
    exit 1

}

Write-Host "Docker Compose trovato." -ForegroundColor Green


# ============================================================
# VERIFICA DOCKER DESKTOP / ENGINE
# ============================================================

Write-Host ""
Write-Host "[3/4] Controllo Docker Engine..." -ForegroundColor Yellow

try {

    docker info | Out-Null

}
catch {

    Write-Host ""
    Write-Host "Docker è installato ma il Docker Engine non è attivo." -ForegroundColor Red
    Write-Host ""
    Write-Host "Avvio Docker Desktop..." -ForegroundColor Yellow

    $DockerDesktop = "$env:ProgramFiles\Docker\Docker\Docker Desktop.exe"

    if (Test-Path $DockerDesktop) {

        Start-Process $DockerDesktop

        Write-Host "Attendo l'avvio di Docker..." -ForegroundColor Cyan

        $MaxAttempts = 30
        $Attempt = 0
        $DockerReady = $false

        while ($Attempt -lt $MaxAttempts) {

            Start-Sleep -Seconds 3

            try {

                docker info | Out-Null
                $DockerReady = $true
                break

            }
            catch {
                $Attempt++
                Write-Host "." -NoNewline
            }

        }

        Write-Host ""

        if (-not $DockerReady) {

            Write-Host "Docker non si è avviato correttamente." -ForegroundColor Red
            exit 1

        }

    }
    else {

        Write-Host "Impossibile trovare Docker Desktop." -ForegroundColor Red
        exit 1

    }

}

Write-Host "Docker Engine attivo." -ForegroundColor Green


# ============================================================
# VERIFICA docker-compose.yml
# ============================================================

if (-not (Test-Path $ComposeFile)) {

    Write-Host ""
    Write-Host "ERRORE: docker-compose.yml non trovato!" -ForegroundColor Red
    Write-Host "Percorso cercato: $ComposeFile"
    exit 1

}


# ============================================================
# AVVIO STACK
# ============================================================

Write-Host ""
Write-Host "[4/4] Avvio stack GDRCD..." -ForegroundColor Yellow
Write-Host ""

Set-Location $ProjectPath

docker compose up -d --build

if ($LASTEXITCODE -ne 0) {

    Write-Host ""
    Write-Host "Errore durante l'avvio dello stack." -ForegroundColor Red
    exit 1

}

Write-Host ""
Write-Host "==========================================" -ForegroundColor Green
Write-Host "        STACK GDRCD AVVIATO!" -ForegroundColor Green
Write-Host "==========================================" -ForegroundColor Green
Write-Host ""

# ============================================================
# ATTESA WEB SERVER
# ============================================================

$Url = "http://localhost:8080"
$MaxAttempts = 30
$Attempt = 0
$ServerReady = $false

Write-Host "Attendo l'avvio del web server..." -ForegroundColor Yellow

while ($Attempt -lt $MaxAttempts) {

    try {

        $Response = Invoke-WebRequest `
            -Uri $Url `
            -UseBasicParsing `
            -TimeoutSec 3

        if ($Response.StatusCode -eq 200) {

            $ServerReady = $true
            break

        }

    }
    catch {
        Start-Sleep -Seconds 2
        $Attempt++
        Write-Host "." -NoNewline
    }

}

Write-Host ""

# ============================================================
# APERTURA WIZARD
# ============================================================

if ($ServerReady) {

    Write-Host ""
    Write-Host "GDRCD è pronto!" -ForegroundColor Green
    Write-Host ""
    Write-Host "Apertura Wizard..." -ForegroundColor Cyan

    Start-Process $Url

}
else {

    Write-Host ""
    Write-Host "Lo stack è stato avviato ma il server non risponde ancora." -ForegroundColor Yellow
    Write-Host ""
    Write-Host "Prova ad aprire manualmente:"
    Write-Host $Url -ForegroundColor Cyan

}

Write-Host ""

quest'ultimo controllerà la presenza o meno di docker desktop e se non fosse presente chiederà all'utente di installarlo, dopo di che procederà ad avviare lo stack, attualmente ho utilizzato quello che già avevo io ma si può riutilizzare quello già presente nel progetto.
docker-compose.yml

services:

  # ==========================================================
  # WEB SERVER + PHP
  # ==========================================================

  web:
    build:
      context: .
      dockerfile: Dockerfile

    container_name: gdrcd_web

    ports:
      - "8080:80"

    volumes:
      - ./:/var/www/html

    depends_on:
      - db

    environment:
      APACHE_DOCUMENT_ROOT: /var/www/html

    restart: unless-stopped


  # ==========================================================
  # DATABASE
  # ==========================================================

  db:
    image: mariadb:11.4

    container_name: gdrcd_db

    restart: unless-stopped

    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: gdrcd
      MYSQL_USER: gdrcd
      MYSQL_PASSWORD: gdrcd

    ports:
      - "3306:3306"

    volumes:
      - gdrcd_db_data:/var/lib/mysql
      - ./database:/docker-entrypoint-initdb.d


  # ==========================================================
  # PHPMYADMIN
  # ==========================================================

  phpmyadmin:
    image: phpmyadmin:latest

    container_name: gdrcd_phpmyadmin

    restart: unless-stopped

    depends_on:
      - db

    ports:
      - "8081:80"

    environment:
      PMA_HOST: db
      PMA_PORT: 3306
      UPLOAD_LIMIT: 128M


  # ==========================================================
  # MAILHOG
  # ==========================================================

  mailhog:
    image: mailhog/mailhog:latest

    container_name: gdrcd_mailhog

    restart: unless-stopped

    ports:
      - "1025:1025"
      - "8025:8025"


# ==========================================================
# VOLUMES
# ==========================================================

volumes:

  gdrcd_db_data:

Dockerfile

FROM php:8.3-apache

# ==========================================================
# SYSTEM DEPENDENCIES
# ==========================================================

RUN apt-get update && apt-get install -y \
    libzip-dev \
    zip \
    unzip \
    && rm -rf /var/lib/apt/lists/*


# ==========================================================
# PHP EXTENSIONS
# ==========================================================

RUN docker-php-ext-install \
    mysqli \
    pdo \
    pdo_mysql \
    zip


# ==========================================================
# APACHE MODULES
# ==========================================================

RUN a2enmod rewrite


# ==========================================================
# APACHE CONFIGURATION
# ==========================================================

ENV APACHE_DOCUMENT_ROOT=/var/www/html

RUN sed -ri \
    -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' \
    /etc/apache2/sites-available/*.conf \
    /etc/apache2/apache2.conf \
    /etc/apache2/conf-available/*.conf

a questo punto con lo stack creato e avviato si può partire con la vera e propria configurazione, dove al posto di andare a mettere mano sul codice, per quanto riguarda tutto ciò che è presente in config.inc.php, io lo sposterei in una tabella del DB dedicata chiamata core_config_data che avrà le configurazioni essenziali già presenti più le configurazioni di FTP e DB del sito in cui verrà caricato effettivamente(altervista o chi per lui), per fare ciò naturalmente dovrà essere disponibile una tabella FE con elenco delle varie config e la possibilità di impostarle. al termine del wizard naturalmente dovrà essere possibile effettivamente pubblicare il risultato.
Ad ora mi fermerei qua, ma come dicevo all'inizio sarebbe bello riuscire a raggiungere un livello tale, in cui il tutto viene gestito da BE e non più con interventi lato codice, quindi anche tutto ciò che riguarda la grafica, renderla customizzabile tramite CMS, comunque ne parleremo in altra sede a tempo debito.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions