Skip to content
This repository has been archived by the owner on Aug 24, 2023. It is now read-only.

Commit

Permalink
Added advanced example
Browse files Browse the repository at this point in the history
Bump version
  • Loading branch information
StiviiK committed May 26, 2020
1 parent 33b0333 commit 6666ae2
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker-build-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@master

- uses: jerray/publish-docker-action@master
with:
username: ${{ secrets.DOCKER_USERNAME }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docker-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@master

- uses: jerray/publish-docker-action@master
with:
username: ${{ secrets.DOCKER_USERNAME }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ jobs:
uses: actions/setup-go@v1
with:
go-version: 1.14

- name: Check out source code
uses: actions/checkout@v1

- name: Build
env:
GOPROXY: "https://proxy.golang.org"
CGO_ENABLED: 0
GOOS: linux
GOARCH: amd64
run: go build -a -installsuffix cgo -ldflags="-w -s" .

- name: Test
env:
GOPROXY: "https://proxy.golang.org"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Additionally are the following outputs available:
## Usage

```yml
- uses: whiteducksoftware/azure-arm-action@v2.3
- uses: whiteducksoftware/azure-arm-action@v3
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
resourceGroupName: <YourResourceGroup>
Expand All @@ -56,14 +56,14 @@ Additionally are the following outputs available:
```yml
on: [push]
name: AzureLoginSample
name: ARMActionSample

jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: whiteducksoftware/azure-arm-action@v2.3
- uses: whiteducksoftware/azure-arm-action@v3
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
resourceGroupName: <YourResourceGroup>
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ branding:
icon: package
runs:
using: 'docker'
image: 'docker://whiteduck/azure-arm-action:v2.3'
image: 'docker://whiteduck/azure-arm-action:v3'
54 changes: 54 additions & 0 deletions examples/Advanced.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Advanced example on how to use this Action
In this exmaple we deploy 2 templates (for the sake of the example the same template) but the seccond one depends on the first one as we need first the output of first one and seccond we need to override a parameter in the seccond template.
Our template has two outputs `location` and `containerName`. But here we only interested in `containerName`, the first template will output that one and the seccond one requires that and appends `-overriden` so we can see it got overriden.

## Steps
```yaml
- uses: whiteducksoftware/azure-arm-action@v3
id: deploy
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
resourceGroupName: azurearmaction
templateLocation: examples/template/template.json
parameters: examples/template/parameters.json
deploymentName: github-advanced-test
```
Here we see a normal use of the Action, we pass the template as json file as well as the parameters. If we look into the `template.json` File we can see at the very bottom the defined outputs:
```json
{
..
"outputs": {
...
"containerName": {
"type": "string",
"value": "[parameters('containerName')]"
}
}
}
```
And we know our Action writes this output(s) to an action output variable with the same name, we can access it using `${{ steps.deploy.outputs.containerName }}` (Note: `deploy` comes from the `id` field from above.)

If we now add a Shell script with a simple echo from that value,
```yaml
- run: echo ${{ steps.deploy.outputs.containerName }}
```
we can see that on the console will be `github-action` printed.

Now we add our seccond deployment which relies on that value and modfies the `containerName` parameter,
```yaml
- uses: whiteducksoftware/azure-arm-action@v3
id: deploy2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
resourceGroupName: azurearmaction
templateLocation: examples/template/template.json
parameters: examples/template/parameters.json
deploymentName: github-advanced-test
overrideParameters: |
containerName=${{ steps.deploy.outputs.containerName }}-overriden
```
Look at the `overrideParameters` section, where we either could plug in another `parameter.json` File or we do it like here with line seperated key-value pairs. If we now add again a shell script to see our ouput,
```yaml
- run: echo ${{ steps.deploy2.outputs.containerName }}
```
we can see that on the console will be `github-action-overriden` printed.
36 changes: 36 additions & 0 deletions examples/advanced-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Unit Tests
on:
pull_request:
push:
branches:
- 'master'

jobs:
test_action_job:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1

- uses: whiteducksoftware/azure-arm-action@v3
id: deploy
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
resourceGroupName: azurearmaction
templateLocation: examples/template/template.json
parameters: examples/template/parameters.json
deploymentName: github-advanced-test

- run: echo ${{ steps.deploy.outputs.containerName }}

- uses: whiteducksoftware/azure-arm-action@v3
id: deploy2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
resourceGroupName: azurearmaction
templateLocation: examples/template/template.json
parameters: examples/template/parameters.json
deploymentName: github-advanced-test
overrideParameters: |
containerName=${{ steps.deploy.outputs.containerName }}-overriden
- run: echo ${{ steps.deploy2.outputs.containerName }}
41 changes: 41 additions & 0 deletions examples/template/parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"containerName": {
"value": "github-action"
},
"location": {
"value": "westeurope"
},
"imageType": {
"value": "Public"
},
"imageName": {
"value": "whiteduck/sample-mvc"
},
"osType": {
"value": "Linux"
},
"numberCpuCores": {
"value": "1"
},
"memory": {
"value": "0.5"
},
"restartPolicy": {
"value": "OnFailure"
},
"ipAddressType": {
"value": "Public"
},
"ports": {
"value": [
{
"port": "8080",
"protocol": "TCP"
}
]
}
}
}
91 changes: 91 additions & 0 deletions examples/template/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"containerName": {
"type": "string"
},
"imageType": {
"type": "string",
"allowedValues": [
"Public",
"Private"
]
},
"imageName": {
"type": "string"
},
"osType": {
"type": "string",
"allowedValues": [
"Linux",
"Windows"
]
},
"numberCpuCores": {
"type": "string"
},
"memory": {
"type": "string"
},
"restartPolicy": {
"type": "string",
"allowedValues": [
"OnFailure",
"Always",
"Never"
]
},
"ipAddressType": {
"type": "string"
},
"ports": {
"type": "array"
}
},
"resources": [
{
"location": "[parameters('location')]",
"name": "[parameters('containerName')]",
"type": "Microsoft.ContainerInstance/containerGroups",
"apiVersion": "2018-10-01",
"properties": {
"containers": [
{
"name": "[parameters('containerName')]",
"properties": {
"image": "[parameters('imageName')]",
"resources": {
"requests": {
"cpu": "[int(parameters('numberCpuCores'))]",
"memoryInGB": "[float(parameters('memory'))]"
}
},
"ports": "[parameters('ports')]"
}
}
],
"restartPolicy": "[parameters('restartPolicy')]",
"osType": "[parameters('osType')]",
"ipAddress": {
"type": "[parameters('ipAddressType')]",
"ports": "[parameters('ports')]"
}
},
"tags": {}
}
],
"outputs": {
"location": {
"type": "string",
"value": "[parameters('location')]"
},
"containerName": {
"type": "string",
"value": "[parameters('containerName')]"
}
}
}
1 change: 0 additions & 1 deletion pkg/github/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ func wrapReadRawParameters(v string) (interface{}, error) {
return false
default:
return unicode.IsSpace(c)

}
}

Expand Down

0 comments on commit 6666ae2

Please sign in to comment.