composer added
This commit is contained in:
		
							parent
							
								
									78e7d279ea
								
							
						
					
					
						commit
						423a000d03
					
				@ -15,5 +15,6 @@
 | 
				
			|||||||
    - role: common
 | 
					    - role: common
 | 
				
			||||||
    - role: database
 | 
					    - role: database
 | 
				
			||||||
    - role: php
 | 
					    - role: php
 | 
				
			||||||
 | 
					    - role: composer
 | 
				
			||||||
    - role: nginx
 | 
					    - role: nginx
 | 
				
			||||||
    - role: projects
 | 
					    - role: projects
 | 
				
			||||||
							
								
								
									
										25
									
								
								roles/composer/tasks/main.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								roles/composer/tasks/main.yml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					---
 | 
				
			||||||
 | 
					- name: "Install yq (YAML processor) for the smart composer script"
 | 
				
			||||||
 | 
					  ansible.builtin.get_url:
 | 
				
			||||||
 | 
					    url: "https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64"
 | 
				
			||||||
 | 
					    dest: /usr/local/bin/yq
 | 
				
			||||||
 | 
					    mode: '0755'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: "Download the Composer installer"
 | 
				
			||||||
 | 
					  ansible.builtin.get_url:
 | 
				
			||||||
 | 
					    url: https://getcomposer.org/installer
 | 
				
			||||||
 | 
					    dest: /tmp/composer-installer.php
 | 
				
			||||||
 | 
					    mode: '0755'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: "Install Composer globally (as composer.phar)"
 | 
				
			||||||
 | 
					  ansible.builtin.command:
 | 
				
			||||||
 | 
					    cmd: php /tmp/composer-installer.php --install-dir=/usr/local/bin --filename=composer.phar
 | 
				
			||||||
 | 
					    creates: /usr/local/bin/composer.phar
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: "Deploy the smart Composer wrapper script"
 | 
				
			||||||
 | 
					  ansible.builtin.template:
 | 
				
			||||||
 | 
					    src: composer-wrapper.sh.j2
 | 
				
			||||||
 | 
					    dest: /usr/local/bin/composer
 | 
				
			||||||
 | 
					    owner: root
 | 
				
			||||||
 | 
					    group: root
 | 
				
			||||||
 | 
					    mode: '0755'
 | 
				
			||||||
							
								
								
									
										38
									
								
								roles/composer/templates/composer-wrapper.sh.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								roles/composer/templates/composer-wrapper.sh.j2
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,38 @@
 | 
				
			|||||||
 | 
					#!/bin/bash
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Lenvi Smart Composer Wrapper
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# This script automatically detects the required PHP version for a project
 | 
				
			||||||
 | 
					# by looking for a `Lenvi.yaml` file and uses the correct PHP binary.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# The real composer binary
 | 
				
			||||||
 | 
					COMPOSER_PHAR="/usr/local/bin/composer.phar"
 | 
				
			||||||
 | 
					DEFAULT_PHP_BINARY="/usr/bin/php"
 | 
				
			||||||
 | 
					PHP_BINARY=""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Find the project root by looking for a Lenvi.yaml file in parent directories
 | 
				
			||||||
 | 
					SEARCH_DIR=$(pwd)
 | 
				
			||||||
 | 
					while [[ "$SEARCH_DIR" != "" && ! -f "$SEARCH_DIR/Lenvi.yaml" ]]; do
 | 
				
			||||||
 | 
					  SEARCH_DIR=${SEARCH_DIR%/*}
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [[ -f "$SEARCH_DIR/Lenvi.yaml" ]]; then
 | 
				
			||||||
 | 
					  # We found a config file, let's find the PHP version for the current directory
 | 
				
			||||||
 | 
					  CURRENT_PROJECT_ROOT=$(pwd)
 | 
				
			||||||
 | 
					  PHP_VERSION=$(yq eval '.sites[] | select(.project_root == "'"$CURRENT_PROJECT_ROOT"'") | .php_version' "$SEARCH_DIR/Lenvi.yaml")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if [[ -n "$PHP_VERSION" && -x "/usr/bin/php$PHP_VERSION" ]]; then
 | 
				
			||||||
 | 
					    # Version found and the corresponding PHP binary exists
 | 
				
			||||||
 | 
					    PHP_BINARY="/usr/bin/php$PHP_VERSION"
 | 
				
			||||||
 | 
					    echo "Lenvi: Found project configuration. Using PHP $PHP_VERSION..." >&2
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# If no specific PHP binary was found, use the system default
 | 
				
			||||||
 | 
					if [[ -z "$PHP_BINARY" ]]; then
 | 
				
			||||||
 | 
					  echo "Lenvi: No project configuration found. Using default system PHP." >&2
 | 
				
			||||||
 | 
					  PHP_BINARY="$DEFAULT_PHP_BINARY"
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Execute the real Composer with the determined PHP version and pass all arguments
 | 
				
			||||||
 | 
					exec "$PHP_BINARY" "$COMPOSER_PHAR" "$@"
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user