add action and upgrade versions

This commit is contained in:
Rodolphe Fontaine 2024-10-18 10:48:49 +02:00
parent 62dbfa8e9a
commit d6e295d005
4 changed files with 196 additions and 7 deletions

11
.github/workflows/Dockerfile vendored Normal file
View file

@ -0,0 +1,11 @@
FROM eclipse-temurin:21-jdk-jammy
EXPOSE 8080
WORKDIR /app
COPY .mvn/ .mvn
COPY mvnw pom.xml ./
RUN ./mvnw dependency:resolve
COPY src ./src
CMD ["./mvnw", "spring-boot:run"]

28
.github/workflows/docker-build.txt vendored Normal file
View file

@ -0,0 +1,28 @@
A test for image build and push to JFrog Artifactory
this is a test
---
name: Build to Docker Hub
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Jfrog Artifactory
uses: docker/login-action@v3
with:
registry: rodi26.jfrog.io
username: 'rodolphe.fontaine@orange.fr'
password: ${{ secrets.JF_ACCESS_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: rodi26.jfrog.io/rodi26-docker/spring-petclinic:latest

View file

@ -11,14 +11,14 @@ on:
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '17' ]
java: [ '21' ]
steps:
- uses: actions/checkout@v4
- name: checkout Git repository
uses: actions/checkout@v4
- name: Set up JDK ${{matrix.java}}
uses: actions/setup-java@v4
with:
@ -27,3 +27,139 @@ jobs:
cache: maven
- name: Build with Maven Wrapper
run: ./mvnw -B package
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
Run_test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
- name: Run Tests
run: ./mvnw -B test
scan-repository:
runs-on: ubuntu-latest
needs: build-and-tag
strategy:
matrix:
# The repository scanning will be triggered periodically on the following branches.
branch: ["main"]
steps:
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '21'
- uses: jfrog/frogbot@v2.9.2
env:
# [Mandatory]
# JFrog platform URL
JF_URL: ${{ secrets.JF_URL }}
# [Mandatory if JF_USER and JF_PASSWORD are not provided]
# JFrog access token with 'read' permissions on Xray service
JF_ACCESS_TOKEN: ${{ secrets.JF_ACCESS_TOKEN }}
# [Mandatory if JF_ACCESS_TOKEN is not provided]
# JFrog username with 'read' permissions for Xray. Must be provided with JF_PASSWORD
# JF_USER: ${{ secrets.JF_USER }}
# [Mandatory if JF_ACCESS_TOKEN is not provided]
# JFrog password. Must be provided with JF_USER
# JF_PASSWORD: ${{ secrets.JF_PASSWORD }}
# [Mandatory]
# The GitHub token is automatically generated for the job
JF_GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# [Mandatory]
# The name of the branch on which Frogbot will perform the scan
JF_GIT_BASE_BRANCH: ${{ matrix.branch }}
# [Mandatory if using OIDC authentication protocol instead of JF_ACCESS_TOKEN]
# Insert to oidc-provider-name the 'Provider Name' defined in the OIDC integration configured in the JPD
# with:
# oidc-provider-name: ""
#JF_PATH_EXCLUSIONS: "*gradle*"
test-action:
runs-on: ubuntu-latest
needs: build-and-tag
strategy:
matrix:
java: [ '21' ]
steps:
- uses: actions/checkout@v4
- name: Set up JDK ${{matrix.java}}
uses: actions/setup-java@v4
with:
java-version: ${{matrix.java}}
distribution: 'adopt'
cache: maven
- name: Login to Jfrog Artifactory
uses: docker/login-action@v3
with:
registry: rodi26.jfrog.io
username: 'rodolphe.fontaine@orange.fr'
password: ${{ secrets.JF_ACCESS_TOKEN }}
- name: Set Up Docker
uses: docker-practice/actions-setup-docker@master
- name: Docker Run
run: docker run -d -p 8080:8080 rodi26.jfrog.io/rodi26-docker/spring-petclinic:latest
- name: Run JMeter Action on a test
uses: rbhadti94/apache-jmeter-action@v0.5.0
with:
testFilePath: src/test/jmeter/petclinic_test_plan.jmx
outputReportsFolder: reports/
args: "--loglevel INFO"
build-and-tag:
runs-on: ubuntu-latest
needs: Run_test
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup JFrog CLI
uses: jfrog/setup-jfrog-cli@v3
env:
JF_URL: ${{ secrets.JF_URL }}
JF_ACCESS_TOKEN: ${{ secrets.JF_ACCESS_TOKEN }}
- name: Build Tag and push Docker Image
env:
IMAGE_NAME: rodi26.jfrog.io/rodi26-docker/jfrog-spring-petclinic:${{ github.run_number }}
run: |
jf docker build -t $IMAGE_NAME .
jf docker push $IMAGE_NAME
- name: Publish Build info With JFrog CLI
env:
# Generated and maintained by GitHub
JFROG_CLI_BUILD_NAME: jfrog-spring-petclinic
# JFrog organization secret
JFROG_CLI_BUILD_NUMBER : ${{ github.run_number }}
run: |
# Export the build name and build nuber
# Collect environment variables for the build
jf rt build-collect-env
# Collect VCS details from git and add them to the build
jf rt build-add-git
# Publish build info
jf rt build-publish

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns="https://maven.apache.org/POM/4.0.0"
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>
<groupId>org.springframework.samples</groupId>
@ -18,7 +18,7 @@
<properties>
<!-- Generic properties -->
<java.version>17</java.version>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- Important for reproducible builds. Update using e.g. ./mvnw versions:set -DnewVersion=... -->
@ -275,7 +275,21 @@
<groupId>org.cyclonedx</groupId>
<artifactId>cyclonedx-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.4.3</version>
<configuration>
<!-- openjdk:11.0.5-jre -->
<from>
<image>openjdk:17-oracle</image>
</from>
<to>
<image>docker.io/${docker.image.prefix}/${project.artifactId}</image>
<credHelper>pass</credHelper>
</to>
</configuration>
</plugin>
</plugins>
</build>