Skip to content

Commit

Permalink
moved from private repository
Browse files Browse the repository at this point in the history
  • Loading branch information
whiteo committed Nov 11, 2023
1 parent 0d95aa5 commit fbd43cd
Show file tree
Hide file tree
Showing 126 changed files with 7,323 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
.github
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DATABASE_URL=
DATABASE_USER=
DATABASE_PWD=
APP_LOG_LEVEL=DEBUG/INFO/ERROR
TOKEN_EXPIRATION_TIME=7200000
TOKEN_SECRET_KEY=TOKEN_SIZE_IS_MIN_24_CHARS
DEMO_ONLY=TRUE/FALSE
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "docker"
directory: "/"
target-branch: "main"
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: "/"
target-branch: "main"
schedule:
interval: "daily"
191 changes: 191 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
name: build

on:
push:
branches: [ main ]
paths: [ '**.java', '.github/workflows/build.yml' ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
test:
name: Test coverage
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Checkout badges branch to a badges directory nested inside first checkout
uses: actions/checkout@v4
with:
ref: badges
path: badges

- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '20'
distribution: 'temurin'

- name: Prepare Language Files
run: |
mkdir -p ./mylfa/languages
curl -o ./mylfa/languages/osd.traineddata https://github.com/tesseract-ocr/tessdata/raw/main/osd.traineddata
- name: Build with Maven
env:
DEMO_ONLY: ${{ secrets.DEMO_ONLY }}
TOKEN_SECRET_KEY: ${{ secrets.TOKEN_SECRET_KEY }}
TOKEN_EXPIRATION_TIME: ${{ secrets.TOKEN_EXPIRATION_TIME }}
APP_LOG_LEVEL: ${{ secrets.APP_LOG_LEVEL }}
DATABASE_PWD: ${{ secrets.DATABASE_PWD }}
DATABASE_USER: ${{ secrets.DATABASE_USER }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
run: |
mvn -B test
- name: Generate JaCoCo badge
id: jacoco
uses: cicirello/jacoco-badge-generator@v2
with:
badges-directory: badges
generate-branches-badge: true
generate-summary: true

- name: Log coverage percentages to workflow output
run: |
echo "coverage = ${{ steps.jacoco.outputs.coverage }}"
echo "branches = ${{ steps.jacoco.outputs.branches }}"
- name: Upload JaCoCo coverage report as a workflow artifact
uses: actions/upload-artifact@v3
with:
name: jacoco-report
path: target/site/jacoco/

- name: Commit and push the coverage badges and summary file
if: ${{ github.event_name != 'pull_request' }}
run: |
cd badges
if [[ `git status --porcelain *.svg *.json` ]]; then
git config --global user.name 'github-actions'
git config --global user.email '1650200+github-actions[bot]@users.noreply.github.com'
git add *.svg *.json
git commit -m "Autogenerated JaCoCo coverage badges" *.svg *.json
git push
fi
- name: Comment on PR with coverage percentages
if: ${{ github.event_name == 'pull_request' }}
run: |
REPORT=$(<badges/coverage-summary.json)
COVERAGE=$(jq -r '.coverage' <<< "$REPORT")%
BRANCHES=$(jq -r '.branches' <<< "$REPORT")%
NEWLINE=$'\n'
BODY="## JaCoCo Test Coverage Summary Statistics${NEWLINE}* __Coverage:__ ${COVERAGE}${NEWLINE}* __Branches:__ ${BRANCHES}"
gh pr comment ${{github.event.pull_request.number}} -b "${BODY}"
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

docker-deploy:
needs: [ test ]
name: Docker release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '20'
distribution: 'temurin'

- name: Build with Maven
run: mvn clean package -DskipTests=true --no-transfer-progress

- name: Create target directory
run: mkdir -p ${{ github.workspace }}/target

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: whiteo/mylfa

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

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Get version from pom.xml
id: get-version
run: echo "::set-output name=version::$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)"

- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
context: ${{ github.workspace }}
platforms: linux/amd64, linux/arm64
tags: |
whiteo/mylfa:${{ steps.get-version.outputs.version }}
whiteo/mylfa:latest
build-args: TAG=${{ steps.get-version.outputs.version }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

gh-release-deploy:
needs: [ docker-deploy ]
name: Github release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Archive source code
run: zip -r source-code.zip .

- name: Get version from pom.xml
id: get-version
run: echo "::set-output name=version::$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)"

- name: Check if release exists
id: check-release
run: |
version=${{ steps.get-version.outputs.version }}
releases=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/tags/v$version")
if [[ $releases == *"\"tag_name\":\"v$version\""* ]]; then
echo "::set-output name=release_exists::true"
else
echo "::set-output name=release_exists::false"
fi
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.get-version.outputs.version }}
release_name: Release v${{ steps.get-version.outputs.version }}
draft: false
if: steps.check-release.outputs.release_exists != 'true'

- name: Upload source code
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./source-code.zip
asset_name: source-code.zip
asset_content_type: application/zip
85 changes: 85 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
### Git ###
# Created by git for backups. To disable backups in Git:
# $ git config --global mergetool.keepBackup false
*.orig

# Created by git when using merge tools for conflicts
*.BACKUP.*
*.BASE.*
*.LOCAL.*
*.REMOTE.*
*_BACKUP_*.txt
*_BASE_*.txt
*_LOCAL_*.txt
*_REMOTE_*.txt

### Maven ###
**/target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar

### Java ###
# Compiled class file
*.class

# Log file
*.log

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

# Sonarlint plugin
.idea/sonarlint

# IntelliJ
out/

# JIRA plugin
atlassian-ide-plugin.xml

### VS Code ###
.vscode/

### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
*.lnk

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

### Linux ###
*~

# KDE directory preferences
.directory
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM --platform=$BUILDPLATFORM eclipse-temurin:20-jre-alpine

RUN mkdir -p /app/mylfa/languages

WORKDIR /app

COPY target/mylfa.jar /app/mylfa.jar

# env values are stored in .env file
ENV DATABASE_URL ${DATABASE_URL}
ENV DATABASE_USER ${DATABASE_USER}
ENV DATABASE_PWD ${DATABASE_PWD}
ENV APP_LOG_LEVEL ${APP_LOG_LEVEL}
ENV TOKEN_EXPIRATION_TIME ${TOKEN_EXPIRATION_TIME}
ENV TOKEN_SECRET_KEY ${TOKEN_SECRET_KEY}
ENV DEMO_ONLY ${DEMO_ONLY}

EXPOSE 8080/tcp

RUN chown -R nobody:nobody /app/mylfa

USER nobody

CMD ["java", "-XX:MaxRAMPercentage=60.0", "-jar", "mylfa.jar"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Leo Tanas

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit fbd43cd

Please sign in to comment.