Skip to content

Commit 5e4ea49

Browse files
Merge pull request #18 from amido/feature/deployment
2 parents 7ef1f3c + 60c9d26 commit 5e4ea49

File tree

15 files changed

+418
-514
lines changed

15 files changed

+418
-514
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
java/target/
1212
java/build/
13+
java/.classpath
14+
java/.project
15+
java/.settings/
1316

1417
lombok.config
1518
.terraform

build/azDevops/azure/azure-pipelines-javaspring-k8s.yml

Lines changed: 195 additions & 154 deletions
Large diffs are not rendered by default.

build/azDevops/azure/templates/steps/build-java.yml

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ parameters:
55
project_root_dir: ""
66
dependsOn: "GetPackage"
77
download_devops: true
8+
# PR / Branch vars
9+
source_branch_ref: ""
10+
target_branch_ref: ""
11+
pullrequest_number: ""
812
# Custom registry (eg. private)
913
customRegistry: ""
1014
# Docker Config
@@ -20,6 +24,8 @@ parameters:
2024
# Static Code Analysis
2125
static_code_analysis: false
2226
sonar_container: ""
27+
sonar_pullrequest_provider: ""
28+
sonar_remote_repo: ""
2329
# Linting and formatting validation
2430
lint_formatting: ""
2531
shared_eslint_config: ""
@@ -41,10 +47,6 @@ parameters:
4147
git_release_tag: ""
4248

4349
steps:
44-
- bash: |
45-
echo '##vso[build.updatebuildnumber]${{ parameters.docker_imagetag }}'
46-
displayName: 'Update: Build Number'
47-
4850
- task: Cache@2
4951
inputs:
5052
key: 'maven | "$(Agent.OS)" | ${{ parameters.project_root_dir }}/pom.xml'
@@ -146,15 +148,58 @@ steps:
146148
147149
# SonarCloud
148150
- ${{ if eq(parameters.static_code_analysis, true) }}:
151+
- bash: |
152+
set -euxo pipefail
153+
function strip_refs()
154+
{
155+
local BRANCH_REF="$1"
156+
157+
RETURN_BRANCH="$(sed -e "s%^refs/\(heads\|tags\)/%%" <<< $BRANCH_REF)"
158+
}
159+
160+
strip_refs "${{ parameters.source_branch_ref }}"
161+
SOURCE_BRANCH=$RETURN_BRANCH
162+
163+
strip_refs "${{ parameters.target_branch_ref }}"
164+
TARGET_BRANCH=$RETURN_BRANCH
165+
166+
if [ -z "${{ parameters.pullrequest_number }}" ]; then
167+
EXTRA_SONAR_ARGUMENTS="-Dsonar.branch.name='$SOURCE_BRANCH'"
168+
EXTRA_SONAR_ARGUMENTS="${EXTRA_SONAR_ARGUMENTS} -Dsonar.branch.target='$TARGET_BRANCH'"
169+
else
170+
PROVIDER_LOWERCASED="$(tr '[:upper:]' '[:lower:]' <<< "${{ parameters.sonar_pullrequest_provider }}")"
171+
172+
EXTRA_SONAR_ARGUMENTS="-Dsonar.pullrequest.key='${{ parameters.pullrequest_number }}'"
173+
EXTRA_SONAR_ARGUMENTS="${EXTRA_SONAR_ARGUMENTS} -Dsonar.pullrequest.branch='$SOURCE_BRANCH'"
174+
EXTRA_SONAR_ARGUMENTS="${EXTRA_SONAR_ARGUMENTS} -Dsonar.pullrequest.provider='$PROVIDER_LOWERCASED'"
175+
EXTRA_SONAR_ARGUMENTS="${EXTRA_SONAR_ARGUMENTS} -Dsonar.pullrequest.base='$TARGET_BRANCH'"
176+
177+
if [ "$PROVIDER_LOWERCASED" == 'github' ]; then
178+
EXTRA_SONAR_ARGUMENTS="${EXTRA_SONAR_ARGUMENTS} -Dsonar.pullrequest.github.repository='${{ parameters.sonar_remote_repo }}'"
179+
fi
180+
fi
181+
182+
echo "##vso[task.setvariable variable=bash_extra_sonar_arguments]$EXTRA_SONAR_ARGUMENTS"
183+
displayName: "Sonar: Extra Sonar Arguments"
184+
149185
- template: azDevOps/azure/templates/v2/steps/test-static-code-sonar.yml@templates
150186
parameters:
151187
working_directory: "${{ parameters.project_root_dir }}"
152188
target_container: "${{ parameters.sonar_container }}"
189+
extra_arguments: "$(bash_extra_sonar_arguments)"
153190
env_vars: {
154-
SONAR_PULL_REQUEST: "$(System.PullRequest.PullRequestNumber)",
155-
SONAR_BRANCH_NAME: "$(System.PullRequest.SourceBranch)",
156-
SONAR_PR_PROVIDER: "GitHub",
157-
SONAR_GITHUB_REPO: "amido/stacks-java",
191+
SONAR_HOST_URL: "https://sonarcloud.io",
192+
SONAR_TOKEN: $SONAR_TOKEN,
193+
SONAR_PROJECT_KEY: $SONAR_PROJECT_KEY,
194+
SONAR_ORGANIZATION: $SONAR_ORGANIZATION,
195+
SONAR_PROJECT_NAME: $SONAR_PROJECT_NAME,
196+
BUILD_NUMBER: $(docker_image_tag),
197+
SONAR_SCANNER_OPTS: "",
198+
# PR Sonar Variables
199+
# SONAR_BRANCH_NAME: "${{ parameters.branch_ref }}",
200+
# SONAR_PULL_REQUEST: "${{ parameters.pull_request_number }}",
201+
# SONAR_PR_PROVIDER: "GitHub",
202+
# SONAR_GITHUB_REPO: "amido/stacks-java",
158203
}
159204

