Skip to content

Commit dd4545f

Browse files
authored
Merge pull request #105832 from cephalin/1666084
add pre/post deploy
2 parents abb89c8 + 3b16ff4 commit dd4545f

File tree

5 files changed

+87
-43
lines changed

5 files changed

+87
-43
lines changed

articles/app-service/containers/configure-language-dotnetcore.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,28 @@ Run the following command in the [Cloud Shell](https://shell.azure.com) to set t
3636
az webapp config set --name <app-name> --resource-group <resource-group-name> --linux-fx-version "DOTNETCORE|2.1"
3737
```
3838

39+
## Customize build automation
40+
41+
If you deploy your app using Git or zip packages with build automation turned on, the App Service build automation steps through the following sequence:
42+
43+
1. Run custom script if specified by `PRE_BUILD_SCRIPT_PATH`.
44+
1. Run `dotnet restore` to restore NuGet dependencies.
45+
1. Run `dotnet publish` to build a binary for production.
46+
1. Run custom script if specified by `POST_BUILD_SCRIPT_PATH`.
47+
48+
`PRE_BUILD_COMMAND` and `POST_BUILD_COMMAND` are environment variables that are empty by default. To run pre-build commands, define `PRE_BUILD_COMMAND`. To run post-build commands, define `POST_BUILD_COMMAND`.
49+
50+
The following example specifies the two variables to a series of commands, separated by commas.
51+
52+
```azurecli-interactive
53+
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings PRE_BUILD_COMMAND="echo foo, scripts/prebuild.sh"
54+
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings POST_BUILD_COMMAND="echo foo, scripts/postbuild.sh"
55+
```
56+
57+
For additional environment variables to customize build automation, see [Oryx configuration](https://github.com/microsoft/Oryx/blob/master/doc/configuration.md).
58+
59+
For more information on how App Service runs and builds ASP.NET Core apps in Linux, see [Oryx documentation: How .NET Core apps are detected and built](https://github.com/microsoft/Oryx/blob/master/doc/runtimes/dotnetcore.md).
60+
3961
## Access environment variables
4062

4163
In App Service, you can [set app settings](../configure-common.md?toc=%2fazure%2fapp-service%2fcontainers%2ftoc.json#configure-app-settings) outside of your app code. Then you can access them in any class using the standard ASP.NET Core dependency injection pattern:

articles/app-service/containers/configure-language-nodejs.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,32 @@ This setting specifies the Node.js version to use, both at runtime and during au
4040
> [!NOTE]
4141
> You should set the Node.js version in your project's `package.json`. The deployment engine runs in a separate container that contains all the supported Node.js versions.
4242
43+
## Customize build automation
44+
45+
If you deploy your app using Git or zip packages with build automation turned on, the App Service build automation steps through the following sequence:
46+
47+
1. Run custom script if specified by `PRE_BUILD_SCRIPT_PATH`.
48+
1. Run `npm install` without any flags, which includes npm `preinstall` and `postinstall` scripts and also installs `devDependencies`.
49+
1. Run `npm run build` if a build script is specified in your *package.json*.
50+
1. Run `npm run build:azure` if a build:azure script is specified in your *package.json*.
51+
1. Run custom script if specified by `POST_BUILD_SCRIPT_PATH`.
52+
53+
> [!NOTE]
54+
> As described in [npm docs](https://docs.npmjs.com/misc/scripts), scripts named `prebuild` and `postbuild` run before and after `build`, respectively, if specified. `preinstall` and `postinstall` run before and after `install`, respectively.
55+
56+
`PRE_BUILD_COMMAND` and `POST_BUILD_COMMAND` are environment variables that are empty by default. To run pre-build commands, define `PRE_BUILD_COMMAND`. To run post-build commands, define `POST_BUILD_COMMAND`.
57+
58+
The following example specifies the two variables to a series of commands, separated by commas.
59+
60+
```azurecli-interactive
61+
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings PRE_BUILD_COMMAND="echo foo, scripts/prebuild.sh"
62+
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings POST_BUILD_COMMAND="echo foo, scripts/postbuild.sh"
63+
```
64+
65+
For additional environment variables to customize build automation, see [Oryx configuration](https://github.com/microsoft/Oryx/blob/master/doc/configuration.md).
66+
67+
For more information on how App Service runs and builds Node.js apps in Linux, see [Oryx documentation: How Node.js apps are detected and built](https://github.com/microsoft/Oryx/blob/master/doc/runtimes/nodejs.md).
68+
4369
## Configure Node.js server
4470

4571
The Node.js containers come with [PM2](https://pm2.keymetrics.io/), a production process manager. You can configure your app to start with PM2, or with NPM, or with a custom command.

articles/app-service/containers/configure-language-php.md

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,56 +36,30 @@ Run the following command in the [Cloud Shell](https://shell.azure.com) to set t
3636
az webapp config set --name <app-name> --resource-group <resource-group-name> --linux-fx-version "PHP|7.2"
3737
```
3838

39-
## Run Composer
39+
## Customize build automation
4040

41-
By default, Kudu doesn't run [Composer](https://getcomposer.org/). To enable Composer automation during Kudu deployment, you need to supply a [custom deployment script](https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script).
41+
If you deploy your app using Git or zip packages with build automation turned on, the App Service build automation steps through the following sequence:
4242

43-
From a local terminal window, change directory to your repository root. Follow the [command-line installation steps](https://getcomposer.org/download/) to download *composer.phar*.
43+
1. Run custom script if specified by `PRE_BUILD_SCRIPT_PATH`.
44+
1. Run `php composer.phar install`.
45+
1. Run custom script if specified by `POST_BUILD_SCRIPT_PATH`.
4446

45-
Run the following commands:
47+
`PRE_BUILD_COMMAND` and `POST_BUILD_COMMAND` are environment variables that are empty by default. To run pre-build commands, define `PRE_BUILD_COMMAND`. To run post-build commands, define `POST_BUILD_COMMAND`.
4648

47-
```bash
48-
npm install kuduscript -g
49-
kuduscript --php --scriptType bash --suppressPrompt
50-
```
51-
52-
Your repository root now has two new files in addition to *composer.phar*: *.deployment* and *deploy.sh*. These files work both for Windows and Linux flavors of App Service.
53-
54-
Open *deploy.sh* and find the `Deployment` section. Replace the whole section with the following code:
55-
56-
```bash
57-
##################################################################################################################################
58-
# Deployment
59-
# ----------
49+
The following example specifies the two variables to a series of commands, separated by commas.
6050

61-
echo PHP deployment
62-
63-
# 1. KuduSync
64-
if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then
65-
"$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh"
66-
exitWithMessageOnError "Kudu Sync failed"
67-
fi
68-
69-
# 3. Initialize Composer Config
70-
initializeDeploymentConfig
71-
72-
# 4. Use composer
73-
echo "$DEPLOYMENT_TARGET"
74-
if [ -e "$DEPLOYMENT_TARGET/composer.json" ]; then
75-
echo "Found composer.json"
76-
pushd "$DEPLOYMENT_TARGET"
77-
php composer.phar install $COMPOSER_ARGS
78-
exitWithMessageOnError "Composer install failed"
79-
popd
80-
fi
81-
##################################################################################################################################
51+
```azurecli-interactive
52+
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings PRE_BUILD_COMMAND="echo foo, scripts/prebuild.sh"
53+
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings POST_BUILD_COMMAND="echo foo, scripts/postbuild.sh"
8254
```
8355

84-
Commit all your changes and deploy your code again. Composer should now be running as part of deployment automation.
56+
For additional environment variables to customize build automation, see [Oryx configuration](https://github.com/microsoft/Oryx/blob/master/doc/configuration.md).
57+
58+
For more information on how App Service runs and builds PHP apps in Linux, see [Oryx documentation: How PHP apps are detected and built](https://github.com/microsoft/Oryx/blob/master/doc/runtimes/php.md).
8559

8660
## Customize start-up
8761

88-
By default, the built-in PHP container run the Apache server. At start-up, it runs `apache2ctl -D FOREGROUND"`. If you like, you can run a different command at start-up, by running the following command in the [Cloud Shell](https://shell.azure.com):
62+
By default, the built-in PHP container runs the Apache server. At start-up, it runs `apache2ctl -D FOREGROUND"`. If you like, you can run a different command at start-up, by running the following command in the [Cloud Shell](https://shell.azure.com):
8963

9064
```azurecli-interactive
9165
az webapp config set --resource-group <resource-group-name> --name <app-name> --startup-file "<custom-command>"

articles/app-service/containers/how-to-configure-python.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@ Run the following command in the [Cloud Shell](https://shell.azure.com) to set t
4444
az webapp config set --resource-group <resource-group-name> --name <app-name> --linux-fx-version "PYTHON|3.7"
4545
```
4646

47+
## Customize build automation
48+
49+
If you deploy your app using Git or zip packages with build automation turned on, the App Service build automation steps through the following sequence:
50+
51+
1. Run custom script if specified by `PRE_BUILD_SCRIPT_PATH`.
52+
1. Run `pip install -r requirements.txt`.
53+
1. If *manage.py* is found in the root of the repository, run *manage.py collectstatic*. However, if `DISABLE_COLLECTSTATIC` is set to `true`, this step is skipped.
54+
1. Run custom script if specified by `POST_BUILD_SCRIPT_PATH`.
55+
56+
`PRE_BUILD_COMMAND`, `POST_BUILD_COMMAND`, and `DISABLE_COLLECTSTATIC` are environment variables that are empty by default. To run pre-build commands, define `PRE_BUILD_COMMAND`. To run post-build commands, define `POST_BUILD_COMMAND`. To disable running collectstatic when building Django apps, set `DISABLE_COLLECTSTATIC=true`.
57+
58+
The following example specifies the two variables to a series of commands, separated by commas.
59+
60+
```azurecli-interactive
61+
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings PRE_BUILD_COMMAND="echo foo, scripts/prebuild.sh"
62+
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings POST_BUILD_COMMAND="echo foo, scripts/postbuild.sh"
63+
```
64+
65+
For additional environment variables to customize build automation, see [Oryx configuration](https://github.com/microsoft/Oryx/blob/master/doc/configuration.md).
66+
67+
For more information on how App Service runs and builds Python apps in Linux, see [Oryx documentation: How Python apps are detected and built](https://github.com/microsoft/Oryx/blob/master/doc/runtimes/python.md).
68+
4769
## Container characteristics
4870

4971
Python apps deployed to App Service on Linux run within a Docker container that's defined in the [App Service Python GitHub repository](https://github.com/Azure-App-Service/python). You can find the image configurations inside the version-specific directories.

articles/app-service/containers/tutorial-php-mysql-app.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,15 +398,15 @@ remote: Running deployment command...
398398
< Output has been truncated for readability >
399399
```
400400

401-
> [!NOTE]
401+
<!-- > [!NOTE]
402402
> You may notice that the deployment process installs [Composer](https://getcomposer.org/) packages at the end. App Service does not run these automations during default deployment, so this sample repository has three additional files in its root directory to enable it:
403403
>
404404
> - `.deployment` - This file tells App Service to run `bash deploy.sh` as the custom deployment script.
405405
> - `deploy.sh` - The custom deployment script. If you review the file, you will see that it runs `php composer.phar install` after `npm install`.
406406
> - `composer.phar` - The Composer package manager.
407407
>
408-
> You can use this approach to add any step to your Git-based deployment to App Service. For more information, see [Run Composer](configure-language-php.md#run-composer).
409-
>
408+
> You can use this approach to add any step to your Git-based deployment to App Service. For more information, see [Run Composer](configure-language-php.md#run-composer). -->
409+
>
410410
411411
### Browse to the Azure app
412412

0 commit comments

Comments
 (0)