Skip to content

Commit

Permalink
try gha only
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Wiesner committed May 23, 2022
1 parent 359da44 commit 9bb1f54
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 39 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/gradle-build-push-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,18 @@ jobs:
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin


- name: Build OCI with Gradle
run: ./gradlew bootBuildImage --imageName $IMAGE_NAME --publishImage
run: ./gradlew bootBuildImage --imageName ghcr.io/$IMAGE_NAME
env:
IMAGE_TAG_BRANCH_COMMIT: ${{ steps.image-tags.outputs.branch_commit_tag }}
IMAGE_TAG_BRANCH: ${{ steps.image-tags.outputs.branch_tag }}
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Log in to registry
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
docker push ghcr.io/$IMAGE_NAME
build-push-image-dry-run:
name: Build OCI Image (Dry Run)
Expand Down
35 changes: 1 addition & 34 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage

plugins {
id("org.springframework.boot") version "2.7.0"
Expand Down Expand Up @@ -55,36 +54,4 @@ tasks.withType<KotlinCompile> {
)
jvmTarget = "17"
}
}

tasks.getByName<BootBuildImage>("bootBuildImage") {
imageName = project.name
val repoName = "ghcr.io/rowi1de"
val fullName = "$repoName/$imageName"
val branchCommitHashTag: String? =
getEnvironmentVariable("IMAGE_TAG_BRANCH_COMMIT")
tags = listOfNotNull(
branchCommitHashTag
).map { "$fullName:$it" }
.toList()
docker {
publishRegistry {
url = repoName
email = "hello@robert-wiesner.de"
token = requireNotNull(getEnvironmentVariable("GHCR_TOKEN")){"GHCR_TOKEN not set"}
}
}
}

/**
* Get value from environment variables and return if not blank or null.
* @param name name of the environment variable
* @param default default if null or blank
* @return value or default
*/
fun getEnvironmentVariable(name: String, default: String? = null): String? =
System.getenv()[name].takeUnless { it.isNullOrBlank() } ?: default

tasks.withType<Test> {
useJUnitPlatform()
}
}

0 comments on commit 9bb1f54

Please sign in to comment.