Skip to content

Commit

Permalink
Update the workshop examples: (#495)
Browse files Browse the repository at this point in the history
* Add a bundle output to porter-tf and porter-tf-aci
* Update the update/uninstall steps to not print anything
* Updated porter-tf-aci to deploy a trivial webapp to ACI
  • Loading branch information
jeremyrickard authored Aug 5, 2019
1 parent 533ed71 commit ad49f02
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 99 deletions.
6 changes: 6 additions & 0 deletions workshop/porter-tf-aci/azure/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM golang:latest
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN go build -o main .
CMD ["/app/main"]
23 changes: 23 additions & 0 deletions workshop/porter-tf-aci/azure/app/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
package main

import (
"fmt"
"log"
"net/http"
"os"
)

func handle(w http.ResponseWriter, r *http.Request) {
sqlFQDN := os.Getenv("MYSQL_FQDN")
if sqlFQDN == "" {
http.Error(w, "couldn't find MYSQL FQDN", http.StatusInternalServerError)
}

w.Write([]byte(fmt.Sprintf("Hello, I'm a webserver that wants to connect to a MYSQL at %s", sqlFQDN)))
}

func main() {

http.HandleFunc("/", handle)

fmt.Printf("Server starting on port 8080\n")
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal(err)
}
}
82 changes: 26 additions & 56 deletions workshop/porter-tf-aci/azure/bundle/porter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ parameters:
- name: database-name
type: string

outputs:
- name: IP_ADDRESS
type: string

imageMap:
websvc:
description: "A simple web service"
imageType: "docker"
image: "jeremyrickard/devops-days-msp@sha256:85b1a9b4b60a4cf73a23517dad677e64edf467107fa7d58fce9c50e6a3e4c914"
digest: "sha256:85b1a9b4b60a4cf73a23517dad677e64edf467107fa7d58fce9c50e6a3e4c914"

install:
- azure:
description: "Create an Azure Storage Account"
Expand Down Expand Up @@ -89,66 +100,25 @@ install:
parameters:
containerName: "{{ bundle.parameters.server-name }}-aci-go"
location: "{{ bundle.parameters.location }}"
imageName: "nginx:1.17.2"
imageName: "jeremyrickard/devops-days-msp@sha256:85b1a9b4b60a4cf73a23517dad677e64edf467107fa7d58fce9c50e6a3e4c914"
mysqlFQDN: "{{bundle.outputs.mysql_fqdn}}"
port: "80"
port: "8080"
outputs:
- name: "IP_ADDRESS"
key: "IP_ADDRESS"

upgrade:
- terraform:
description: "Update Azure MySQL With Terraform"
autoApprove: true
input: false
backendConfig:
key: "{{ bundle.name }}.tfstate"
storage_account_name: "{{ bundle.parameters.backend_storage_account }}"
container_name: "{{ bundle.parameters.backend_storage_container }}"
access_key: "{{ bundle.outputs.STORAGE_ACCOUNT_KEY }}"
vars:
backend_storage_account: "{{ bundle.parameters.backend_storage_account }}"
subscription_id: "{{bundle.credentials.subscription_id}}"
tenant_id: "{{bundle.credentials.tenant_id}}"
client_id: "{{bundle.credentials.client_id}}"
client_secret: "{{bundle.credentials.client_secret}}"
server-name: "{{bundle.parameters.server-name}}"
- exec:
description: "Perform an upgrade"
command: "bash"
arguments:
- "-c"
- "echo Not implemented yet"

uninstall:
- azure:
description: "Create an ACI Instance"
type: aci
name: "{{ bundle.name }}-aci"
resourceGroup: "{{ bundle.parameters.backend_storage_resource_group }}"
parameters:
name: "{{ bundle.name }}-aci-go"
location: "{{ bundle.parameters.location }}"
image: "nginx:1.17.2"

