mirror of https://github.com/halo-dev/halo
Add build and publish tasks for Docker images using Buildpacks
parent
98f655c018
commit
cd2dac7f01
|
@ -80,6 +80,32 @@ jobs:
|
|||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: gh release upload ${{ github.event.release.tag_name }} application/build/libs/*
|
||||
|
||||
build-and-publish-container-image-with-buildpacks:
|
||||
if: always() && (github.event_name == 'push' || github.event_name == 'release')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Setup Environment
|
||||
uses: ./.github/actions/setup-env
|
||||
- name: Reset version of Halo
|
||||
if: github.event_name == 'release'
|
||||
shell: bash
|
||||
run: |
|
||||
# Set the version with tag name when releasing
|
||||
version=${{ github.event.release.tag_name }}
|
||||
version=${version#v}
|
||||
sed -i "s/version=.*-SNAPSHOT$/version=$version/1" gradle.properties
|
||||
- name: Publish To Container Registries
|
||||
env:
|
||||
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
||||
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
|
||||
F2C_USERNAME: ${{ secrets.F2C_REGISTRY_USER }}
|
||||
F2C_TOKEN: ${{ secrets.F2C_REGISTRY_TOKEN }}
|
||||
GHCR_USERNAME: ${{ github.repository_owner }}
|
||||
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run:
|
||||
./gradlew publishToAllRegistries -Prelease=${{ github.event_name == 'release' && 'true' || 'false' }}
|
||||
|
||||
docker-build-and-push:
|
||||
if: always() && needs.build.result == 'success' && (github.event_name == 'push' || github.event_name == 'release')
|
||||
runs-on: ubuntu-latest
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import de.undercouch.gradle.tasks.download.Download
|
||||
import org.gradle.crypto.checksum.Checksum
|
||||
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage
|
||||
import org.springframework.boot.gradle.tasks.bundling.BootJar
|
||||
import org.springframework.util.StringUtils
|
||||
|
||||
plugins {
|
||||
id "checkstyle"
|
||||
|
@ -14,6 +17,7 @@ plugins {
|
|||
alias(libs.plugins.checksum)
|
||||
alias(libs.plugins.springdoc.openapi)
|
||||
alias(libs.plugins.versions)
|
||||
alias(libs.plugins.grgit)
|
||||
}
|
||||
|
||||
group = 'run.halo.app'
|
||||
|
@ -194,3 +198,67 @@ tasks.named('generateOpenApiDocs') {
|
|||
false
|
||||
}
|
||||
}
|
||||
|
||||
def name = 'halo'
|
||||
def tagName = "${project.version}-cnb"
|
||||
def isRelease = Objects.equals(project.findProperty('release'), 'true')
|
||||
if (!isRelease) {
|
||||
name = 'halo-dev'
|
||||
tagName = "cnb-sha-${grgit.head().abbreviatedId}"
|
||||
}
|
||||
|
||||
tasks.register('publishToGhcr', BootBuildImage) {
|
||||
group = 'publishing'
|
||||
description = 'Build and publish the Docker image to GitHub Container Registry.'
|
||||
imageName = "ghcr.io/halo/${name}:${tagName}"
|
||||
publish = StringUtils.hasText(System.getenv('GHCR_TOKEN'))
|
||||
if (!isRelease) {
|
||||
tags = ["ghcr.io/halo/${name}:main".toString()]
|
||||
}
|
||||
docker {
|
||||
publishRegistry {
|
||||
username = System.getenv('GHCR_USERNAME')
|
||||
password = System.getenv('GHCR_TOKEN')
|
||||
}
|
||||
}
|
||||
archiveFile = tasks.named('bootJar', BootJar).get().archiveFile
|
||||
}
|
||||
|
||||
tasks.register('publishToDockerHub', BootBuildImage) {
|
||||
group = 'publishing'
|
||||
description = 'Build and publish the Docker image to Docker Hub.'
|
||||
imageName = "halohub/${name}:${tagName}"
|
||||
publish = StringUtils.hasText(System.getenv('DOCKER_TOKEN'))
|
||||
if (!isRelease) {
|
||||
tags = ["halohub/${name}:main".toString()]
|
||||
}
|
||||
docker {
|
||||
publishRegistry {
|
||||
username = System.getenv("DOCKER_USERNAME")
|
||||
password = System.getenv("DOCKER_TOKEN")
|
||||
}
|
||||
}
|
||||
archiveFile = tasks.named('bootJar', BootJar).get().archiveFile
|
||||
}
|
||||
|
||||
tasks.register('publishToFit2Cloud', BootBuildImage) {
|
||||
imageName = "registry.fit2cloud.com/${name}:${tagName}"
|
||||
description = 'Build and publish the Docker image to Fit2Cloud Container Registry.'
|
||||
publish = StringUtils.hasText(System.getenv('F2C_TOKEN'))
|
||||
if (!isRelease) {
|
||||
tags = ["registry.fit2cloud.com/${name}:main".toString()]
|
||||
}
|
||||
docker {
|
||||
publishRegistry {
|
||||
username = System.getenv("F2C_USERNAME")
|
||||
password = System.getenv("F2C_TOKEN")
|
||||
}
|
||||
}
|
||||
archiveFile = tasks.named('bootJar', BootJar).get().archiveFile
|
||||
}
|
||||
|
||||
tasks.register('publishToAllRegistries') {
|
||||
group = 'publishing'
|
||||
description = 'Build and publish the Docker image to all configured registries.'
|
||||
dependsOn tasks.named('publishToGhcr'), tasks.named('publishToDockerHub'), tasks.named('publishToFit2Cloud')
|
||||
}
|
||||
|
|
|
@ -49,3 +49,4 @@ node = 'com.github.node-gradle.node:7.1.0'
|
|||
openapi-generator = 'org.openapi.generator:7.12.0'
|
||||
springdoc-openapi = 'org.springdoc.openapi-gradle-plugin:1.9.0'
|
||||
versions = 'com.github.ben-manes.versions:0.52.0'
|
||||
grgit = 'org.ajoberstar.grgit:5.3.3'
|
||||
|
|
Loading…
Reference in New Issue