Skip to content

Commit f565aef

Browse files
authored
Merge pull request #1410 from lesserwhirls/doc-build
Build docs using docker
2 parents 8b5855c + 403fe6a commit f565aef

File tree

2 files changed

+102
-5
lines changed

2 files changed

+102
-5
lines changed

docs/build.gradle

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
plugins {
22
id 'base' // Adds 'assemble', 'check', 'build', and 'clean' tasks.
3-
id 'edu.ucar.unidata.site.jekyll'
43
}
54

65
//////////////////////////////////////////////// Javadoc ////////////////////////////////////////////////
6+
apply from: "$rootDir/gradle/any/dependencies.gradle"
77
apply from: "$rootDir/gradle/any/javadoc.gradle"
88
apply from: "$rootDir/gradle/any/testing.gradle"
99

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

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

118+
String docTheme = "unidata-jekyll-docs:0.0.4"
119+
120+
boolean isGitHub = System.getenv('GITHUB_ACTIONS') as boolean
121+
String imageBaseUrl = "docker.unidata.ucar.edu"
122+
if (isGitHub) {
123+
imageBaseUrl = "ghcr.io/unidata"
124+
}
125+
126+
String dockerImage = "${imageBaseUrl}/${docTheme}"
127+
Provider<Directory> siteBuildDir = layout.buildDirectory.dir("site")
128+
129+
tasks.register("buildJekyllSite", Exec) {
130+
group = "documentation"
131+
description = "Build the netCDF-Java documentation."
132+
ConfigurableFileTree buildDocInputs = fileTree(".")
133+
buildDocInputs.exclude("build/", ".gradle", ".jekyll-cache")
134+
inputs.files(buildDocInputs)
135+
outputs.dir(siteBuildDir)
136+
commandLine("docker", "run", "--rm",
137+
"-e", "SRC_DIR=/netcdf-java/docs/src/site",
138+
"-v", "$rootDir:/netcdf-java",
139+
"-v", "./${relativePath(siteBuildDir.get().toString())}:/site",
140+
dockerImage, "build")
141+
}
142+
143+
class NullOutputStream extends OutputStream {
144+
@Override
145+
void write(int b) throws IOException {}
146+
}
147+
148+
tasks.register("serveJekyllSite", Exec) {
149+
group = "documentation"
150+
description = "Start a local server to live edit the netCDF-Java documentation."
151+
commandLine("docker", "run", "--rm", "-d",
152+
"--name", "netcdf-java-docs-server",
153+
"-e", "SRC_DIR=/netcdf-java/docs/src/site",
154+
"-v", "$rootDir:/netcdf-java",
155+
"-p", "4005:4005",
156+
dockerImage, "serve", "--livereload")
157+
standardOutput = new NullOutputStream()
158+
doLast {
159+
String msg = "NetCDF-Java documentation available at http://localhost:4005"
160+
String bannerBorder = new String(new char[msg.length() + 4]).replace("\0", "#");
161+
println()
162+
println(bannerBorder)
163+
println("# $msg #")
164+
println(bannerBorder)
165+
println()
166+
}
167+
}
168+
169+
tasks.register("stopServe", Exec) {
170+
group = "documentation"
171+
description = "Stop the local server used while live editing the netCDF-Java documentation."
172+
commandLine("docker", "stop", "netcdf-java-docs-server")
173+
delete("$projectDir/src/site/Gemfile")
174+
delete("$projectDir/src/site/Gemfile.lock")
175+
}
176+
118177
import edu.ucar.build.publishing.tasks.PublishToRawRepoTask
119178

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

135194
tasks.register('publishAsVersionedUserGuide', PublishToRawRepoTask) {
136195
description = 'Publish user guide (versioned) to Nexus under /major.minor/.'
137-
138-
publishSrc = buildJekyllSite.destinationDirectory.get()
196+
publishSrc = siteBuildDir.get().toString()
139197
destPath = "$project.docVersion/userguide/"
140198
dependsOn tasks.getByName('buildJekyllSite')
141199
}
142200

143201
tasks.register('publishAsCurrentUserGuide', PublishToRawRepoTask) {
144202
description = 'Publish the user guide to Nexus under /current/.'
145-
146-
publishSrc = buildJekyllSite.destinationDirectory.get()
203+
publishSrc = siteBuildDir.get().toString()
147204
destPath = 'current/userguide/'
148205
dependsOn tasks.getByName('buildJekyllSite')
149206
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
pipeline {
2+
agent { label 'main' }
3+
stages {
4+
stage('Build documentation') {
5+
steps {
6+
sh '''docker run --rm \
7+
-e SRC_DIR=/netcdf-java/docs/src/site \
8+
-e DOCS_UID=$(id -u) \
9+
-v .:/netcdf-java \
10+
-v ./docs/build/site:/site \
11+
docker.unidata.ucar.edu/unidata-jekyll-docs:0.0.4 build
12+
'''
13+
}
14+
}
15+
stage('Publish documentation') {
16+
agent {
17+
docker {
18+
image 'docker.unidata.ucar.edu/thredds-test-environment:latest'
19+
// Run the container on the node specified at the
20+
// top-level of the Pipeline, in the same workspace,
21+
// rather than on a new node entirely:
22+
reuseNode true
23+
}
24+
}
25+
steps {
26+
withCredentials([file(credentialsId: 'thredds_vault', variable: 'TV'), file(credentialsId: 'vault_pw', variable: 'AVP')]) {
27+
sh '''#!/bin/bash -l
28+
select-java temurin 11
29+
set +x
30+
./gradlew \
31+
-Pnexus.username=`get_pw NEXUS_USER` \
32+
-Pnexus.password=`get_pw NEXUS_PW` \
33+
-x :docs:buildJekyllSite \
34+
:docs:publishAsVersionedUserGuide
35+
'''
36+
}
37+
}
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)