Skip to content

Commit

Permalink
initial attempt at deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Kruining committed Nov 21, 2024
1 parent f88c283 commit 591ddf8
Show file tree
Hide file tree
Showing 36 changed files with 632 additions and 145 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Publish to registry

on:
push:
branches:
- main

jobs:
prepare:
name: Calculate next version
runs-on: ubuntu-latest
outputs:
semver: ${{ steps.gitversion.outputs.SemVer }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: "5.x"

- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/[email protected]
with:
useConfigFile: true

infra:
name: Infrastructure
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
infrastructure
- name: Az CLI login
uses: azure/login@v2
with:
client-id: ${{ secrets.TRICEP_CLIENT_ID }}
tenant-id: ${{ secrets.TRICEP_TENANT_ID }}
subscription-id: ${{ secrets.TRICEP_SUBSCRIPTION_ID }}

- name: Deploy bicep
uses: Azure/cli@v2
with:
azcliversion: 2.66.0
inlineScript: |
az deployment sub create \
--location westeurope \
--template-file infrastructure/main.bicep \
--parameters infrastructure/params/main.prd.bicepparam \
publish:
name: Publish
runs-on: ubuntu-latest
needs: [ prepare, infra ]
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
src
- name: Az CLI login
uses: azure/login@v2
with:
client-id: ${{ secrets.TRICEP_CLIENT_ID }}
tenant-id: ${{ secrets.TRICEP_TENANT_ID }}
subscription-id: ${{ secrets.TRICEP_SUBSCRIPTION_ID }}

- name: Publish Bicep module
uses: azure/cli@v1
with:
inlineScript: |
for x in ls -al src; do
echo "$x"
done
# az bicep publish \
# --file src/main.bicep \
# --target 'br:toycompany.azurecr.io/main:${{needs.prepare.outputs.semver}}'
20 changes: 20 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatchTag
assembly-informational-format: "{InformationalVersion}"
mode: Mainline
tag-prefix: "[vV]"
continuous-delivery-fallback-tag: ci
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
patch-version-bump-message: '\+semver:\s?(fix|patch)'
no-bump-message: '\+semver:\s?(none|skip)'
legacy-semver-padding: 4
build-metadata-padding: 4
commits-since-version-source-padding: 4
commit-message-incrementing: Enabled
branches: {}
ignore:
sha: []
increment: Inherit
commit-date-format: yyyy-MM-dd
merge-message-formats: {}
1 change: 1 addition & 0 deletions dev.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ Function Watch {
}
}

Build
Watch
116 changes: 64 additions & 52 deletions example/containerApps/environment/containers.bicep
Original file line number Diff line number Diff line change
@@ -1,17 +1,60 @@
import { Context } from '../../../src/types.bicep'
import { withManagedIdentity } from '../../../src/common/identity.bicep'
import { containerRegistry } from '../../../src/recommended/container-registry.bicep'
import { containerApp, containerAppEnvironment } from '../../../src/recommended/container-app.bicep'
import { with_name } from '../../../src/common/context.bicep'
import { with_managed_identity } from '../../../src/common/identity.bicep'
import { container_registry } from '../../../src/recommended/container-registry.bicep'
import {
container_app
container
with_dapr
container_app_environment
with_auto_scaling
with_environment
with_app_logs
} from '../../../src/recommended/container-app.bicep'

targetScope = 'resourceGroup'

param context Context
param customerId string
param sharedKey string