- terraform:
description: "Remove Azure CosmosDB and Event Hubs"
autoApprove: true
input: false
vars:
subscription_id: "{{bundle.credentials.subscription_id}}"
tenant_id: "{{bundle.credentials.tenant_id}}"
client_id: "{{bundle.credentials.client_id}}"
client_secret: "{{bundle.credentials.client_secret}}"
database_name: "{{bundle.parameters.database-name}}"
resource_group_name: "{{bundle.parameters.resource_group_name}}"
resource_group_location: "{{bundle.parameters.location}}"
backendConfig:
key: "{{ bundle.name }}.tfstate"
storage_account_name: "{{ bundle.parameters.storage_account_name }}"
container_name: "{{ bundle.parameters.storage_container_name }}"
access_key: "{{ bundle.parameters.tf_storage_account_key }}"

- azure:
description: "Create an Azure Storage Account"
type: storage
name: "{{ bundle.parameters.backend_storage_account }}"
resourceGroup: "{{ bundle.parameters.backend_storage_resource_group }}"
parameters:
location: "{{ bundle.parameters.location }}"
storageAccountName: "{{ bundle.parameters.backend_storage_account }}"
storageContainerName: "{{ bundle.parameters.backend_storage_container }}"
- exec:
description: "Perform an uninstall"
command: "bash"
arguments:
- "-c"
- "echo Not implemented yet"
60 changes: 17 additions & 43 deletions workshop/porter-tf/azure/porter.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mixins:
- azure
- exec
- terraform

name: porter-workshop-tf
Expand Down Expand Up @@ -47,6 +48,10 @@ parameters:
- name: database-name
type: string

outputs:
- name: STORAGE_ACCOUNT_KEY
type: string

install:
- azure:
description: "Create an Azure Storage Account"
Expand Down Expand Up @@ -79,48 +84,17 @@ install:
database-name: "{{bundle.parameters.database-name}}"

upgrade:
- terraform:
description: "Update Azure MySQL With Terraform"
autoApprove: true
input: false
backendConfig:
key: "{{ bundle.name }}.tfstate"
storage_account_name: "{{ bundle.parameters.backend_storage_account }}"
container_name: "{{ bundle.parameters.backend_storage_container }}"
access_key: "{{ bundle.outputs.STORAGE_ACCOUNT_KEY }}"
vars:
backend_storage_account: "{{ bundle.parameters.backend_storage_account }}"
subscription_id: "{{bundle.credentials.subscription_id}}"
tenant_id: "{{bundle.credentials.tenant_id}}"
client_id: "{{bundle.credentials.client_id}}"
client_secret: "{{bundle.credentials.client_secret}}"
server-name: "{{bundle.parameters.server-name}}"
- exec:
description: "Perform an upgrade"
command: "bash"
arguments:
- "-c"
- "echo Not implemented yet"

uninstall:
- terraform:
description: "Remove Azure CosmosDB and Event Hubs"
autoApprove: true
input: false
vars:
subscription_id: "{{bundle.credentials.subscription_id}}"
tenant_id: "{{bundle.credentials.tenant_id}}"
client_id: "{{bundle.credentials.client_id}}"
client_secret: "{{bundle.credentials.client_secret}}"
database_name: "{{bundle.parameters.database-name}}"
resource_group_name: "{{bundle.parameters.resource_group_name}}"
resource_group_location: "{{bundle.parameters.location}}"
backendConfig:
key: "{{ bundle.name }}.tfstate"
storage_account_name: "{{ bundle.parameters.storage_account_name }}"
container_name: "{{ bundle.parameters.storage_container_name }}"
access_key: "{{ bundle.parameters.tf_storage_account_key }}"

- azure:
description: "Create an Azure Storage Account"
type: storage
name: "{{ bundle.parameters.backend_storage_account }}"
resourceGroup: "{{ bundle.parameters.backend_storage_resource_group }}"
parameters:
location: "{{ bundle.parameters.location }}"
storageAccountName: "{{ bundle.parameters.backend_storage_account }}"
storageContainerName: "{{ bundle.parameters.backend_storage_container }}"
- exec:
description: "Perform an uninstall"
command: "bash"
arguments:
- "-c"
- "echo Not implemented yet"

0 comments on commit ad49f02

Please sign in to comment.