Skip to content

Commit f34351b

Browse files
committed
Merge branch 'develop'
2 parents f518ab6 + 2473ec6 commit f34351b

File tree

85 files changed

+4917
-1726
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+4917
-1726
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,15 @@ Change logs
4444
DB schema update:
4545
``` ALTER TABLE alerts.query_result MODIFY logs TEXT NULL; ```
4646

47-
### 4.2.0 Release
47+
### 4.3.0 Release
4848
No DB changes
49+
50+
51+
### 4.4.0 Release
52+
Apply new templates for alerts
53+
54+
#### Change logs
55+
Database update: Check release/4.4.0-release.sql
56+
57+
58+

build.gradle

+8-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* rights and limitations under the License.
1212
*/
1313
buildscript {
14-
version "4.2.4"
14+
version "4.4.0-SNAPSHOT"
1515
group "au.org.ala"
1616
}
1717

@@ -54,8 +54,8 @@ bootWar {
5454
repositories {
5555
repositories {
5656
mavenLocal()
57-
maven { url "https://nexus.ala.org.au/content/groups/public/" }
5857
mavenCentral()
58+
maven { url "https://nexus.ala.org.au/content/groups/public/" }
5959
maven { url "https://repo.grails.org/grails/core/" }
6060
}
6161
mavenCentral()
@@ -127,6 +127,8 @@ dependencies {
127127
implementation "org.grails.plugins:ala-ws-plugin:$alaSecurityLibsVersion"
128128
implementation "au.org.ala:userdetails-service-client:$alaSecurityLibsVersion"
129129
implementation "org.grails.plugins:ala-admin-plugin:2.3.0"
130+
implementation "au.org.ala.plugins:openapi:1.3.0"
131+
implementation "org.grails.plugins:aws-sdk-s3:2.4.8"
130132

131133
// for ContentType
132134
implementation "org.apache.httpcomponents:httpcore:4.4.16"
@@ -136,7 +138,7 @@ dependencies {
136138
//Using AWS SES as email provider
137139
implementation 'org.grails.plugins:mail:4.0.0'
138140
implementation 'au.org.ala:ala-mail:1.0.0-SNAPSHOT'
139-
implementation group: 'com.amazonaws', name: 'aws-java-sdk-sts', version: "1.12.759"
141+
implementation 'com.amazonaws:aws-java-sdk-sts:1.12.759'
140142

141143
implementation 'org.grails.plugins:schwartz-monitor:2.0.1.ALA-SNAPSHOT'
142144
implementation 'org.grails.plugins:quartz:2.0.13'
@@ -154,13 +156,14 @@ dependencies {
154156
testRuntimeOnly("org.seleniumhq.selenium:selenium-firefox-driver:4.10.0")
155157
testRuntimeOnly("org.seleniumhq.selenium:selenium-safari-driver:4.10.0")
156158
runtimeOnly 'commons-lang:commons-lang:2.6'
157-
implementation 'commons-io:commons-io:2.11.0'
159+
implementation 'commons-codec:commons-codec:1.17.1'
160+
implementation 'commons-io:commons-io:2.17.0'
161+
implementation 'org.apache.commons:commons-csv:1.12.0'
158162
runtimeOnly 'org.hamcrest:hamcrest-core:2.2'
159163
runtimeOnly 'org.hamcrest:hamcrest-library:2.2'
160164
runtimeOnly 'xalan:xalan:2.7.3'
161165
implementation 'com.jayway.jsonpath:json-path:2.7.0'
162166
implementation 'com.jayway.jsonpath:json-path-assert:2.7.0'
163-
implementation 'au.org.ala.plugins:openapi:1.3.0'
164167
}
165168
//
166169
//bootRun {

cicd/deploy/config.ini cicd/backend/config.ini

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
[DEFAULT]
2-
PRODUCT_COMPONENT = deploy
2+
PRODUCT_COMPONENT = backend
33
PIPELINE_STACK_NAME = ala-${PRODUCT_NAME}-${PRODUCT_COMPONENT}-pipeline-${ENVIRONMENT}
4-
BASE_STACK_NAME = ala-${PRODUCT_NAME}-base-${ENVIRONMENT}
54
DATABASE_STACK_NAME = ala-${PRODUCT_NAME}-database-${ENVIRONMENT}
6-
AUTO_DEPLOY = false
5+
HELM_RELEASE_NAME = ala-alerts-${CLEAN_BRANCH}
6+
DOMAIN_NAME = ${PRODUCT_NAME}.${HOSTED_ZONE}
7+
AUTO_DEPLOY = true
78
SLACK_DEPLOY_NOTIFICATION = false
89
SLACK_ALERT_CHANNEL = deployments
910

1011
[development]
1112
# code pipeline
1213
PIPELINE_STACK_NAME = ala-${PRODUCT_NAME}-${PRODUCT_COMPONENT}-pipeline-${CLEAN_BRANCH}
13-
BASE_STACK_NAME = ala-${PRODUCT_NAME}-base-${CLEAN_BRANCH}
14-
DATABASE_STACK_NAME = ala-${PRODUCT_NAME}-database-${CLEAN_BRANCH}
14+
; Update the database stack name if creating a new database stack for feature branch
15+
DATABASE_STACK_NAME = ala-${PRODUCT_NAME}-database-develop
1516
SLACK_DEPLOY_NOTIFICATION = true
1617
SLACK_ALERT_CHANNEL = zabbix-alerts
17-
AUTO_DEPLOY = false
18+
DOMAIN_NAME = ${PRODUCT_NAME}-${CLEAN_BRANCH}.${HOSTED_ZONE}
1819

1920
[testing]
21+
SLACK_DEPLOY_NOTIFICATION = true
22+
SLACK_ALERT_CHANNEL = zabbix-alerts
2023

2124
[staging]
2225

cicd/build/pipeline/build_alerts_buildspec.yaml cicd/backend/pipeline/build_alerts_buildspec.yaml

+13-14
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,51 @@ env:
44
shell: bash
55
variables:
66
JAVA_TOOL_OPTIONS: -Dhttps.protocols=TLSv1.2
7+
exported-variables:
8+
- BUILD_TAG
79

810
phases:
911
install:
12+
runtime-versions:
13+
java: corretto11
1014
commands:
1115
- echo Installing dependencies...
1216
- apt update -y
1317
&& cat /etc/lsb-release
14-
&& apt-get -q -y install openjdk-11-jdk
15-
&& apt-get -q -y install unzip
16-
&& apt-get -q -y install zip
17-
&& apt-get -q -y install curl
1818
&& curl -s "https://get.sdkman.io" | bash
1919
&& chmod a+x /root/.sdkman/bin/sdkman-init.sh
2020
&& source /root/.sdkman/bin/sdkman-init.sh && sdk install grails 6.0.0 /root/.sdkman/candidates/grails/6.0.0
21-
&& apt-get install -y apt-transport-https ca-certificates curl software-properties-common
21+
&& apt-get install -y apt-transport-https ca-certificates software-properties-common
2222
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
2323
&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
2424
&& apt-get update
2525
&& apt-get install -y docker-ce
26+
- java -version
2627
- ./gradlew clean
2728
- ./gradlew assemble
2829

2930
build:
3031
commands:
3132
- echo Build started on $(date)
3233
- echo Building the project...
33-
- ./gradlew build
34+
- ./gradlew build --stacktrace
3435
- ./gradlew bootWar
3536

3637
post_build:
3738
commands:
3839
- echo Post-build phase...
3940
- echo Build completed on $(date)
40-
# - aws s3 rm s3://ala-alerts-builds/devbuilds/$CLEAN_BRANCH/ --recursive
41-
# - aws s3 cp build/libs/*.war s3://ala-alerts-builds/devbuilds/$CLEAN_BRANCH/
4241
- echo Logging in to Amazon ECR...
4342
- aws ecr get-login-password | docker login -u AWS --password-stdin "https://$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com"
4443
- rm -rf build/libs/*-plain.war
4544
- echo Building the Docker image...
4645
- docker build -t ala-alerts .
4746
- echo Tagging the Docker image...
48-
- export REPO=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ALERTS_ECR_REPOSITORY_NAME
49-
- echo REPO=$REPO
47+
- BUILD_TAG=$CLEAN_BRANCH-$CODEBUILD_BUILD_NUMBER
48+
- echo build tag is $BUILD_TAG
5049
- echo tagging
51-
- docker tag ala-alerts:latest $REPO:$CLEAN_BRANCH-$CODEBUILD_BUILD_NUMBER
52-
- docker tag ala-alerts:latest $REPO:latest
50+
- docker tag ala-alerts:latest $ECR_REPO:$BUILD_TAG
51+
- docker tag ala-alerts:latest $ECR_REPO:latest
5352
- echo Pushing the Docker image to Amazon ECR...
54-
- docker push $REPO:$CLEAN_BRANCH-$CODEBUILD_BUILD_NUMBER
55-
- docker push $REPO:latest
53+
- docker push $ECR_REPO:$BUILD_TAG
54+
- docker push $ECR_REPO:latest
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
version: 0.2
2+
3+
env:
4+
shell: bash
5+
variables:
6+
JAVA_TOOL_OPTIONS: -Dhttps.protocols=TLSv1.2
7+
secrets-manager:
8+
DB_PASSWORD: $ALERTS_SECRET_NAME:db-password
9+
10+
phases:
11+
install:
12+
commands:
13+
- echo Installing dependencies...
14+
- cat /etc/lsb-release
15+
- apt update -y
16+
&& apt-get -q -y install openjdk-11-jdk
17+
&& pip3 install jinja2
18+
&& curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
19+
&& chmod 700 get_helm.sh
20+
&& ./get_helm.sh
21+
22+
build:
23+
commands:
24+
- echo Build started on $(date)
25+
- wget https://raw.githubusercontent.com/AtlasOfLivingAustralia/ala-install/refs/heads/master/ansible/roles/alerts/templates/alerts-config.properties
26+
- aws eks --region ap-southeast-2 update-kubeconfig --name $EKS_CLUSTER_NAME
27+
- |
28+
USER_POOL_ID=$(aws cloudformation describe-stacks --stack-name $COGNITO_STACK_NAME \
29+
--query "Stacks[0].Outputs[?OutputKey=='UserPoolId'].OutputValue" --output text)
30+
- |
31+
CLIENT_ID=$(aws cloudformation describe-stacks --stack-name $BASE_STACK_NAME \
32+
--query "Stacks[0].Outputs[?OutputKey=='AlertsAppClient'].OutputValue" --output text)
33+
- |
34+
CLIENT_SECRET=$(aws cognito-idp describe-user-pool-client --user-pool-id $USER_POOL_ID \
35+
--client-id $CLIENT_ID --query "UserPoolClient.ClientSecret" --output text)
36+
- |
37+
SERVER_TO_SERVER_CLIENT_ID=$(aws cloudformation describe-stacks --stack-name $BASE_STACK_NAME \
38+
--query "Stacks[0].Outputs[?OutputKey=='AlertsServerToServerAppClient'].OutputValue" --output text)
39+
- |
40+
SERVER_TO_SERVER_CLIENT_SECRET=$(aws cognito-idp describe-user-pool-client --user-pool-id $USER_POOL_ID \
41+
--client-id $SERVER_TO_SERVER_CLIENT_ID --query "UserPoolClient.ClientSecret" --output text)
42+
- kubectl config set-context --current --namespace=alerts
43+
- |
44+
python3 cicd/gen_app_config.py -t alerts-config.properties \
45+
-v $CODEBUILD_SRC_DIR_AnsibleInventoriesSourceArtifact/alerts/alerts-feature-branch \
46+
-b $CLEAN_BRANCH \
47+
-o alerts-config.properties
48+
- sed -i "s/dataSource.password=/dataSource.password=$DB_PASSWORD/" alerts-config.properties
49+
- sed -i "s/security.oidc.clientId=/security.oidc.clientId=$CLIENT_ID/" alerts-config.properties
50+
- sed -i "s/security.oidc.secret=/security.oidc.secret=$CLIENT_SECRET/" alerts-config.properties
51+
- sed -i "s/webservice.client-id=/webservice.client-id=$SERVER_TO_SERVER_CLIENT_ID/" alerts-config.properties
52+
- sed -i "s/webservice.client-secret=/webservice.client-secret=$SERVER_TO_SERVER_CLIENT_SECRET/" alerts-config.properties
53+
- sed -i "s/mysql-rds\/alerts/mysql-rds-$CLEAN_BRANCH\/alertsdevelopment/" alerts-config.properties
54+
- sed -i "s/ala-alerts-test/alerts-$CLEAN_BRANCH/" alerts-config.properties
55+
- sed -i '1i server.port=8000' alerts-config.properties
56+
- kubectl delete secret alerts-config-secret-$CLEAN_BRANCH || true
57+
- kubectl create secret generic alerts-config-secret-$CLEAN_BRANCH --from-file=alerts-config.properties
58+
- |
59+
ALERTS_ROLE_ARN=$(aws cloudformation describe-stacks --stack-name $BASE_STACK_NAME \
60+
--query "Stacks[0].Outputs[?OutputKey=='AlertsRoleArn'].OutputValue" --output text)
61+
- printf "$(kubectl config current-context)\n"
62+
- |
63+
eksctl create iamserviceaccount --name alerts-service-account-$CLEAN_BRANCH \
64+
--namespace alerts --cluster $EKS_CLUSTER_NAME --attach-role-arn $ALERTS_ROLE_ARN \
65+
--approve --override-existing-serviceaccounts \
66+
--tags "product=alerts,environment=development,branch=${CLEAN_BRANCH}"
67+
- cd helm
68+
- |
69+
export CERTIFICATE_ARN=$(aws acm list-certificates --region ap-southeast-2 \
70+
--query "CertificateSummaryList[?DomainName=='*.$HOSTED_ZONE' && Status=='ISSUED'].CertificateArn" --output text)
71+
- BUILD_TAG=$CLEAN_BRANCH-$CODEBUILD_BUILD_NUMBER
72+
- env
73+
- |
74+
helm upgrade --install $HELM_RELEASE_NAME . -n alerts \
75+
--set image.repository=$ECR_REPO \
76+
--set image.tag=$BUILD_TAG \
77+
--set ingress.hostname=$DOMAIN_NAME \
78+
--set rds.externalName=$DB_WRITE_ENDPOINT \
79+
--set ingress.certificateArn=$CERTIFICATE_ARN \
80+
--set secret.name=alerts-config-secret-$CLEAN_BRANCH \
81+
--set serviceAccount.name=alerts-service-account-$CLEAN_BRANCH \
82+
--set rds.name=mysql-rds-$CLEAN_BRANCH
83+
- kubectl rollout restart deployment $HELM_RELEASE_NAME
84+
post_build:
85+
commands:
86+
- echo Post-build phase...
87+
- echo Build completed on $(date)
88+
89+
artifacts:
90+
base-directory: $CODEBUILD_SRC_DIR
91+
files:
92+
- '**/*'
93+
secondary-artifacts:
94+
AnsibleInventoriesSourceArtifact:
95+
base-directory: $CODEBUILD_SRC_DIR_AnsibleInventoriesSourceArtifact
96+
files:
97+
- '**/*'

cicd/deploy/pipeline/deploy_pipeline.sh cicd/backend/pipeline/deploy_pipeline.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,16 @@ aws cloudformation deploy \
139139
--parameter-overrides \
140140
pAutoDeploy=$AUTO_DEPLOY \
141141
pBootstrapStackName=$BOOTSTRAP_STACK_NAME \
142+
pBaseStackName=$BASE_STACK_NAME \
142143
pBucketsStackName=$BUCKETS_STACK_NAME \
143144
pCleanBranch=$clean_branch \
144-
pEksClusterName=$EKS_CLUSTER_NAME \
145145
pEnvironment=$environment \
146146
pGitHubBranch=$branch \
147147
pGitHubOwner=$GITHUB_OWNER \
148148
pGitHubRepositoryName=$GITHUB_REPO_NAME \
149149
pPipelineFingerprint=$PIPELINE_MD5 \
150150
pProductComponent=$PRODUCT_COMPONENT \
151151
pProductName=$PRODUCT_NAME \
152+
pDomainName=$DOMAIN_NAME \
152153
pRestartExecutionOnUpdate=$RESTART_PIPELINE_ON_UPDATE \
153154

cicd/deploy/pipeline/export_config_buildspec.yaml cicd/backend/pipeline/export_config_buildspec.yaml

+22-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ env:
1010
DEBIAN_FRONTEND: "noninteractive"
1111
exported-variables:
1212
- CODEBUILD_BUILD_NUMBER
13-
- BASE_STACK_FILE_PFIX
1413
- PRODUCT_NAME
1514
- PRODUCT_COMPONENT
1615
- SLACK_DEPLOY_NOTIFICATION
1716
- SLACK_ALERT_CHANNEL
1817
- ALERTS_SECRET_NAME
19-
- ALERTS_ECR_REPOSITORY_NAME
18+
- BASE_STACK_FILE_PFIX
19+
- BASE_STACK_NAME
20+
- CODEBUILD_BUILD_NUMBER
21+
- COGNITO_STACK_NAME
2022
- DB_READ_ENDPOINT
2123
- DB_WRITE_ENDPOINT
24+
- DOMAIN_NAME
25+
- EKS_CLUSTER_NAME
26+
- HELM_RELEASE_NAME
27+
- HOSTED_ZONE
2228

2329
phases:
2430

@@ -59,25 +65,36 @@ phases:
5965
- cicd/gen_env_vars.py --env $ENVIRONMENT --clean-branch $CLEAN_BRANCH --conf cicd/$PRODUCT_COMPONENT/config.ini > env.txt
6066
- echo loading config..
6167
- set -a ; source env.txt ; set +a
68+
# import stack export from the base cloudformation stack
69+
- echo importing stack output...
70+
- ALERTS_SECRETS=$(aws cloudformation describe-stacks --stack-name $BASE_STACK_NAME --query "Stacks[0].Outputs[?OutputKey=='AlertsSecrets'].OutputValue" --output text)
71+
- echo ALERTS_SECRETS=$ALERTS_SECRETS
6272
- ALERTS_SECRET_NAME_ARN=$(aws cloudformation describe-stacks --stack-name $BASE_STACK_NAME --query "Stacks[0].Outputs[?OutputKey=='AlertsSecret'].OutputValue" --output text)
6373
- ALERTS_SECRET_NAME=$(echo $ALERTS_SECRET_NAME_ARN | cut -d':' -f7 | rev | cut -d'-' -f2- | rev)
64-
- ALERTS_ECR_REPOSITORY_NAME=$(aws cloudformation describe-stacks --stack-name $BASE_STACK_NAME --query "Stacks[0].Outputs[?OutputKey=='AlertsRepositoryName'].OutputValue" --output text)
74+
- echo ALERTS_SECRET_NAME=$ALERTS_SECRET_NAME
75+
- |
76+
if [[ "$ENVIRONMENT" == "development" ]]; then
77+
ALERTS_SECRET_NAME="alerts-develop"
78+
fi
79+
- echo ALERTS_SECRET_NAME=$ALERTS_SECRET_NAME
6580
- DB_READ_ENDPOINT=$(aws cloudformation describe-stacks --stack-name $DATABASE_STACK_NAME --query "Stacks[0].Outputs[?OutputKey=='ReadEndpoint'].OutputValue" --output text)
6681
- DB_WRITE_ENDPOINT=$(aws cloudformation describe-stacks --stack-name $DATABASE_STACK_NAME --query "Stacks[0].Outputs[?OutputKey=='WriteEndpoint'].OutputValue" --output text)
6782
- echo ALERTS_SECRET_NAME=$ALERTS_SECRET_NAME
68-
- echo ALERTS_ECR_REPOSITORY_NAME=$ALERTS_ECR_REPOSITORY_NAME
6983
- echo DB_READ_ENDPOINT=$DB_READ_ENDPOINT
7084
- echo DB_WRITE_ENDPOINT=$DB_WRITE_ENDPOINT
85+
- export EKS_CLUSTER_NAME=$(aws cloudformation list-exports --query "Exports[?Name=='$REGOLITH_STACK_NAME-ClusterName'].Value" --output text)
86+
- echo EKS_CLUSTER_NAME=$EKS_CLUSTER_NAME
7187
finally:
7288
- #echo This always runs
7389

7490
build:
7591
commands:
7692
- echo Entered the build phase...
93+
# package templates and generate the template configs
7794
finally:
7895
- #echo This always runs
7996

8097

8198
post_build:
8299
commands:
83-
- #echo Entered the post_build phase...
100+
- #echo Entered the post_build phase...

0 commit comments

Comments
 (0)