var containerRegistryConfig = containerRegistry(context, [])
var containerAppEnvironmentConfig = containerAppEnvironment(context, [])
var containerAppConfig = containerApp(context, [
withManagedIdentity()
var containerRegistryConfig = container_registry(with_name(context, context.project), [])
var containerAppEnvironmentConfig = container_app_environment(with_name(context, context.project), [
with_app_logs(customerId, sharedKey)
])
var containerApp1Config = container_app(
with_name(context, 'app_1'),
[
container('container 1', 'some-container-image')
container('container 2', 'some-other-container-image')
],
[
with_managed_identity()
with_environment(environment.id)
with_dapr(context, 3000)
with_auto_scaling(0, 1, {
ruleName: {
concurrentRequests: '10'
}
})
]
)
var containerApp2Config = container_app(
with_name(context, 'app_2'),
[
container('container 1', 'some-third-container-image')
],
[
with_managed_identity()
with_environment(environment.id)
with_dapr(context, 3001)
with_auto_scaling(1, 1, {
ruleName: {
concurrentRequests: '10'
}
})
]
)

resource registry 'Microsoft.ContainerRegistry/registries@2023-07-01' = {
name: containerRegistryConfig.name
Expand All @@ -25,28 +68,16 @@ resource environment 'Microsoft.App/managedEnvironments@2024-03-01' = {
name: containerAppEnvironmentConfig.name
location: containerAppEnvironmentConfig.location
tags: containerAppEnvironmentConfig.tags
sku: containerAppEnvironmentConfig.sku
properties: containerAppEnvironmentConfig.properties

// properties: {
// appLogsConfiguration: {
// destination: 'log-analytics'
// logAnalyticsConfiguration: {
// customerId: logAnalytics.properties.customerId
// sharedKey: logAnalytics.listKeys().primarySharedKey
// }
// }
// }
}

resource app 'Microsoft.App/containerApps@2024-03-01' = {
name: containerAppConfig.name
location: containerAppConfig.location
identity: containerAppConfig.identity
properties: containerAppConfig.properties
resource app_1 'Microsoft.App/containerApps@2024-03-01' = {
name: containerApp1Config.name
location: containerApp1Config.location
identity: containerApp1Config.identity
properties: containerApp1Config.properties

// properties: {
// managedEnvironmentId: containerAppEnv.id
// configuration: {
// ingress: {
// external: true
Expand All @@ -66,34 +97,15 @@ resource app 'Microsoft.App/containerApps@2024-03-01' = {
// }
// ]
// }
// template: {
// revisionSuffix: 'firstrevision'
// containers: [
// {
// name: containerAppName
// image: acrImportImage.outputs.importedImages[0].acrHostedImage
// resources: {
// cpu: json('.25')
// memory: '.5Gi'
// }
// }
// ]
// scale: {
// minReplicas: minReplica
// maxReplicas: maxReplica
// rules: [
// {
// name: 'http-requests'
// http: {
// metadata: {
// concurrentRequests: '10'
// }
// }
// }
// ]
// }
// }
// }
}

output app resource'Microsoft.App/containerApps@2022-06-01-preview' = app
resource app_2 'Microsoft.App/containerApps@2024-03-01' = {
name: containerApp2Config.name
location: containerApp2Config.location
identity: containerApp2Config.identity
properties: containerApp2Config.properties
}

output app_1 resource'Microsoft.App/containerApps@2022-06-01-preview' = app_1
output app_2 resource'Microsoft.App/containerApps@2022-06-01-preview' = app_2
19 changes: 15 additions & 4 deletions example/containerApps/environment/main.bicep
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Context } from '../../../src/types.bicep'
import { createContext } from '../../../src/common/context.bicep'
import { resourceGroup } from '../../../src/recommended/resource-group.bicep'
import { create_context } from '../../../src/common/context.bicep'
import { resource_group } from '../../../src/recommended/resource-group.bicep'

targetScope = 'subscription'

param deployedAt string
param environment string

var context = createContext({
var context = create_context({
name: 'appName'
project: 'project'
nameConventionTemplate: '$type-$env-$loc-$name'
environment: environment
location: 'westeurope'
Expand All @@ -17,7 +18,7 @@ var context = createContext({
tags: {}
})

var resourceGroupConfig = resourceGroup(context, [])
var resourceGroupConfig = resource_group(context, [])

resource group 'Microsoft.Resources/resourceGroups@2024-07-01' = {
name: resourceGroupConfig.name
Expand All @@ -26,10 +27,20 @@ resource group 'Microsoft.Resources/resourceGroups@2024-07-01' = {
properties: resourceGroupConfig.properties
}

module monitoring 'monitoring.bicep' = {
name: 'monitoring'
scope: group
params: {
context: context
}
}

module containers 'containers.bicep' = {
name: 'containers'
scope: group
params: {
context: context
customerId: 'monitoring.outputs.la_customerId'
sharedKey: 'monitoring.outputs.la_sharedKey'
}
}
18 changes: 18 additions & 0 deletions example/containerApps/environment/monitoring.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Context } from '../../../src/types.bicep'
import { log_analytics } from '../../../src/recommended/log-analytics.bicep'

targetScope = 'resourceGroup'

param context Context

var logAnalyticsConfig = log_analytics(context, [])

resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2021-06-01' = {
name: logAnalyticsConfig.name
location: logAnalyticsConfig.location
properties: logAnalyticsConfig.properties
}

// output logAnalytics resource'Microsoft.OperationalInsights/workspaces@2021-06-01' = logAnalytics
output la_customerId string = logAnalytics.properties.customerId
output la_sharedKey string = logAnalytics.listKeys().primarySharedKey
7 changes: 4 additions & 3 deletions example/containerApps/shared/main.bicep
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { createContext } from '../../../src/common/context.bicep'
import { resourceGroup } from '../../../src/recommended/resource-group.bicep'
import { create_context } from '../../../src/common/context.bicep'
import { resource_group } from '../../../src/recommended/resource-group.bicep'

targetScope = 'subscription'

param deployedAt string

var context = createContext({
var context = create_context({
name: 'appName'
nameConventionTemplate: '$type-$env-$loc-$name'
environment: 'shared'
location: 'westeurope'
deployedAt: deployedAt
tenant: tenant()
tags: {}
})
3 changes: 3 additions & 0 deletions infrastructure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


# this is not part of the library, this is the bicep used to deploy the bicep
29 changes: 29 additions & 0 deletions infrastructure/main.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
targetScope = 'subscription'

param deployedAt string = utcNow('yyyyMMdd')

var locationAbbreviation = 'euw'
var location = 'west europe'
var environment = 'prd'
var projectName = 'tricep'

var context = {
locationAbbreviation: locationAbbreviation
location: location
environment: environment
projectName: projectName
deployedAt: deployedAt
}

resource calqueResourceGroup 'Microsoft.Resources/resourceGroups@2024-07-01' = {
name: 'rg-${locationAbbreviation}-${environment}-${projectName}'
location: location
}

module registry 'registry.bicep' = {
name: 'registry'
scope: calqueResourceGroup
params: {
context: context
}
}
1 change: 1 addition & 0 deletions infrastructure/params/main.prd.bicepparam
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
using '../main.bicep'
Loading

0 comments on commit 591ddf8

Please sign in to comment.