Skip to content

Commit

Permalink
Inventory (#24)
Browse files Browse the repository at this point in the history
* add inventory Docker and ci

* config inventory ci

* config pom
  • Loading branch information
khanhduzz authored Oct 1, 2024
1 parent b67df43 commit fc008dd
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 44 deletions.
168 changes: 168 additions & 0 deletions .github/workflows/inventory-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
name: Inventory service CI

on:
push:
branches: [ "main" ]
paths:
- "inventory/**"
- ".github/workflows/actions/action.yaml"
- ".github/workflows/inventory-ci.yaml"
- "pom.xml"
pull_request:
branches: [ "main" ]
paths:
- "inventory/**"
- ".github/workflows/actions/action.yaml"
- ".github/workflows/inventory-ci.yaml"
- "pom.xml"
workflow_dispatch:

jobs:
style:
runs-on: ubuntu-latest
name: Check style
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Run maven checkstyle
run: mvn checkstyle:checkstyle -f inventory
compile:
runs-on: ubuntu-latest
name: Compile project
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'adopt'
cache: maven

- name: Compile project
run: mvn clean compile -f inventory

unit-tests:
runs-on: ubuntu-latest
name: Unit tests
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'adopt'
cache: maven

- name: Running unit tests
run: mvn test -f inventory jacoco:report

build:
runs-on: ubuntu-latest
name: Build project
needs: [compile, unit-tests]
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'adopt'
cache: maven

- name: Building project
run: mvn package -f inventory

coverage:
runs-on: ubuntu-latest
env:
FROM_ORIGINAL_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name == github.repository || github.ref == 'refs/heads/main' }}
permissions:
pull-requests: write
packages: write
name: Coverage and Package
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'adopt'
cache: maven
- name: Building project
run: mvn package -f inventory
- name: Add coverage report to PR
uses: madrapps/[email protected]
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' }}
with:
paths: ${{github.workspace}}/inventory/target/site/jacoco/jacoco.xml
token: ${{secrets.GITHUB_TOKEN}}
min-coverage-overall: 30
min-coverage-changed-files: 20
title: 'Inventory Coverage Report'
update-comment: true

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
continue-on-error: false

- name: OWASP Dependency Check
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' }}
uses: dependency-check/Dependency-Check_Action@main
env:
JAVA_HOME: /opt/jdk
with:
project: 'matcha'
path: '.'
format: 'HTML'
- name: Upload OWASP Dependency Check results
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' }}
uses: actions/upload-artifact@master
with:
name: OWASP Dependency Check Report
path: ${{github.workspace}}/reports

- name: Log in to the Container registry
if: ${{ github.ref == 'refs/heads/main' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker images
if: ${{ github.ref == 'refs/heads/main' }}
uses: docker/build-push-action@v6
with:
context: ./inventory
push: true
file: ./inventory/Dockerfile
platforms: linux/amd64
tags: ghcr.io/${{ github.repository_owner }}/matcha-inventory:latest

check:
runs-on: ubuntu-latest
name: Git-leaks check
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Gitleaks check
run: |
docker pull zricethezav/gitleaks:v8.18.4
docker run --rm -v ${{ github.workspace }}:/work -w /work zricethezav/gitleaks:v8.18.4 detect --source="." --config="/work/gitleaks.toml" --verbose --no-git
3 changes: 3 additions & 0 deletions inventory/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM eclipse-temurin:21-jre-alpine
COPY target/inventory*.jar app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
51 changes: 21 additions & 30 deletions inventory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.4</version>
<relativePath/> <!-- lookup parent from repository -->
<groupId>com.fjb</groupId>
<artifactId>matcha</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<groupId>com.fjb</groupId>
<artifactId>inventory</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>${revision}</version>
<name>inventory</name>
<description>inventory</description>
<description>Matcha Inventory</description>

<url/>
<licenses>
<license/>
Expand All @@ -26,18 +26,18 @@
<tag/>
<url/>
</scm>

<properties>
<java.version>21</java.version>
<sonar.organization>khanhduzz</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.projectKey>khanhduzz_matcha-inventory</sonar.projectKey>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
Expand All @@ -46,33 +46,16 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
Expand All @@ -94,6 +77,14 @@
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
@SpringBootApplication
public class InventoryApplication {

public static void main(String[] args) {
SpringApplication.run(InventoryApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(InventoryApplication.class, args);
}

}
13 changes: 13 additions & 0 deletions inventory/src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
server.port=8080
server.servlet.context-path=/inventory

spring.profiles.active=test

spring.data.mongodb.uri=jdbc:h2:mem:testdb;NON_KEYWORDS=VALUE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

spring.jpa.hibernate.ddl-auto=update
spring.liquibase.enabled=false
11 changes: 0 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,6 @@
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
Expand Down

0 comments on commit fc008dd

Please sign in to comment.