Skip to content

Commit

Permalink
Fix package push to ghcr
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikreuzer committed Jan 3, 2025
1 parent c1e3d79 commit b3cbc43
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 71 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/gradle-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ jobs:
cache: 'gradle'
- name: Build with Gradle
run: ./gradlew build
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to Maven Central
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USERNAME }}
Expand All @@ -55,6 +49,12 @@ jobs:
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_PRIVATE_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }}
run: ./gradlew publishAllPublicationsToMavenCentralRepository
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image to GitHub Packages
run: ./gradlew bootBuildImage
- name: Publish Chart to GitHub Packages
Expand Down
130 changes: 65 additions & 65 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,71 +38,7 @@ license {
exclude("**/*.properties")
}

helm {
charts {
create("main") {
chartName.set("${project.name}-chart")
chartVersion.set("${project.version}")
sourceDir.set(file("src/main/helm"))
}
}
}

tasks.register("replaceChartVersion") {
doLast {
val chartFile = file("src/main/helm/Chart.yaml")
val content = chartFile.readText()
val updatedContent = content.replace("\${chartVersion}", "${project.version}")
chartFile.writeText(updatedContent)
}
}

tasks.register("helmPush") {
description = "Push Helm chart to OCI registry"
group = "helm"
dependsOn(tasks.named("helmPackageMainChart"))

doLast {
val registryUrl = getProperty("REGISTRY_URL")
val registryUsername = getProperty("REGISTRY_USERNAME")
val registryPassword = getProperty("REGISTRY_PASSWORD")
val registryNamespace = getProperty("REGISTRY_NAMESPACE")

helm.execHelm("registry", "login") {
option("-u", registryUsername)
option("-p", registryPassword)
args(registryUrl)
}

helm.execHelm("push") {
args(tasks.named("helmPackageMainChart").get().outputs.files.singleFile.toString())
args("oci://$registryUrl/$registryNamespace")
}

helm.execHelm("registry", "logout") {
args(registryUrl)
}
}
}

fun getProperty(propertyName: String) = getenv(propertyName) ?: project.findProperty(propertyName) as String

tasks.named<BootBuildImage>("bootBuildImage") {
val registryUrl = getProperty("REGISTRY_URL")
val registryUsername = getProperty("REGISTRY_USERNAME")
val registryPassword = getProperty("REGISTRY_PASSWORD")
val registryNamespace = getProperty("REGISTRY_NAMESPACE")

imageName.set("$registryUrl/$registryNamespace/${project.name}:${project.version}")
publish = true
docker {
publishRegistry {
url.set(registryUrl)
username.set(registryUsername)
password.set(registryPassword)
}
}
}
fun getProperty(propertyName: String) = System.getenv(propertyName) ?: project.findProperty(propertyName) as String

mavenPublishing {
publishToMavenCentral(SonatypeHost.DEFAULT)
Expand Down Expand Up @@ -158,6 +94,70 @@ mavenPublishing {
}
}

tasks.named<BootBuildImage>("bootBuildImage") {
val registryUrl = getProperty("REGISTRY_URL")
val registryUsername = getProperty("REGISTRY_USERNAME")
val registryPassword = getProperty("REGISTRY_PASSWORD")
val registryNamespace = getProperty("REGISTRY_NAMESPACE")

imageName.set("$registryUrl/$registryNamespace/${rootProject.name}:${project.version}")
publish = true
docker {
publishRegistry {
url.set(registryUrl)
username.set(registryUsername)
password.set(registryPassword)
}
}
}

helm {
charts {
create("main") {
chartName.set("${rootProject.name}-chart")
chartVersion.set("${project.version}")
sourceDir.set(file("src/main/helm"))
}
}
}

tasks.register("replaceChartVersion") {
doLast {
val chartFile = file("src/main/helm/Chart.yaml")
val content = chartFile.readText()
val updatedContent = content.replace("\${chartVersion}", "${project.version}")
chartFile.writeText(updatedContent)
}
}

tasks.register("helmPush") {
description = "Push Helm chart to OCI registry"
group = "helm"
dependsOn(tasks.named("helmPackageMainChart"))

doLast {
val registryUrl = getProperty("REGISTRY_URL")
val registryUsername = getProperty("REGISTRY_USERNAME")
val registryPassword = getProperty("REGISTRY_PASSWORD")
val registryNamespace = getProperty("REGISTRY_NAMESPACE")

helm.execHelm("registry", "login") {
option("-u", registryUsername)
option("-p", registryPassword)
args(registryUrl)
}

helm.execHelm("push") {
args(tasks.named("helmPackageMainChart").get().outputs.files.singleFile.toString())
args("oci://$registryUrl/$registryNamespace")
}

helm.execHelm("registry", "logout") {
args(registryUrl)
}
}
}

repositories {
mavenCentral()
mavenLocal()
Expand Down

0 comments on commit b3cbc43

Please sign in to comment.