|  | 
|  | 1 | +# Web App | 
|  | 2 | + | 
|  | 3 | +Continuously build and deploy a Go web app using Azure App Service and Azure | 
|  | 4 | +Container Registry. | 
|  | 5 | + | 
|  | 6 | +This package includes a basic Go web app and scripts to set up infrastructure | 
|  | 7 | +for it in Azure. | 
|  | 8 | + | 
|  | 9 | +Requires [Azure CLI][]. | 
|  | 10 | + | 
|  | 11 | +## Try It! | 
|  | 12 | + | 
|  | 13 | +Set configuration in a local .env file in the package root by copying | 
|  | 14 | +`.env.tpl` to `.env`. Change `AZURE_BASE_NAME` to something relatively unique | 
|  | 15 | +to you; for example you might include your name. Then run ./[setup.sh][] to | 
|  | 16 | +build and deploy your container to Container Registry and App Service. | 
|  | 17 | + | 
|  | 18 | +If run within the Azure Go SDK samples repo, this will carry out a one-off | 
|  | 19 | +build and push to your registry, which will trigger refresh of the App Service | 
|  | 20 | +Web App.  If you stick with the script defaults, you can visit your app at | 
|  | 21 | +`https://${AZURE_BASE_NAME}-webapp.azurewebsites.net/`. | 
|  | 22 | + | 
|  | 23 | +### Continuous Build and Deploy | 
|  | 24 | + | 
|  | 25 | +Follow these steps to set up continuous build and deploy: | 
|  | 26 | + | 
|  | 27 | +1. Copy the contents of this package to your own fresh git repo and push it to GitHub. | 
|  | 28 | +2. Specify an image name in env var `IMAGE_NAME` (e.g. in `.env`) that matches | 
|  | 29 | +   your GitHub 'org/repo' structure. | 
|  | 30 | +3. Run `./setup.sh`. It will arrange continuous build and deploy for you from | 
|  | 31 | +   the specified repo/image name. | 
|  | 32 | + | 
|  | 33 | +**NOTE**: Container Registry Build requires a [GitHub personal access | 
|  | 34 | +token](https://github.com/settings/tokens); you need to get one from the linked | 
|  | 35 | +page and set it in a local environment variable `GH_TOKEN`, e.g. `export | 
|  | 36 | +GH_TOKEN=mylongtokenstring`. You can also add it to your local `.env` file for | 
|  | 37 | +persistence. | 
|  | 38 | + | 
|  | 39 | +To test continuous integration, now make a change and `git push` it to your | 
|  | 40 | +repo. The Container Registry build task should detect the change, rebuild your | 
|  | 41 | +container, and notify App Service; which should then refresh and reload your | 
|  | 42 | +container image and app. | 
|  | 43 | + | 
|  | 44 | +## More Details | 
|  | 45 | + | 
|  | 46 | +[setup.sh][] ensures an Azure resource group, container registry, app service | 
|  | 47 | +plan, and container-based web app are provisioned and connected in the | 
|  | 48 | +subscription currently logged in to [Azure CLI][]. | 
|  | 49 | + | 
|  | 50 | +It uses the following environment variables to choose names: | 
|  | 51 | + | 
|  | 52 | +* IMAGE\_NAME: Name of container image (aka "repo"). | 
|  | 53 | +* IMAGE\_TAG: Tag for container image. | 
|  | 54 | +* AZURE\_BASE\_NAME: Prefix for Azure resources. | 
|  | 55 | +* AZURE\_DEFAULT\_LOCATION: Location for Azure resources.  | 
|  | 56 | + | 
|  | 57 | +These names can be specified in a .env file in the root of the package. If a | 
|  | 58 | +`.env` file isn't found, `.env.tpl` is copied to `.env` and used. | 
|  | 59 | + | 
|  | 60 | +Explicit parameters can also be passed, see comments at beginning of | 
|  | 61 | +[setup.sh][] for details. | 
|  | 62 | + | 
|  | 63 | +[Azure CLI]: https://github.com/Azure/azure-cli | 
|  | 64 | +[setup.sh]: ./setup.sh | 
0 commit comments