Skip to content

Commit

Permalink
Add CI/CD for Docker Build and Sonar cloud (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaikrishnaBairamoni authored Jun 28, 2023
1 parent a5a8b73 commit b88f08b
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 14 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: CI
on:
pull_request:
push:

jobs:
jpo-security-svcs:
runs-on: ubuntu-latest
container:
image: openjdk:17-jdk-slim-buster
options: --user root
steps:
- name: Checkout ${{ github.event.repository.name }}
uses: actions/checkout@v3
- name: Set up Maven
uses: stCarolas/setup-maven@v4.5
with:
maven-version: 3.8.2
- uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: Build
run: |
cd $GITHUB_WORKSPACE
ls -ls && pwd
mvn -e -X clean org.jacoco:jacoco-maven-plugin:prepare-agent package
mvn -e -X clean org.jacoco:jacoco-maven-plugin:report package
- name: Archive code coverage results
uses: actions/upload-artifact@v3
with:
name: jpo-security-svcs
path: /__w/jpo-security-svcs/jpo-security-svcs/target
if-no-files-found: error
tmca-tester:
runs-on: ubuntu-latest
steps:
- name: Checkout ${{ github.event.repository.name }}
uses: actions/checkout@v3
- name: build tmca-tester
uses: actions/setup-node@v3
with:
node-version: '18.x'
- run: |
cd $GITHUB_WORKSPACE/tmca-tester
npm install --force
node ./tmca-tester.js
sonar:
needs: [jpo-security-svcs, tmca-tester]
runs-on: ubuntu-latest
steps:
- name: Checkout ${{ github.event.repository.name }}
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download code coverage results
uses: actions/download-artifact@v3
with:
name: jpo-security-svcs
path: home/runner/work/jpo-security-svcs/jpo-security-svcs/target
- name: Find jacoco.xml
shell: bash
run: |
find "$GITHUB_WORKSPACE" -name "jacoco.xml"
- name: Setup SonarScanner
uses: warchant/setup-sonar-scanner@v4
with:
version: 4.8.0.2856
- name: Generate sonar properties file
run: |
cat <<EOF > /tmp/sonar-scanner.properties
sonar.host.url=https://sonarcloud.io
sonar.coverage.jacoco.xmlReportPaths=$GITHUB_WORKSPACE/tmca-tester/target/site/jacoco/jacoco.xml
sonar.java.binaries=home/runner/work/jpo-security-svcs/jpo-security-svcs/target
sonar.projectBaseDir=$GITHUB_WORKSPACE
sonar.projectKey=usdot-jpo-ode_jpo-security-svcs
sonar.organization=usdot-jpo-ode-1
jpo-security-svcs.sonar.projectBaseDir = home/runner/work/jpo-security-svcs/jpo-security-svcs
jpo-security-svcs.sonar.sources = src
tmca-tester.sonar.projectBaseDir=$GITHUB_WORKSPACE /tmca-tester
tmca-tester.sonar.sources=.
EOF
- name: Run SonarScanner
uses: usdot-fhwa-stol/actions/sonar-scanner@main
with:
sonar-properties-path: /tmp/sonar-scanner.properties
sonar-token: ${{ secrets.SONAR_TOKEN }}
working-dir: $GITHUB_WORKSPACE
21 changes: 21 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Docker build

on:
push:
branches-ignore:
- "develop"
- "master"
- "release/*"
pull_request:

jobs:
jpo-security-svcs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- run: ls -la && pwd
- name: Build
uses: docker/build-push-action@v3
27 changes: 27 additions & 0 deletions .github/workflows/dockerhub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "DockerHub Build and Push"

on:
push:
branches:
- "develop"
- "master"
- "release/*"

jobs:
dockerhub-jpo-ode:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build
uses: docker/build-push-action@v3
with:
push: true
tags: usdotjpoode/jpo-security-svcs:${{ github.ref_name }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
**.jks
**.pem
.env
**.crt
**.crt
.sonar/
dependency-reduced-pom.xml
80 changes: 67 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -18,6 +16,20 @@
<packaging>jar</packaging>
<name>jpo-security-svcs</name>
<description>JPO ODE Cryptography Module</description>
<properties>
<java.version>1.8</java.version>
<jmockit.version>1.49</jmockit.version>
<argLine>-javaagent:${user.home}/.m2/repository/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar</argLine>
<sonar.organization>usdot-jpo-ode-1</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<!-- JaCoCo Properties -->
<jacoco.version>0.8.8</jacoco.version>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<sonar.language>java</sonar.language>
</properties>


<dependencies>
<dependency>
Expand Down Expand Up @@ -64,21 +76,63 @@
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
</dependency>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>${jmockit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.11</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.projectreactor</groupId>
<artifactId>reactor-spring</artifactId>
<version>1.0.1.RELEASE</version>
</dependency>
</dependencies>

<properties>
<java.version>1.8</java.version>
</properties>


<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down

0 comments on commit b88f08b

Please sign in to comment.