Skip to content

Commit

Permalink
app_service: adding docker compose example to docs (#2913)
Browse files Browse the repository at this point in the history
adding docker compose examples to app service docs

Fixes #2827
Fixes #1633
Fixes #1981
  • Loading branch information
ghostinthewires authored and katbyte committed Feb 26, 2019
1 parent 677312d commit 8c84d52
Show file tree
Hide file tree
Showing 30 changed files with 478 additions and 157 deletions.
16 changes: 2 additions & 14 deletions examples/app-service/README.md
@@ -1,15 +1,3 @@
# Azure App Service Sample
## Examples of using the App Service Resources

Sample to deploy an App Service within an App Service Plan.

## Creates

1. A Resource Group
2. An [App Service Plan](https://docs.microsoft.com/en-us/azure/app-service/azure-web-sites-web-hosting-plans-in-depth-overview)
3. An [App Service](https://azure.microsoft.com/en-gb/services/app-service/) configured for usage with .NET 4.x Application

## Usage

- Provide values to all variables (credentials and names).
- Create with `terraform apply`
- Destroy all with `terraform destroy --force`
This folder contains examples of using the App Service resources.
55 changes: 0 additions & 55 deletions examples/app-service/app.tf

This file was deleted.

25 changes: 25 additions & 0 deletions examples/app-service/docker-basic/README.md
@@ -0,0 +1,25 @@
# Example: a Linux App Service running a Docker container

This example provisions a Linux App Service which runs a single Docker container.

### Notes

* The Container is launched on the first HTTP Request, which can take a while.
* Continuous Deployment of a single Docker Container can be achieved using the App Setting `DOCKER_ENABLE_CI` to `true`.
* If you're not using App Service Slots and Deployments are handled outside of Terraform - [it's possible to ignore changes to specific fields in the configuration using `ignore_changes` within Terraform's `lifecycle` block](https://www.terraform.io/docs/configuration/resources.html#lifecycle), for example:

```hcl
resource "azurerm_app_service" "test" {
# ...
site_config = {
# ...
linux_fx_version = "DOCKER|appsvcsample/python-helloworld:0.1.2"
}
lifecycle {
ignore_changes = [
"site_config.0.linux_fx_version", # deployments are made outside of Terraform
]
}
}
```
42 changes: 42 additions & 0 deletions examples/app-service/docker-basic/main.tf
@@ -0,0 +1,42 @@
provider "azurerm" {
# if you're using a Service Principal (shared account) then either set the environment variables, or fill these in:
# subscription_id = "..."
# client_id = "..."
# client_secret = "..."
# tenant_id = "..."
}

resource "azurerm_resource_group" "main" {
name = "${var.prefix}-resources"
location = "${var.location}"
}

resource "azurerm_app_service_plan" "main" {
name = "${var.prefix}-asp"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
kind = "Linux"
reserved = true

sku {
tier = "Standard"
size = "S1"
}
}

resource "azurerm_app_service" "main" {
name = "${var.prefix}-appservice"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
app_service_plan_id = "${azurerm_app_service_plan.main.id}"

site_config {
app_command_line = ""
linux_fx_version = "DOCKER|appsvcsample/python-helloworld:latest"
}

app_settings {
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false",
"DOCKER_REGISTRY_SERVER_URL" = "https://index.docker.io"
}
}
7 changes: 7 additions & 0 deletions examples/app-service/docker-basic/outputs.tf
@@ -0,0 +1,7 @@
output "app_service_name" {
value = "${azurerm_app_service.main.name}"
}

output "app_service_default_hostname" {
value = "https://${azurerm_app_service.main.default_site_hostname}"
}
7 changes: 7 additions & 0 deletions examples/app-service/docker-basic/variables.tf
@@ -0,0 +1,7 @@
variable "prefix" {
description = "The prefix used for all resources in this example"
}

variable "location" {
description = "The Azure location where all resources in this example should be created"
}
24 changes: 24 additions & 0 deletions examples/app-service/docker-compose/README.md
@@ -0,0 +1,24 @@
# Example: a Linux App Service running multiple containers from a Docker Compose file.

This example provisions a Linux App Service which runs multiple Docker Containers from Docker Compose file.

### Notes

* The Container is launched on the first HTTP Request, which can take a while.
* If you're not using App Service Slots and Deployments are handled outside of Terraform - [it's possible to ignore changes to specific fields in the configuration using `ignore_changes` within Terraform's `lifecycle` block](https://www.terraform.io/docs/configuration/resources.html#lifecycle), for example:

```hcl
resource "azurerm_app_service" "test" {
# ...
site_config = {
# ...
linux_fx_version = "COMPOSE|${base64encode(file("compose.yml"))}"
}
lifecycle {
ignore_changes = [
"site_config.0.linux_fx_version", # deployments are made outside of Terraform
]
}
}
```
27 changes: 27 additions & 0 deletions examples/app-service/docker-compose/docker-compose.yml
@@ -0,0 +1,27 @@
version: '3.3'

services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress

wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data:
41 changes: 41 additions & 0 deletions examples/app-service/docker-compose/main.tf
@@ -0,0 +1,41 @@
provider "azurerm" {
# if you're using a Service Principal (shared account) then either set the environment variables, or fill these in:
# subscription_id = "..."
# client_id = "..."
# client_secret = "..."
# tenant_id = "..."
}

resource "azurerm_resource_group" "main" {
name = "${var.prefix}-resources"
location = "${var.location}"
}

resource "azurerm_app_service_plan" "main" {
name = "${var.prefix}-asp"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
kind = "Linux"
reserved = true

sku {
tier = "Standard"
size = "S1"
}
}

resource "azurerm_app_service" "main" {
name = "${var.prefix}-appservice"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
app_service_plan_id = "${azurerm_app_service_plan.main.id}"

site_config {
app_command_line = ""
linux_fx_version = "COMPOSE|${base64encode(file("docker-compose.yml"))}"
}

app_settings {
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false"
}
}
7 changes: 7 additions & 0 deletions examples/app-service/docker-compose/outputs.tf
@@ -0,0 +1,7 @@
output "app_service_name" {
value = "${azurerm_app_service.main.name}"
}

output "app_service_default_hostname" {
value = "https://${azurerm_app_service.main.default_site_hostname}"
}
7 changes: 7 additions & 0 deletions examples/app-service/docker-compose/variables.tf
@@ -0,0 +1,7 @@
variable "prefix" {
description = "The prefix used for all resources in this example"
}

variable "location" {
description = "The Azure location where all resources in this example should be created"
}
24 changes: 24 additions & 0 deletions examples/app-service/docker-kubernetes/README.md
@@ -0,0 +1,24 @@
# Example: a Linux App Service running multiple containers from a Kubernetes Manifest

This example provisions a Linux App Service which runs multiple Docker Containers from a Kubernetes Manifest.

### Notes

* The Container is launched on the first HTTP Request, which can take a while.
* If you're not using App Service Slots and Deployments are handled outside of Terraform - [it's possible to ignore changes to specific fields in the configuration using `ignore_changes` within Terraform's `lifecycle` block](https://www.terraform.io/docs/configuration/resources.html#lifecycle), for example:

```hcl
resource "azurerm_app_service" "test" {
# ...
site_config = {
# ...
linux_fx_version = "KUBE|${base64encode(file("kubernetes.yml"))}"
}
lifecycle {
ignore_changes = [
"site_config.0.linux_fx_version", # deployments are made outside of Terraform
]
}
}
```
13 changes: 13 additions & 0 deletions examples/app-service/docker-kubernetes/kubernetes.yml
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Pod
metadata:
name: python
spec:
containers:
- name: web
image: appsvcsample/flaskapp:kube
# source code for this image repo come from "Get started with Docker Compose" on docker.com
ports:
- containerPort: 80
- name: redis
image: redis:alpine
41 changes: 41 additions & 0 deletions examples/app-service/docker-kubernetes/main.tf
@@ -0,0 +1,41 @@
provider "azurerm" {
# if you're using a Service Principal (shared account) then either set the environment variables, or fill these in:
# subscription_id = "..."
# client_id = "..."
# client_secret = "..."
# tenant_id = "..."
}

resource "azurerm_resource_group" "main" {
name = "${var.prefix}-resources"
location = "${var.location}"
}

resource "azurerm_app_service_plan" "main" {
name = "${var.prefix}-asp"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
kind = "Linux"
reserved = true

sku {
tier = "Standard"
size = "S1"
}
}

resource "azurerm_app_service" "main" {
name = "${var.prefix}-appservice"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
app_service_plan_id = "${azurerm_app_service_plan.main.id}"

site_config {
app_command_line = ""
linux_fx_version = "KUBE|${base64encode(file("kubernetes.yml"))}"
}

app_settings {
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false"
}
}
7 changes: 7 additions & 0 deletions examples/app-service/docker-kubernetes/outputs.tf
@@ -0,0 +1,7 @@
output "app_service_name" {
value = "${azurerm_app_service.main.name}"
}

output "app_service_default_hostname" {
value = "https://${azurerm_app_service.main.default_site_hostname}"
}
7 changes: 7 additions & 0 deletions examples/app-service/docker-kubernetes/variables.tf
@@ -0,0 +1,7 @@
variable "prefix" {
description = "The prefix used for all resources in this example"
}

variable "location" {
description = "The Azure location where all resources in this example should be created"
}
3 changes: 3 additions & 0 deletions examples/app-service/linux-basic/README.md
@@ -0,0 +1,3 @@
# Example: a Basic Linux App Service

This example provisions a basic Linux App Service.

0 comments on commit 8c84d52

Please sign in to comment.