-
-
Save tony1223/8b4bf50c6f02ede9d446b8da1b332b49 to your computer and use it in GitHub Desktop.
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
# PHP as Linux Web App on Azure | |
# Build, package and deploy your PHP project to Azure Linux Web App. | |
# Add steps that run tests and more: | |
# https://docs.microsoft.com/azure/devops/pipelines/languages/php | |
trigger: | |
- master | |
variables: | |
# Azure Resource Manager connection created during pipeline creation | |
azureSubscription: 'b5b03643-d71d-44d1-9900-860f95ca2448' | |
# Web app name | |
webAppName: 'tonyq-mapfiddle' | |
# Agent VM image name | |
vmImageName: 'ubuntu-latest' | |
# Environment name | |
environmentName: 'tonyq-mapfiddle' | |
# Root folder under which your composer.json file is available. | |
rootFolder: $(System.DefaultWorkingDirectory) | |
stages: | |
- stage: Build | |
displayName: Build stage | |
variables: | |
phpVersion: '7.3' | |
jobs: | |
- job: BuildJob | |
pool: | |
vmImage: $(vmImageName) | |
steps: | |
- script: | | |
sudo update-alternatives --set php /usr/bin/php$(phpVersion) | |
sudo update-alternatives --set phar /usr/bin/phar$(phpVersion) | |
sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpVersion) | |
sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpVersion) | |
sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpVersion) | |
php -version | |
workingDirectory: $(rootFolder) | |
displayName: 'Use PHP version $(phpVersion)' | |
- script: composer install --no-interaction --prefer-dist | |
workingDirectory: $(rootFolder) | |
displayName: 'Composer install' | |
- task: PowerShell@2 | |
inputs: | |
targetType: 'inline' | |
script: | | |
New-Item $(rootFolder)/.htaccess | |
Set-Content $(rootFolder)/.htaccess @" | |
<IfModule mod_rewrite.c> | |
RewriteEngine on | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule ^(.*)$ index.php?$1 [NC,L,QSA] | |
</IfModule> | |
"@ | |
New-Item $(rootFolder)/application/config/database.php | |
Set-Content $(rootFolder)/application/config/database.php @" | |
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
`$active_group = 'default'; | |
`$query_builder = TRUE; | |
`$db['default'] = array( | |
'dsn' => '', | |
'hostname' => 'pgsql:host=tonyq-mapfiddle-db.postgres.database.azure.com;dbname=mapfiddle', | |
'username' => 'pguser@tonyq-mapfiddle-db', | |
'password' => '<the password>', | |
'database' => 'mapfiddle', | |
'dbdriver' => 'pdo', | |
'dbprefix' => '', | |
'pconnect' => FALSE, | |
'db_debug' => (ENVIRONMENT !== 'production'), | |
'cache_on' => FALSE, | |
'cachedir' => '', | |
'char_set' => 'utf8', | |
'dbcollat' => 'utf8_general_ci', | |
'swap_pre' => '', | |
'encrypt' => FALSE, | |
'compress' => FALSE, | |
'stricton' => FALSE, | |
'failover' => array(), | |
'save_queries' => TRUE | |
); | |
"@ | |
Remove-Item index.php | |
Move-Item -Path public\* -Destination . | |
((Get-Content -path index.php -Raw) -replace '../system','system') | Set-Content -Path index.php | |
((Get-Content -path index.php -Raw) -replace '../application','application') | Set-Content -Path index.php | |
- task: ArchiveFiles@2 | |
displayName: 'Archive files' | |
inputs: | |
rootFolderOrFile: '$(rootFolder)' | |
includeRootFolder: false | |
archiveType: zip | |
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip | |
replaceExistingArchive: true | |
- upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip | |
displayName: 'Upload package' | |
artifact: drop | |
- stage: Deploy | |
displayName: 'Deploy Web App' | |
dependsOn: Build | |
condition: succeeded() | |
jobs: | |
- deployment: DeploymentJob | |
pool: | |
vmImage: $(vmImageName) | |
environment: $(environmentName) | |
strategy: | |
runOnce: | |
deploy: | |
steps: | |
- task: AzureWebApp@1 | |
displayName: 'Deploy Azure Web App : tonyq-mapfiddle' | |
inputs: | |
azureSubscription: $(azureSubscription) | |
appName: $(webAppName) | |
package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment