Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
7032596
  • Loading branch information
daileyo committed Mar 29, 2024
0 parents commit 0665404
Show file tree
Hide file tree
Showing 75 changed files with 3,277 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Application settings
APP_NAME=dks-api
APP_PORT=8080
SPRING_PROFILES_ACTIVE=local
HEALTH_CHECK_URL=http://${APP_NAME}:${APP_PORT}/actuator/health

# Debug settings
JAVA_DEBUG_PORT=5005
JAVA_ENABLE_DEBUG=false

# Database settings
DB_CONTAINER_NAME=dks-db
POSTGRES_USER=postgres
POSTGRES_PASSWORD=<UPDATE ME>

# Gradle settings
# Gradle User Home is set to /app/.gradle for use within the container which uses /app as the working directory
GRADLE_USER_HOME=/app/.gradle

# Optional settings
# Uncomment and set the value as needed
# PGPORT=<TCP port that database server answers on (default: 5432)>
164 changes: 164 additions & 0 deletions .github/workflows/build-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
name: Build Java Project

on:
pull_request:
branches: [main]
workflow_call:
inputs:
tagTypes:
required: false
type: string
default: |
type=sha
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
name: Build and Test with Gradle
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4
with:
java-version: '17'
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

- name: Lint
run: echo TODO linting

- name: Unit Test
run: ./gradlew test

- name: Build JAR
run: ./gradlew bootJar

- name: Upload JAR
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4
with:
name: dks-api
path: build/libs/devops-knowledge-share-api.jar

dependency-submission:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Set up JDK 17
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4
with:
java-version: '17'
distribution: 'temurin'

- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

docker-build:
name: Build and Push Container Image
needs: build
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.meta.outputs.json }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Download JAR
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4
with:
name: dks-api
path: build/libs

- name: Log in to the Container registry
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 # v4
with:
images: |
${{ env.REGISTRY }}/${{ github.repository }}
# when opened on pull request, no inputs are provided. when empty the
# defaults are used which produces pr-* as the tag to the image using
# the below information.
# type=schedule,pattern=nightly,enable=true,priority=1000
# type=ref,event=branch,enable=true,priority=600
# type=ref,event=tag,enable=true,priority=600
# type=ref,event=pr,prefix=pr-,enable=true,priority=600
tags: |
${{ inputs.tagTypes }}
- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@2b51285047da1547ffb1b2203d8be4c0af6b1f20 # v3

- name: Build and push Docker image
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5
with:
push: true
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

scan:
needs: docker-build
runs-on: ubuntu-latest
strategy:
matrix:
version: ${{ fromJSON(needs.docker-build.outputs.matrix).tags }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ matrix.version }}
# exit-code: '1'
# ignore-unfixed: true
severity: 'CRITICAL,HIGH'
format: 'template'
template: '@/contrib/sarif.tpl'
output: 'trivy-results.sarif'
env:
TRIVY_USERNAME: trivy
TRIVY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3
with:
name: 'trivy-results'
path: 'trivy-results.sarif'

- name: Run Trivy in GitHub SBOM mode and submit results to Dependency Snapshots
uses: aquasecurity/trivy-action@master
with:
format: 'github'
output: 'dependency-results.sbom.json'
image-ref: ${{ matrix.version }}
github-pat: ${{ secrets.GITHUB_TOKEN }}
env:
TRIVY_USERNAME: trivy
TRIVY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3
with:
name: 'trivy-sbom'
path: 'dependency-results.sbom.json'

# This can't be setup until we enable GHAS
# - name: Upload Trivy scan results to GitHub Security tab
# uses: github/codeql-action/upload-sarif@v2
# with:
# sarif_file: 'trivy-results.sarif'
75 changes: 75 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [main]
pull_request:
# The branches below must be a subset of the branches above
branches: [main]
schedule:
- cron: '22 8 * * 1'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: ['java']
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@a82bad71823183e5b120ab52d521460ecb0585fe # v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to:
# https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@a82bad71823183e5b120ab52d521460ecb0585fe # v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@a82bad71823183e5b120ab52d521460ecb0585fe # v2
with:
category: "/language:${{matrix.language}}"
19 changes: 19 additions & 0 deletions .github/workflows/conventional-commits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This workflow checks that commits on the PR have been made against the
# conventional commits spec.

name: Conventional Commits

on:
pull_request:
types:
- opened
- edited
- synchronize

jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: liatrio/github-actions/conventional-pr-title@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
43 changes: 43 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This workflow is the main workflow on pushing to the main branch
# and runs builds, releases, conventional commits, and pushes.

name: Main

on:
push:
branches: [main]

jobs:
build-java:
uses: ./.github/workflows/build-java.yml
with:
tagTypes: |
type=sha
release:
runs-on: ubuntu-latest
needs: [build-java]
outputs:
changed: ${{ steps.tag.outputs.changed }}
newVersion: ${{ steps.tag.outputs.newVersion }}
steps:
- name: Checkout code with commit history
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
with:
fetch-depth: 0

- uses: liatrio/github-action-conventional-release@175f2e2567994ea2bd99fd6ad86a62c5fe894a12 # v0.2.0
id: tag
with:
debug: true
env:
GITHUB_TOKEN: ${{ secrets.LIATRIO_BOT_PRIVATE_REPO_ACCESS_PAT }}

publish-image:
uses: ./.github/workflows/build-java.yml
needs: release
if: needs.release.outputs.changed == 'true'
with:
tagTypes: |
type=semver,pattern={{version}},value=${{ needs.release.outputs.newVersion }}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
62 changes: 62 additions & 0 deletions .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Scorecards supply-chain security
on:
# Only the default branch is supported.
branch_protection_rule:
schedule:
- cron: '27 21 * * 2'
push:
branches: [main]

# Declare default permissions as read only.
permissions: read-all

jobs:
analysis:
name: Scorecards analysis
runs-on: ubuntu-latest
permissions:
# Needed to upload the results to code-scanning dashboard.
security-events: write
# Used to receive a badge.
id-token: write
# Needs for private repositories.
contents: read
actions: read

steps:
- name: "Checkout code"
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1
with:
results_file: results.sarif
results_format: sarif
# (Optional) Read-only PAT token. Uncomment the `repo_token` line below if:
# - you want to enable the Branch-Protection check on a *public* repository, or
# - you are installing Scorecards on a *private* repository
# To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat.
repo_token: ${{ secrets.LIATRIO_BOT_PRIVATE_REPO_ACCESS_PAT }}

# Publish the results for public repositories to enable scorecard badges. For more details, see
# https://github.com/ossf/scorecard-action#publishing-results.
# For private repositories, `publish_results` will automatically be set to `false`, regardless
# of the value entered here.
publish_results: true

# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: SARIF file
path: results.sarif
retention-days: 5

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@a82bad71823183e5b120ab52d521460ecb0585fe # v2.24.9
with:
sarif_file: results.sarif
Loading

0 comments on commit 0665404

Please sign in to comment.