Skip to content

Commit

Permalink
Cndit 1600 deployment (#7)
Browse files Browse the repository at this point in the history
* Created github workflow files and updated build script for the test reports.

* Update Build-and-deploy-nnd-service.yaml

* Update Build-and-deploy-nnd-service.yaml

* Update Dockerfile

* updated gitignore

* testing nnd-data-poll-service

* testing jar upload

* Update Build-and-deploy-nnd-service.yaml

* Update Build-and-deploy-nnd-service.yaml

* To upload one jar

* Update Build-and-deploy-nnd-service.yaml

* Added nnd-message-processor jar

* Removed --no-daemon

* Added back --no-daemon

* Uncommented nnd-data-exchange-service code

* Update sonar.yaml

* updated for sonarcloud
  • Loading branch information
ssathiah authored Aug 7, 2024
1 parent a981b49 commit 410c793
Show file tree
Hide file tree
Showing 14 changed files with 320 additions and 18 deletions.
Binary file modified .DS_Store
Binary file not shown.
73 changes: 73 additions & 0 deletions .github/workflows/Build-and-deploy-nnd-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Build and push data-ingestion-service and data-processing-service images to ECR
on:
push:
branches:
- main
- master
- rel-**
- CNDIT-1600-*
paths-ignore:
- "docker-compose.yml"
- "**.md"
jobs:
# sonar_scan:
# uses: ./.github/workflows/sonar.yaml
# secrets:
# CDC_NBS_SANDBOX_SHARED_SERVICES_ACCOUNTID: ${{secrets.CDC_NBS_SANDBOX_SHARED_SERVICES_ACCOUNTID}}
# PASSED_GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
# SONAR_TOKEN: ${{secrets.SONAR_TOKEN}}
call-build-microservice-container-workflow:
name: Build Container
# needs: sonar_scan
uses: CDCgov/NEDSS-Workflows/.github/workflows/Build-gradle-microservice-container.yaml@main
with:
microservice_name: nnd-data-exchange-service
dockerfile_relative_path: -f ./nnd-data-exchange-service/Dockerfile .
environment_classifier: SNAPSHOT
java_version: "17"
secrets:
CDC_NBS_SANDBOX_SHARED_SERVICES_ACCOUNTID: ${{secrets.CDC_NBS_SANDBOX_SHARED_SERVICES_ACCOUNTID}}
ECR_REPO_BASE_NAME: ${{secrets.ECR_REPO_BASE_NAME}}
GIT_USER_EMAIL: ${{secrets.GIT_USER_EMAIL}}
GIT_USER_NAME: ${{secrets.GIT_USER_NAME}}
HELM_TOKEN: ${{secrets.HELM_TOKEN}}

call-update-helm-data-ingestion:
name: Request DEV deployment
needs: call-build-microservice-container-workflow
uses: CDCgov/NEDSS-Workflows/.github/workflows/Update-helm-charts.yaml@main
with:
microservice_name: nnd-data-exchange-service
values_file_with_path: charts/nnd-service/values-dts1.yaml
new_image_tag: ${{ needs.call-build-microservice-container-workflow.outputs.output_image_tag }}
secrets:
GIT_USER_EMAIL: ${{secrets.GIT_USER_EMAIL}}
GIT_USER_NAME: ${{secrets.GIT_USER_NAME}}
HELM_TOKEN: ${{secrets.HELM_TOKEN}}

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'gradle'
- name: create-nnd-data-poll-jar
working-directory: ./nnd-data-poll-service
run: ./gradlew build --no-daemon
- name: upload-nnd-data-poll-jar
uses: actions/upload-artifact@v4
with:
name: NND-data-poll-service-jar
path: nnd-data-poll-service/build/libs/nnd-data-poll-service.jar

- name: create-nnd-message-processor-jar
working-directory: ./nnd-message-processor
run: ./gradlew build --no-daemon
- name: upload-nnd-message-processor-jar
uses: actions/upload-artifact@v4
with:
name: NND-message-processor-jar
path: nnd-message-processor/build/libs/nnd-message-processor.jar
65 changes: 65 additions & 0 deletions .github/workflows/Release-container-nnd-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Release nnd-data-exchange-service image
on:
workflow_dispatch:
inputs:
microservice_name:
description: "Microservice name matching your repository (ex. nnd-data-exchange-service)."
required: true
type: string
default: <microservicename>
dockerfile_relative_path:
description: "Relative path of your dockerfile, may include -f flag (ex. ./apps/<microservice>/Dockerfile)."
required: true
type: string
default: -f ./nnd-data-exchange-service/Dockerfile .
existing-image-tag:
description: "Image tag of existing container in ECR (not used if build-new-container=true)."
required: false
type: string
environment_classifier:
description: Metadata to append to application version (A setting of NONE, indicates all metadata to be stripped). Ex. if version=1.0.0, and environment_classifier=SNAPSHOT result will be 1.0.0-SNAPSHOT.<githubsha>. If version=1.0.0, and environment_classifier=NONE result will be 1.0.0.
required: true
type: string
default: SNAPSHOT
values_file_with_path:
description: What is the path to the helm chart in NBS helm chart repository? (ex. charts/nnd-service/values-int1.yaml)
type: string
default: "charts/<microservice>/<values_filename.yaml>"
build-new-container:
description: "Check the box to create a new container tagged based on the environment_classifier."
required: true
default: false
type: boolean
update_helm_chart:
description: "Do you want to update the specified helm chart"
required: true
default: true
type: boolean

jobs:
call-build-microservice-container-workflow:
uses: CDCgov/NEDSS-Workflows/.github/workflows/Release-gradle-microservice-container.yaml@main
with:
microservice_name: ${{inputs.microservice_name}}
existing-image-tag: ${{inputs.existing-image-tag}}
build-new-container: ${{inputs.build-new-container}}
dockerfile_relative_path: ${{inputs.dockerfile_relative_path}}
environment_classifier: ${{inputs.environment_classifier}}
secrets:
CDC_NBS_SANDBOX_SHARED_SERVICES_ACCOUNTID: ${{secrets.CDC_NBS_SANDBOX_SHARED_SERVICES_ACCOUNTID}}
ECR_REPO_BASE_NAME: ${{secrets.ECR_REPO_BASE_NAME}}
GIT_USER_EMAIL: ${{secrets.GIT_USER_EMAIL}}
GIT_USER_NAME: ${{secrets.GIT_USER_NAME}}
HELM_TOKEN: ${{secrets.HELM_TOKEN}}

call-update-helm:
needs: call-build-microservice-container-workflow
uses: CDCgov/NEDSS-Workflows/.github/workflows/Update-helm-charts.yaml@main
with:
microservice_name: ${{inputs.microservice_name}}
values_file_with_path: ${{inputs.values_file_with_path}}
new_image_tag: ${{ needs.call-build-microservice-container-workflow.outputs.output_image_tag }}
secrets:
GIT_USER_EMAIL: ${{secrets.GIT_USER_EMAIL}}
GIT_USER_NAME: ${{secrets.GIT_USER_NAME}}
HELM_TOKEN: ${{secrets.HELM_TOKEN}}
69 changes: 69 additions & 0 deletions .github/workflows/sonar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: SonarCloud
on:
workflow_call:
secrets:
CDC_NBS_SANDBOX_SHARED_SERVICES_ACCOUNTID:
description: "Secret named CDC_NBS_SANDBOX_SHARED_SERVICES_ACCOUNTID where ECR resides."
required: true
PASSED_GITHUB_TOKEN:
description: "Secret named GITHUB_TOKEN that references the github token for this repository."
required: true
SONAR_TOKEN:
description: "Secret named SONAR_TOKEN that references the sonar token secret corresponding to the project in sonarcloud."
required: true
pull_request:
paths:
- "nnd-data-exchange-service/**"
- "nnd-data-poll-service/**"
- "nnd-message-processor/**"
- ".github/workflows/sonar.yaml"
env:
deployment_env: dev
accountid: ${{secrets.cdc_nbs_sandbox_shared_services_accountid}}

jobs:
pipeline:
name: Build and analyze
runs-on: ubuntu-latest

permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available

- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle

- name: Build and analyze
working-directory: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
./gradlew build jacocoTestReport sonar "-Dorg.gradle.jvmargs=-Xms512m -Xmx4g -XX:MaxMetaspaceSize=1g"
- name: Publish Testing Reports
uses: actions/upload-artifact@v4
with:
name: testing
path: ./**/build/reports
35 changes: 31 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
*.gradle
!build.gradle
*/build
*.idea
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.tar.gz
*.rar


.DS_Store
.gradle/

### .idea ###
.idea/
.idea/.name
.idea/*.xml
.idea/modules/*
.idea/libraries/*

52 changes: 52 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("com.dipien:semantic-version-gradle-plugin:2.0.0")
}
}

plugins {
id 'org.sonarqube' version '4.2.1.3168'
}

version = '1.0.1-SNAPSHOT'
apply plugin: "com.dipien.semantic-version"

subprojects {

repositories {
mavenCentral()
maven {
url "https://packages.confluent.io/maven"
}
}

apply plugin: 'java'
apply plugin: 'jacoco'

jacocoTestReport {
dependsOn test
reports {
xml.required = true
}
}

tasks.named('test') {
finalizedBy tasks.named('jacocoTestReport', JacocoReport)
}
}

sonarqube {
properties {
property "sonar.sourceEncoding", "UTF-8"
property "sonar.projectKey", "CDCgov_NEDSS-NNDSS"
property "sonar.organization", "cdcgov"
property "sonar.host.url", "https://sonarcloud.io"
}
}
Binary file added nnd-data-exchange-service/.DS_Store
Binary file not shown.
12 changes: 6 additions & 6 deletions nnd-data-exchange-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ FROM amazoncorretto:17 as builder


#Copy project config
COPY gradle /usr/src/nnd/gradle
COPY gradlew /usr/src/nnd/gradlew
COPY build.gradle /usr/src/nnd/build.gradle
COPY settings.gradle /usr/src/nnd/settings.gradle
COPY gradle /usr/src/nnddataexchange/gradle
COPY gradlew /usr/src/nnddataexchange/gradlew
COPY build.gradle /usr/src/nnddataexchange/build.gradle
COPY settings.gradle /usr/src/nnddataexchange/settings.gradle

#Copy sources
COPY nnd-data-exchange-service /usr/src/nnd/nnd-data-exchange-service
COPY nnd-data-exchange-service /usr/src/nnddataexchange/nnd-data-exchange-service

COPY . /usr/src/nnd

WORKDIR /usr/src/nnd

#Build report service along with any required libraries
RUN ./gradlew :nnd-data-exchange-service :buildNeeded -x test --no-daemon
RUN ./gradlew :nnd-data-exchange-service:buildNeeded -x test --no-daemon

FROM amazoncorretto:17

Expand Down
23 changes: 15 additions & 8 deletions nnd-data-exchange-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.3.2'
id 'io.spring.dependency-management' version '1.1.6'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'jacoco'
id "org.sonarqube" version "4.2.1.3168"
}

group = 'gov.cdc'
Expand All @@ -23,6 +26,11 @@ repositories {
mavenCentral()
}

test {
useJUnitPlatform()
finalizedBy jacocoTestReport
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
Expand All @@ -45,12 +53,11 @@ dependencies {
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

test {
useJUnitPlatform()
}


test {
useJUnitPlatform()
sonarqube {
properties {
property "sonar.sourceEncoding", "UTF-8"
property "sonar.projectKey", "CDCgov_NEDSS-NNDSS"
property "sonar.organization", "cdcgov"
property "sonar.host.url", "https://sonarcloud.io"
}
}
1 change: 1 addition & 0 deletions nnd-data-exchange-service/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'nnd-data-exchange-service'
Binary file modified nnd-data-poll-service/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions nnd-data-poll-service/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'nnd-data-poll-service'
Binary file added nnd-message-processor/.DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rootProject.name = 'NEDSS-NNDSS'

include 'nnd-data-exchange-service'

include 'nnd-data-poll-service'

include 'nnd-message-processor'

0 comments on commit 410c793

Please sign in to comment.