Skip to content

java-webapp-gha

java-webapp-gha #91

Workflow file for this run

name: java-webapp-gha
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ "main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
JF_ENV_1: ${{ secrets.JF_DEMO_SECRET }}
JF_ID: yann-sbx
JF_CLI_VERSION: 2.48.0
APP_VERSION: 2.0.0
MVN_REPO: yann-mvn
JFROG_CLI_BUILD_PROJECT: yann
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build_webapp:
if: ${{ true }}
runs-on: ubuntu-latest
env:
#JF_ENV_1: ${{ secrets.JF_DEMO_SECRET }}
JFROG_BUILD_STATUS: PASS
JAVA_VERSION: 16.0.2+7
JAVA_DIST: zulu
MVN_VERSION: 3.8.2
# required by jf CLI
# M2_HOME: /opt/hostedtoolcache/maven/3.8.2/x64 # NOT required in jf CLI v2.3.0
#MVN_REPO: yann-mvn
PROMOTE_REPO: yann-mvn-release-local
steps:
- uses: actions/checkout@v2
- name: Setup JFrog CLI
uses: jfrog/setup-jfrog-cli@v2
with:
version: ${{ env.JF_CLI_VERSION }}
- name: Setup Java JDK ${{ env.JAVA_DIST }} ${{ env.JAVA_VERSION }}
uses: actions/[email protected]
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DIST }}
- name: Setup Maven ${{ env.MVN_VERSION }}
uses: stCarolas/[email protected]
with:
maven-version: ${{ env.MVN_VERSION }}
- name: Ping Artifactory
run: |
jf --version
jf config show
jf rt ping
env
- name: Configure JFrog CLI with Maven client
run: |
jf rt mvnc \
--server-id-resolve=${{ env.JF_ID }} \
--repo-resolve-releases=${{ env.MVN_REPO }} \
--repo-resolve-snapshots=${{ env.MVN_REPO }} \
--server-id-deploy=${{ env.JF_ID }} \
--repo-deploy-releases=${{ env.MVN_REPO }} \
--repo-deploy-snapshots=${{ env.MVN_REPO }}
- name: Scan dependencies
run: cd src && jf audit
- name: Build webapp and scan generated artifact before upload
run: jf mvn clean install -f src/ --no-transfer-progress
- name: Publish Build Info
run: |
# Collect environment variables for the build
jf rt bce
# Collect VCS details from git and add them to the build
jf rt bag
# Publish build info
jf rt bp
- name: Run test
run: echo running tests ...
- name: Promote Build
run: jf rt bpr --fail-fast=false --status "TEST_OK" --comment "promoted to the next level" ${{ env.PROMOTE_REPO }}
build_docker:
if: ${{ true }}
needs: build_webapp
runs-on: ubuntu-latest
env:
DOCKER_REPO: yann-docker
SRC_REPO: yann-docker-dev-local
PROMOTE_REPO: yann-docker-release-local
steps:
- uses: actions/checkout@v2
- name: Setup JFrog CLI
uses: jfrog/setup-jfrog-cli@v2
with:
version: ${{ env.JF_CLI_VERSION }}
- name: Download webapp
run: |
jf rt download \
--build $JFROG_CLI_BUILD_NAME/$JFROG_CLI_BUILD_NUMBER \
--exclusions "*.pom;*library*" \
--flat=true \
--build-name=docker-$JFROG_CLI_BUILD_NAME --build-number=$JFROG_CLI_BUILD_NUMBER \
--fail-no-op=true \
--module=webapp \
--project=$JFROG_CLI_BUILD_PROJECT \
${{ env.MVN_REPO }} src/multi-module-application.jar
- name: Docker Login
uses: docker/[email protected]
with:
registry: ${{ secrets.DOCKER_DEMO_REG }}
username: ${{ secrets.DOCKER_DEMO_USER }}
password: ${{ secrets.DOCKER_DEMO_PASS }}
- name: Build Docker image
uses: docker/[email protected]
with:
context: src/
tags: ${{ env.DOCKER_REG }}/${{ env.DOCKER_REPO }}/gha-java-webapp:${{ env.APP_VERSION }}
build-args: |
REGISTRY=${{ env.DOCKER_REG }}
DOCKER_REPO=${{ env.DOCKER_REPO }}
- name: Scan Docker image
run: |
jf docker scan ${{ env.DOCKER_REG }}/${{ env.DOCKER_REPO }}/gha-java-webapp:${{ env.APP_VERSION }}
- name: Push Docker image
run: jf docker push ${{ env.DOCKER_REG }}/${{ env.DOCKER_REPO }}/gha-java-webapp:${{ env.APP_VERSION }} --build-name=docker-$JFROG_CLI_BUILD_NAME --build-number=$JFROG_CLI_BUILD_NUMBER
- name: Publish Docker Build Info
run: |
jf rt bce docker-$JFROG_CLI_BUILD_NAME $JFROG_CLI_BUILD_NUMBER
jf rt bag docker-$JFROG_CLI_BUILD_NAME $JFROG_CLI_BUILD_NUMBER
jf rt bp docker-$JFROG_CLI_BUILD_NAME $JFROG_CLI_BUILD_NUMBER
# - name: Scan Build
# run: jf bs --fail=false docker-$jf_CLI_BUILD_NAME $jf_CLI_BUILD_NUMBER
# - name: Deploy and Test
# run: echo deploy and run test
# - name: Promote Build
# run: jf rt bpr --fail-fast=false --status "XRAY_SCAN_OK" --source-repo ${{ env.SRC_REPO }} --comment "promoted to the next level" docker-$jf_CLI_BUILD_NAME $jf_CLI_BUILD_NUMBER ${{ env.PROMOTE_REPO }}