117 lines
3.7 KiB
YAML
117 lines
3.7 KiB
YAML
image: tools-registry.esy-web.dev/mainframe/mainframe:php # Utilisation de l'image Docker spécifiée
|
|
|
|
stages:
|
|
- install
|
|
- test
|
|
- build
|
|
- analyse
|
|
- deploy
|
|
|
|
variables:
|
|
POSTGRES_DB: "mainframe"
|
|
POSTGRES_USER: "mainframe"
|
|
POSTGRES_PASSWORD: "mainframe"
|
|
POSTGRES_HOST_AUTH_METHOD: trust
|
|
|
|
# Services Docker définis globalement, disponibles pour tous les jobs
|
|
services:
|
|
- redis:7-alpine
|
|
- postgres:16-alpine
|
|
|
|
before_script:
|
|
- echo "Starting environment setup..."
|
|
- echo "Creating .env.local file..."
|
|
- echo "APP_ENV=test" > .env.local
|
|
- echo "APP_ENV=test" > .env.test
|
|
- echo "KERNEL_CLASS=App\Kernel" > .env.test
|
|
- echo "APP_SECRET='$ecretf0rt3st'" > .env.test
|
|
- echo 'DATABASE_URL="postgresql://symfony_user:ChangeMeInProd!@postgres:5432/app_db_test?serverVersion=16&charset=utf8"' > .env.test
|
|
- echo "XDEBUG_MODE=coverage" > .env.test
|
|
- echo ".env.local created successfully."
|
|
|
|
install_dependencies:
|
|
stage: install
|
|
script:
|
|
- echo "Starting installation stage..."
|
|
- curl -fsSL https://bun.sh/install | bash
|
|
- source /root/.bashrc
|
|
- composer install # Ajout de la commande composer install
|
|
- bun install # Ajout de la commande bun install
|
|
- echo "Dependencies installed successfully."
|
|
artifacts:
|
|
paths:
|
|
- vendor/
|
|
- node_modules/
|
|
expire_in: 1 day
|
|
|
|
run_tests:
|
|
stage: test
|
|
variables:
|
|
XDEBUG_MODE: coverage
|
|
script:
|
|
- echo "Starting testing stage..."
|
|
- cat .env.test
|
|
- cat .env.local
|
|
- php bin/console doctrine:database:create
|
|
- php bin/console -no-interaction doctrine:migrations:migrate
|
|
- vendor/bin/phpunit -c phpunit.dist.xml
|
|
- echo "Tests completed successfully."
|
|
needs:
|
|
- job: install_dependencies # Ce job dépend du job 'install_dependencies'
|
|
artifacts: true
|
|
artifacts:
|
|
paths:
|
|
- .coverage/
|
|
expire_in: 1 day
|
|
|
|
build_application:
|
|
stage: build
|
|
script:
|
|
- echo "Starting build stage..."
|
|
- curl -fsSL https://bun.sh/install | bash
|
|
- source /root/.bashrc
|
|
- echo "Application built successfully."
|
|
needs:
|
|
- run_tests
|
|
- job: install_dependencies # Ce job dépend du job 'install_dependencies'
|
|
artifacts: true
|
|
analyse_code:
|
|
stage: analyse
|
|
image:
|
|
name: sonarsource/sonar-scanner-cli:latest
|
|
entrypoint: [ "" ]
|
|
variables:
|
|
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
|
|
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
|
|
cache:
|
|
key: "${CI_JOB_NAME}"
|
|
paths:
|
|
- .sonar/cache
|
|
allow_failure: true
|
|
script:
|
|
- echo "Starting analysis stage..."
|
|
- sonar-scanner
|
|
- echo "Code analysis completed."
|
|
needs:
|
|
- job: run_tests # Ce job dépend du job 'build_application'
|
|
artifacts: true
|
|
|
|
deploy_application:
|
|
stage: deploy
|
|
before_script:
|
|
- apt-get update --fix-missing
|
|
- apt-get install -qq git
|
|
# Setup SSH deploy keys
|
|
- 'which ssh-agent || ( apt-get install -qq openssh-client )'
|
|
- eval $(ssh-agent -s)
|
|
- ssh-add <(echo "$SSH_PRIVATE_KEY")
|
|
- mkdir -p ~/.ssh
|
|
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
|
|
script:
|
|
- echo "Starting deployment stage..."
|
|
- ssh bot@35.204.191.160 "cd /var/www/mainframe/app && git pull && nohup sh ./update.sh"
|
|
- echo "Application deployed successfully."
|
|
needs:
|
|
- analyse_code # Ce job dépend maintenant du job 'analyse_code'
|
|
|