Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/make repo generic #7

Merged
merged 9 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.gradle
build/*
build/*
*/build/*
96 changes: 96 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
pipeline {
environment {
ARTIFACTORY_URL = credentials('ARTIFACTORY_URL')
}

agent {
label 'build'
}

tools {
gradle "gradle-7.2"
jdk 'adoptjdk13'
}

stages {

stage ('Build Lambdas') {
steps {
withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
sh './gradlew -b build.gradle '
}
}
}
stage ('Test Lambdas') {
steps {
withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
sh './gradlew clean test --info -b build.gradle'
}
}
}

stage ('Build Jars') {
steps {
withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
sh './gradlew buildZip --info -b build.gradle'
}
}
}
// stage('SonarQube Analysis') {
// steps {
// withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
// // Automatically saves the an id for the SonarQube build
// withSonarQubeEnv('CMSSonar') {
// sh './gradlew sonarqube -Dsonar.projectKey=ab2d-lambdas-project -Dsonar.host.url=https://sonarqube.cloud.cms.gov'
// }
// }
// }
//}
// stage("Quality Gate") {
// options {
// timeout(time: 10, unit: 'MINUTES')
// }
// steps {
// Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails
// true = set pipeline to UNSTABLE, false = don't
// waitForQualityGate abortPipeline: true
// }
// }*/

stage ('Publish Lambdas') {
//when {
// branch 'main'
// }
steps {
withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
script {
def deployScript = '';

//Calls a gradle task to check if the version of each build has already been deployed
//Each build is broken up by '''.
def versionPublishedList = sh(
script: './gradlew -q lookForArtifacts',
returnStdout: true
).trim().split("'''")

//First value represents the build name and the second value is if the version is already deployed.
for (int i = 1; i < versionPublishedList.size(); i++) {
def artifactoryInfo = versionPublishedList[i].split(":")
if (artifactoryInfo[1] == 'false') {
echo "Deploying ${artifactoryInfo[0]}"
deployScript += "${artifactoryInfo[0]}:artifactoryPublish "
}
}

//deployScript represents what we are publishing. Insert it into the gradle command to do the publishing.
//ex. ab2d-fhir:artifactoryPublish"
//If nothing is there, skip publishing
if(deployScript != '') {
sh "./gradlew ${deployScript} -b build.gradle"
}
}
}
}
}
}
}
134 changes: 112 additions & 22 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ ext {
: System.getenv()['ARTIFACTORY_USER']
artifactory_password = project.hasProperty('artifactory_password') ? project.artifactory_password
: System.getenv()['ARTIFACTORY_PASSWORD']

metricsVersion = '1.0.0'
fetcherVersion = '1.0.0'


sourcesRepo = 'ab2d-maven-repo'
deployerRepo = 'ab2d-main'
resolverRepo = 'ab2d-main'
}