160205
- ${{ if eq(parameters.docker_build, true) }}:

deploy/azure/app/kube/backend.local.tfvars

Lines changed: 0 additions & 4 deletions
This file was deleted.

deploy/azure/app/kube/custom.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Example of further extensions to Stacks Core templates
2+
# Potential user defined extensions
3+
data "azurerm_application_insights" "example" {
4+
name = var.core_resource_group
5+
resource_group_name = var.app_insights_name
6+
}
7+
8+
output "app_insights_instrumentation_key" {
9+
description = "App Insights key for downstream deploymnent use"
10+
value = data.azurerm_application_insights.example.instrumentation_key
11+
sensitive = true
12+
}
13+
14+
variable app_insights_name {
15+
type = string
16+
default = ""
17+
description = "app insights name for key retriaval in memory"
18+
}

deploy/azure/app/kube/lookups.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# We are keeping this as a lookup
2-
# since proper conventions for naming of resources should be followed
2+
# since proper conventions for naming of resources should be followed
33
# and things can always be looked up without resorting to cross state searches
44
data "azurerm_public_ip" "app_gateway" {
55
name = var.app_gateway_frontend_ip_name
6-
resource_group_name = var.resource_group_name
6+
resource_group_name = var.core_resource_group
77
}

deploy/azure/app/kube/main.tf

Lines changed: 21 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,64 +5,36 @@
55

66
data "azurerm_client_config" "current" {}
77

8-
# Naming convention
8+
# Naming convention
99
module "default_label" {
1010
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=0.16.0"
1111
namespace = "${var.name_company}-${var.name_project}"
1212
stage = var.stage
13-
name = "${lookup(var.location_name_map, var.resource_group_location, "uksouth")}-${var.name_component}"
13+
name = "${lookup(var.location_name_map, var.resource_group_location, "uksouth")}-${var.name_domain}"
1414
attributes = var.attributes
1515
delimiter = "-"
1616
tags = var.tags
1717
}
1818

