diff --git a/.github/workflows/Dockerfile b/.github/workflows/Dockerfile new file mode 100644 index 000000000..65c027669 --- /dev/null +++ b/.github/workflows/Dockerfile @@ -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"] \ No newline at end of file diff --git a/.github/workflows/docker-build.txt b/.github/workflows/docker-build.txt new file mode 100644 index 000000000..0d328d7f7 --- /dev/null +++ b/.github/workflows/docker-build.txt @@ -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 \ No newline at end of file diff --git a/.github/workflows/maven-build.yml b/.github/workflows/maven-build.yml index 4718a6ce5..6b98c425c 100644 --- a/.github/workflows/maven-build.yml +++ b/.github/workflows/maven-build.yml @@ -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 \ No newline at end of file diff --git a/pom.xml b/.github/workflows/pom.xml similarity index 96% rename from pom.xml rename to .github/workflows/pom.xml index e32768166..a88005e5c 100644 --- a/pom.xml +++ b/.github/workflows/pom.xml @@ -1,6 +1,6 @@ 4.0.0 org.springframework.samples @@ -18,7 +18,7 @@ - 17 + 21 UTF-8 UTF-8 @@ -275,7 +275,21 @@ org.cyclonedx cyclonedx-maven-plugin - + + com.google.cloud.tools + jib-maven-plugin + 3.4.3 + + + + openjdk:17-oracle + + + docker.io/${docker.image.prefix}/${project.artifactId} + pass + + +