Skip to content

Commit

Permalink
Merge pull request #296 from KPMP/KPMP-5135_create-github-action
Browse files Browse the repository at this point in the history
KPMP-5135_create-github-action
  • Loading branch information
rlreamy authored Feb 15, 2024
2 parents ef5f3aa + 504262c commit 15f60cd
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
38 changes: 38 additions & 0 deletions .github/workflows/build-gradle-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build orion-data docker image

on:
push:

jobs:
build-gradle-project:
runs-on: ubuntu-latest
steps:
- name: Get branch names
id: branch-names
uses: tj-actions/branch-names@v8

- name: Get current branch name
if: steps.branch-names.outputs.is_default == 'false'
run: |
echo "Running on branch: ${{ steps.branch-names.outputs.current_branch }}"
- name: Checkout project sources
uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: 7.4

- name: Login to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.ENV_DOCKER_USER }}
password: ${{ secrets.ENV_DOCKER_PASS }}

- name: Run build with Gradle Wrapper
run: |
./gradlew build docker
docker push "${{secrets.ENV_DOCKER_USER}}/orion-data:${{ steps.branch-names.outputs.current_branch }}"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ NOTE: You need to create a new credentials file if the permissions change
4. Authenticate.
5. The redirect to localhost will probably fail, since you're not running the app locally. Copy this URL.
6. Go into the spring container and do a wget on the pasted URL. This will create the credentials file and the app will start running.

# Build
`./gradlew build docker`
The default tag is the github branch name if no verison is provided
To pass a version when building the docker image execute
`./gradlew build docker -Ptag=<tagNumber>`
21 changes: 20 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,27 @@ task unpack(type: Copy) {
into("build/dependency")
}

def getTagInfo() {
if (project.hasProperty('tag')) {
def tagValue = project.property('tag')
return tagValue
} else {
def gitBranch = "Unknown branch"
try {
def workingDir = new File("${project.projectDir}")
def result = 'git rev-parse --abbrev-ref HEAD'.execute(null, workingDir)
result.waitFor()
if (result.exitValue() == 0) {
gitBranch = result.text.trim()
}
} catch (e) {
}
return gitBranch
}
}

docker {
name "${project.group}/${jar.baseName}:${jar.version}"
name "${project.group}/${jar.baseName}:" + getTagInfo()
copySpec.from(tasks.unpack.outputs).into("dependency")
buildArgs(['DEPENDENCY': "dependency"])
}

0 comments on commit 15f60cd

Please sign in to comment.