19-
locals {
20-
create_resource_group = var.use_existing_resource_group && var.resource_group_name != "" ? false : true
21-
resource_group_name = var.use_existing_resource_group && var.resource_group_name != "" ? var.resource_group_name : module.default_label.id
22-
}
23-
24-
resource "azurerm_resource_group" "default" {
25-
count = local.create_resource_group ? 1 : 0
26-
name = local.resource_group_name
27-
location = var.resource_group_location
28-
tags = var.tags
29-
}
30-
31-
####
32-
# app level DNS can/should be controlled from here
33-
# an alternative way of managing this would be through K8s operators
34-
# [TODO]: examples can be found in the deploy folders
35-
####
36-
resource "azurerm_dns_a_record" "default" {
37-
name = var.dns_record
38-
zone_name = var.dns_zone_name
39-
resource_group_name = local.resource_group_name
40-
ttl = 300
41-
records = [data.azurerm_public_ip.app_gateway.ip_address]
42-
}
43-
44-
module "cosmosdb" {
45-
source = "git::https://github.com/amido/stacks-terraform//azurerm/modules/azurerm-cosmosdb?ref=v1.1.0"
19+
module "app" {
20+
source = "git::https://github.com/amido/stacks-terraform//azurerm/modules/azurerm-server-side-app?ref=v1.3.1"
21+
create_cdn_endpoint = var.create_cdn_endpoint
4622
create_cosmosdb = var.create_cosmosdb
4723
resource_namer = module.default_label.id
48-
name_environment = "dev-feature"
49-
name_project = var.name_project
50-
name_company = var.name_company
51-
name_component = var.name_component
52-
resource_group_name = local.resource_group_name
53-
cosmosdb_sql_container = "Menu"
54-
cosmosdb_sql_container_partition_key = "/id"
55-
cosmosdb_kind = "GlobalDocumentDB"
56-
cosmosdb_offer_type = "Standard"
24+
resource_group_location = var.resource_group_location
25+
resource_tags = module.default_label.tags
26+
cosmosdb_sql_container = var.cosmosdb_sql_container
27+
cosmosdb_sql_container_partition_key = var.cosmosdb_sql_container_partition_key
28+
cosmosdb_kind = var.cosmosdb_kind
29+
cosmosdb_offer_type = var.cosmosdb_offer_type
30+
create_cache = var.create_cache
31+
create_dns_record = var.create_dns_record
32+
dns_record = var.dns_record
33+
dns_zone_name = var.dns_zone_name
34+
core_resource_group = var.core_resource_group
35+
dns_zone_resource_group = var.dns_zone_resource_group != "" ? var.dns_zone_resource_group : var.core_resource_group
36+
dns_a_records = [data.azurerm_public_ip.app_gateway.ip_address]
37+
subscription_id = data.azurerm_client_config.current.subscription_id
38+
# Alternatively if you want you can pass in the IP directly and remove the need for a lookup
39+
# dns_a_records = ["0.1.23.45"]
5740
}
58-
59-
####
60-
# Additional modules need to go here as they can be re-used across app deployments
61-
####
62-
# module "observability" {
63-
# source = "git://...."
64-
# }
65-
66-
####
67-
# Additional user defined resources or modules can go here
68-
####

deploy/azure/app/kube/outputs.tf

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
11
output "cosmosdb_database_name" {
22
description = "CosmosDB Database name"
3-
value = module.cosmosdb.cosmosdb_database_name
3+
value = module.app.cosmosdb_database_name
44
}
55

66
output "cosmosdb_account_name" {
77
description = "CosmosDB account name"
8-
value = module.cosmosdb.cosmosdb_account_name
8+
value = module.app.cosmosdb_account_name
99
}
1010

1111
output "cosmosdb_endpoint" {
1212
description = "Endpoint for accessing the DB CRUD"
13-
value = module.cosmosdb.cosmosdb_endpoint
13+
value = module.app.cosmosdb_endpoint
1414
}
1515

1616
output "cosmosdb_primary_master_key" {
1717
description = "Primary Key for accessing the DB CRUD, should only be used in applications running outside of AzureCloud"
1818
sensitive = true
19-
value = module.cosmosdb.cosmosdb_primary_master_key
19+
value = module.app.cosmosdb_primary_master_key
20+
}
21+
22+
output "redis_cache_key" {
23+
description = "Primary Key for accessing the RedisCache, should only be used in applications running outside of AzureCloud"
24+
sensitive = true
25+
value = module.app.redis_cache_key
26+
}
27+
28+
output "redis_cache_hostname" {
29+
description = "Primary Hostname endpoint for Redis Cache"
30+
value = module.app.redis_cache_hostname
31+
}
32+
33+
output "resource_group" {
34+
description = "Resource group name for the app"
35+
value = module.app.resource_group
36+
}
37+
38+
output "dns_name" {
39+
description = "DNS Name if created"
40+
value = module.app.dns_name
2041
}

deploy/azure/app/kube/vars.tf

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ variable "name_component" {
2222
default = "replace_component_name"
2323
}
2424

25+
variable "name_domain" {
26+
type = string
27+
default = "replace_domain_name"
28+
}
29+
2530
variable "stage" {
2631
type = string
2732
default = "dev"
@@ -36,7 +41,7 @@ variable "tags" {
3641
default = {}
3742
}
3843

39-
# Each region must have corresponding a shortend name for resource naming purposes
44+
# Each region must have corresponding a shortend name for resource naming purposes
4045
variable "location_name_map" {
4146
type = map(string)
4247

@@ -62,44 +67,83 @@ variable "resource_group_location" {
6267
default = "uksouth"
6368
}
6469

65-
variable "resource_group_name" {
66-
description = "RG name of where you want to be deploying app level resources, can be left blank and "
67-
type = string
68-
}
69-
7070
variable "app_gateway_frontend_ip_name" {
7171
description = ""
72-
type = string
72+
type = string
7373
}
7474

7575
variable "dns_record" {
7676
description = ""
77-
type = string
78-
default = "app"
77+
type = string
78+
default = "app"
7979
}
8080

81-
8281
variable "dns_zone_name" {
8382
type = string
8483
default = "nonprod.amidostacks.com"
8584
}
8685

86+
variable "dns_zone_resource_group" {
87+
type = string
88+
default = ""
89+
}
90+
91+
variable "core_resource_group" {
92+
type = string
93+
}
94+
8795
variable "internal_dns_zone_name" {
8896
type = string
8997
default = "nonprod.amidostacks.internal"
9098
}
9199

100+
92101
###########################
93102
# CONDITIONAL SETTINGS
94103
##########################
95104
variable "create_cosmosdb" {
96105
description = "Whether to create a cosmosdb or not for this application"
106+
type = bool
107+
default = true
108+
}
109+
110+
variable "create_cache" {
111+
type = bool
112+
description = "Whether to create a RedisCache"
113+
default = false
114+
}
115+
116+
variable "create_dns_record" {
97117
type = bool
98-
default = true
118+
default = false
99119
}
100120

101-
variable "use_existing_resource_group" {
102-
description = "Whether to create a resource group for application level resources, if set to true and `resource_group_name` is not specified it will create a resource group for you. Ensure you specify resource group when setting to true"
121+
variable create_cdn_endpoint {
103122
type = bool
104-
default = true
123+
default = false
124+
}
125+
###########################
126+
# CosmosDB SETTINGS
127+
##########################
128+
variable "cosmosdb_sql_container" {
129+
type = string
130+
description = "Specify the SQLContainer name in CosmosDB"
131+
default = "Menu"
132+
}
133+
134+
variable "cosmosdb_sql_container_partition_key" {
135+
type = string
136+
default = "/id"
137+
description = "Specify partition key"
138+
}
139+
140+
variable "cosmosdb_kind" {
141+
type = string
142+
default = "GlobalDocumentDB"
143+
description = "Specify the CosmosDB kind"
144+
}
145+
variable "cosmosdb_offer_type" {
146+
type = string
147+
default = "Standard"
148+
description = "Specify the offer type"
105149
}

0 commit comments

Comments
 (0)