repositories {
mavenCentral()
maven {
Expand All @@ -27,33 +36,112 @@ repositories {
}
}

dependencies {
compileOnly 'org.projectlombok:lombok:1.18.24'
implementation 'com.amazonaws:aws-lambda-java-core:1.2.1'
implementation 'com.amazonaws:aws-lambda-java-events:3.11.0'
implementation 'org.springframework:spring-context:5.3.20'
implementation 'com.newrelic.agent.java:newrelic-api:7.6.0'
implementation 'ca.uhn.hapi.fhir:hapi-fhir-structures-dstu3:5.7.2'
implementation 'ca.uhn.hapi.fhir:hapi-fhir-structures-r4:5.7.2'
implementation 'gov.cms.ab2d:ab2d-aggregator:1.2.1'
implementation 'gov.cms.ab2d:ab2d-bfd:1.3.1'
implementation 'gov.cms.ab2d:ab2d-events-client:1.3.1'
implementation 'gov.cms.ab2d:ab2d-fhir:1.1.1'
implementation 'gov.cms.ab2d:ab2d-filters:1.6.1'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.13.3'
annotationProcessor "org.projectlombok:lombok:1.18.24"
}

test {
useJUnitPlatform()
}

task buildZip(type: Zip) {
from compileJava
from processResources
into('lib') {
from configurations.runtimeClasspath
subprojects {
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
publishing {
publications {
mavenJava(MavenPublication) {
artifact file("build/distributions/${project.name}.zip")
}
}
}

sourceCompatibility = 11
targetCompatibility = 11

group 'gov.cms.ab2d'


artifactory {
contextUrl = project.artifactoryLoc

publish {
repository {
repoKey = "${deployerRepo}"
username = project.artifactory_user
password = project.artifactory_password
maven = true
}
defaults {
publications('mavenJava')
publishArtifacts = true
publishBuildInfo = false
}
}
resolve {
repository {
repoKey = "${resolverRepo}"
username = project.artifactory_user
password = project.artifactory_password
maven = true
}
}
}
}

allprojects {

task lookForArtifacts {
doLast {
//This is the parent build where nothing gets published. Skip it.
if (project.name != 'ab2d-lambdas')
//Set path to repository that might exist if previous published on this version.
//Sets project name and if it exists in repository. Print out so jenkins can take it.
System.out.print("'''" + project.name + ":" + urlExists("${artifactoryLoc}/${deployerRepo}/gov/cms/ab2d/${project.name}/${project.version}/${project.name}-${project.version}.zip"))
}
}

repositories {
maven {
url = "${artifactoryLoc}/${sourcesRepo}"
credentials {
username = project.artifactory_user
password = project.artifactory_password
}
}
mavenCentral()
}


}

def getBase64EncodedCredentials() {
def s = "$artifactory_user" + ":" + "$artifactory_password"
return s.bytes.encodeBase64().toString()
}

//Check if url exist in the repository
def urlExists(repositoryUrl) {
try {
def connection = (HttpURLConnection) new URL(repositoryUrl).openConnection()

connection.setRequestProperty("Authorization", "Basic " + getBase64EncodedCredentials())
connection.setConnectTimeout(10000)
connection.setReadTimeout(10000)
connection.setRequestMethod("HEAD")

def responseCode = connection.getResponseCode()

if (responseCode == 401) {
throw new RuntimeException("Unauthorized MavenUser user. Please provide valid username and password.")
}

return (200 == responseCode)

} catch (IOException ignored) {
println(ignored)
return false
}
}

task buildZip(type: Zip) {
dependsOn ':metrics-lambda:buildZip'
dependsOn ':eob-fetcher:buildZip'
}

java {
Expand All @@ -62,3 +150,5 @@ java {
}

build.dependsOn buildZip


67 changes: 67 additions & 0 deletions eob-fetcher/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
plugins {
id 'java'
}

configurations {
all.collect { configuration ->
configuration.exclude group: 'org.springframework.boot'
configuration.exclude group: 'com.slack.api'
configuration.exclude group: 'org.jetbrains.kotlin'
configuration.exclude group: 'org.postgresql'
configuration.exclude group: 'com.squareup.okhttp3'
configuration.exclude group: 'commons-codec'
configuration.exclude group: 'com.squareup.okio'
configuration.exclude group: 'org.springframework.cloud'
configuration.exclude group: 'org.mock-server'
configuration.exclude group: 'software.amazon.awssdk:netty-nio-client'
configuration.exclude group: 'io.netty'
configuration.exclude group: 'org.testcontainers:testcontainers'
// Lombok is amazing but its jar is 2 MBs which is 20% of the total fat jar.
// Even when set as compile and annotationProcessor only gradle still adds it to the fat jar

}

}

version "$fetcherVersion"

dependencies {
compileOnly 'org.projectlombok:lombok:1.18.24'
implementation 'com.amazonaws:aws-lambda-java-core:1.2.1'
implementation 'com.amazonaws:aws-lambda-java-events:3.11.0'
implementation 'org.springframework:spring-context:5.3.20'
implementation 'com.newrelic.agent.java:newrelic-api:7.6.0'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dependabot - change this to 7.10.0

implementation 'ca.uhn.hapi.fhir:hapi-fhir-structures-dstu3:5.7.2'
implementation 'ca.uhn.hapi.fhir:hapi-fhir-structures-r4:5.7.2'
implementation 'gov.cms.ab2d:ab2d-aggregator:1.2.1'
implementation 'gov.cms.ab2d:ab2d-bfd:1.3.1'
implementation 'gov.cms.ab2d:ab2d-events-client:1.3.1'
implementation 'gov.cms.ab2d:ab2d-fhir:1.1.1'
implementation 'gov.cms.ab2d:ab2d-filters:1.6.1'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.13.3'
annotationProcessor "org.projectlombok:lombok:1.18.24"
}

test {
useJUnitPlatform()
}

task buildZip(type: Zip) {
from compileJava
from processResources
into('lib') {
from configurations.runtimeClasspath
}
archiveFileName = 'eob-fetcher.zip'
}

task wrapper(type: Wrapper){
gradleVersion = '7.5'
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does AWS support 17 yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet. It's been requested for almost a year aws/aws-lambda-base-images#29

}

build.dependsOn buildZip
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Empty file modified gradlew
100644 → 100755
Empty file.
Loading