Skip to content

Commit

Permalink
Build docs using docker
Browse files Browse the repository at this point in the history
Migrate from jruby-based jekyll build to docker-based build
  • Loading branch information
lesserwhirls committed Feb 3, 2025
1 parent 8b5855c commit 0b562cc
Showing 1 changed file with 62 additions and 5 deletions.
67 changes: 62 additions & 5 deletions docs/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
plugins {
id 'base' // Adds 'assemble', 'check', 'build', and 'clean' tasks.
id 'edu.ucar.unidata.site.jekyll'
}

//////////////////////////////////////////////// Javadoc ////////////////////////////////////////////////
apply from: "$rootDir/gradle/any/dependencies.gradle"
apply from: "$rootDir/gradle/any/javadoc.gradle"
apply from: "$rootDir/gradle/any/testing.gradle"

Expand Down Expand Up @@ -115,6 +115,65 @@ gradle.projectsEvaluated { // Several statements below rely upon all subproject

apply from: "$rootDir/gradle/any/properties.gradle" // For Nexus credential properties.

String docTheme = "unidata-jekyll-docs:0.0.4"

boolean isGitHub = System.getenv('GITHUB_ACTIONS') as boolean
String imageBaseUrl = "docker.unidata.ucar.edu"
if (isGitHub) {
imageBaseUrl = "ghcr.io/unidata"
}

String dockerImage = "${imageBaseUrl}/${docTheme}"
Provider<Directory> siteBuildDir = layout.buildDirectory.dir("site")

tasks.register("buildJekyllSite", Exec) {
group = "documentation"
description = "Build the netCDF-Java documentation."
ConfigurableFileTree buildDocInputs = fileTree(".")
buildDocInputs.exclude("build/", ".gradle", ".jekyll-cache")
inputs.files(buildDocInputs)
outputs.dir(siteBuildDir)
commandLine("docker", "run", "--rm",
"-e", "SRC_DIR=/netcdf-java/docs/src/site",
"-v", "$rootDir:/netcdf-java",
"-v", "./${relativePath(siteBuildDir.get().toString())}:/site",
dockerImage, "build")
}

class NullOutputStream extends OutputStream {
@Override
void write(int b) throws IOException {}
}

tasks.register("serveJekyllSite", Exec) {
group = "documentation"
description = "Start a local server to live edit the netCDF-Java documentation."
commandLine("docker", "run", "--rm", "-d",
"--name", "netcdf-java-docs-server",
"-e", "SRC_DIR=/netcdf-java/docs/src/site",
"-v", "$rootDir:/netcdf-java",
"-p", "4005:4005",
dockerImage, "serve", "--livereload")
standardOutput = new NullOutputStream()
doLast {
String msg = "NetCDF-Java documentation available at http://localhost:4005"
String bannerBorder = new String(new char[msg.length() + 4]).replace("\0", "#");
println()
println(bannerBorder)
println("# $msg #")
println(bannerBorder)
println()
}
}

tasks.register("stopServe", Exec) {
group = "documentation"
description = "Stop the local server used while live editing the netCDF-Java documentation."
commandLine("docker", "stop", "netcdf-java-docs-server")
delete("$projectDir/src/site/Gemfile")
delete("$projectDir/src/site/Gemfile.lock")
}

import edu.ucar.build.publishing.tasks.PublishToRawRepoTask

tasks.withType(PublishToRawRepoTask).all { // Common PublishToRawRepoTask config.
Expand All @@ -134,16 +193,14 @@ tasks.withType(PublishToRawRepoTask).all { // Common PublishToRawRepoTask confi

tasks.register('publishAsVersionedUserGuide', PublishToRawRepoTask) {
description = 'Publish user guide (versioned) to Nexus under /major.minor/.'

publishSrc = buildJekyllSite.destinationDirectory.get()
publishSrc = layout.buildDirectory.dir("site")
destPath = "$project.docVersion/userguide/"
dependsOn tasks.getByName('buildJekyllSite')
}

tasks.register('publishAsCurrentUserGuide', PublishToRawRepoTask) {
description = 'Publish the user guide to Nexus under /current/.'

publishSrc = buildJekyllSite.destinationDirectory.get()
publishSrc = layout.buildDirectory.dir("site")
destPath = 'current/userguide/'
dependsOn tasks.getByName('buildJekyllSite')
}
Expand Down

0 comments on commit 0b562cc

Please sign in to comment.