Skip to content

Commit 2cef15d

Browse files
committed
Deployment update
1 parent 2e9ff7d commit 2cef15d

5 files changed

Lines changed: 128 additions & 70 deletions

File tree

.drone.star

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,23 @@ def build(ctx, environment, latest_version, deployment_branch, base_branch, pdf_
8686
{
8787
"name": "docs-deps",
8888
"pull": "always",
89-
"image": "owncloudci/nodejs:14",
89+
"image": "owncloudci/nodejs:16",
9090
"commands": [
9191
"yarn install",
9292
],
9393
},
9494
{
9595
"name": "docs-validate",
9696
"pull": "always",
97-
"image": "owncloudci/nodejs:14",
97+
"image": "owncloudci/nodejs:16",
9898
"commands": [
9999
"yarn validate --fetch",
100100
],
101101
},
102102
{
103103
"name": "docs-build",
104104
"pull": "always",
105-
"image": "owncloudci/nodejs:14",
105+
"image": "owncloudci/nodejs:16",
106106
"commands": [
107107
"yarn antora --fetch --attribute format=html",
108108
],

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"printWidth": 99,
3+
"singleQuote": true,
4+
"semi": false,
5+
"trailingComma": "none"
6+
}

generator/generate-site.js

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const _ = require('lodash')
44
const cheerio = require('cheerio')
55
const Entities = require('html-entities')
6-
const Elasticsearch = require('elasticsearch')
6+
const { Client } = require('@elastic/elasticsearch')
77

88
const aggregateContent = require('@antora/content-aggregator')
99
const buildNavigation = require('@antora/navigation-builder')
@@ -17,11 +17,13 @@ const produceRedirects = require('@antora/redirect-producer')
1717
const publishSite = require('@antora/site-publisher')
1818
const { resolveConfig: resolveAsciiDocConfig } = require('@antora/asciidoc-loader')
1919

20-
async function generateSite (args, env) {
20+
async function generateSite(args, env) {
2121
const playbook = buildPlaybook(args, env)
2222
const [contentCatalog, uiCatalog] = await Promise.all([
23-
aggregateContent(playbook).then((contentAggregate) => classifyContent(playbook, enforceEditurl(contentAggregate))),
24-
loadUi(playbook),
23+
aggregateContent(playbook).then((contentAggregate) =>
24+
classifyContent(playbook, enforceEditurl(contentAggregate))
25+
),
26+
loadUi(playbook)
2527
])
2628
const asciidocConfig = resolveAsciiDocConfig(playbook)
2729
const pages = convertDocuments(contentCatalog, asciidocConfig)
@@ -35,7 +37,7 @@ async function generateSite (args, env) {
3537
return publishSite(playbook, [contentCatalog, uiCatalog, siteCatalog])
3638
}
3739

38-
async function generateIndex (playbook, pages) {
40+
async function generateIndex(playbook, pages) {
3941
if ((process.env.BUILD_SEARCH_INDEX || 'true') !== 'true') {
4042
console.log('elastic: search index generation skipped')
4143
return
@@ -67,7 +69,7 @@ async function generateIndex (playbook, pages) {
6769
})
6870

6971
let text = Entities.decode($('article').text())
70-
.replace(/(<([^>]+)>)/ig, '')
72+
.replace(/(<([^>]+)>)/gi, '')
7173
.replace(/\n/g, ' ')
7274
.replace(/\r/g, ' ')
7375
.replace(/\s+/g, ' ')
@@ -84,13 +86,18 @@ async function generateIndex (playbook, pages) {
8486
}
8587
})
8688

87-
if (process.env.UPDATE_SEARCH_INDEX == 'true' && process.env.ELASTICSEARCH_HOST && process.env.ELASTICSEARCH_INDEX) {
89+
if (
90+
process.env.UPDATE_SEARCH_INDEX == 'true' &&
91+
process.env.ELASTICSEARCH_NODE &&
92+
process.env.ELASTICSEARCH_INDEX &&
93+
process.env.ELASTICSEARCH_WRITE_AUTH
94+
) {
8895
console.log('elastic: rebuild search index')
8996
let result = []
9097

9198
documents.forEach((document, index) => {
9299
result.push({
93-
index: {
100+
index: {
94101
_index: process.env.ELASTICSEARCH_INDEX,
95102
_type: 'page',
96103
_id: index
@@ -100,35 +107,36 @@ async function generateIndex (playbook, pages) {
100107
result.push(document)
101108
})
102109

103-
const client = new Elasticsearch.Client({
104-
host: [{
105-
host: process.env.ELASTICSEARCH_HOST,
106-
port: process.env.ELASTICSEARCH_PORT || 443,
107-
protocol: process.env.ELASTICSEARCH_PROTOCOL || 'https',
108-
auth: process.env.ELASTICSEARCH_WRITE_AUTH,
109-
}]
110+
const client = new Client({
111+
node: process.env.ELASTICSEARCH_NODE,
112+
auth: {
113+
username: process.env.ELASTICSEARCH_WRITE_AUTH.split(':')[0],
114+
password: process.env.ELASTICSEARCH_WRITE_AUTH.split(':')[1]
115+
}
110116
})
111117

112118
try {
113-
console.log("elastic: remove old search index");
119+
console.log('elastic: remove old search index')
114120
await indexDelete(client)
115-
console.log("elastic: create empty search index");
121+
console.log('elastic: create empty search index')
116122
await indexCreate(client)
117123
console.log('elastic: upload search index')
118124
await indexBulk(client, result)
119125
} catch (err) {
120-
console.log("elastic: ERROR: " + err.status + " - " + err.displayName);
121-
process.exit(1);
126+
const errObj = JSON.parse(err)
127+
console.log('elastic: ERROR: ' + errObj.status + ' - ' + errObj.error.reason)
128+
process.exit(1)
122129
}
123130
}
124131
}
125132

126-
function enforceEditurl (contentAggregate) {
133+
function enforceEditurl(contentAggregate) {
127134
_.map(contentAggregate, (source) => {
128135
_.map(source.files, (file) => {
129136
if (_.startsWith(file.src.editUrl, 'file://')) {
130137
if (source.name === 'server') {
131-
file.src.editUrl = 'https://github.com/owncloud/docs/edit/' + source.version + '/' + file.src.path
138+
file.src.editUrl =
139+
'https://github.com/owncloud/docs/edit/' + source.version + '/' + file.src.path
132140
}
133141
}
134142

@@ -146,53 +154,54 @@ function indexDelete(client) {
146154
client.indices
147155
.delete({
148156
index: process.env.ELASTICSEARCH_INDEX,
149-
ignore_unavailable: true,
157+
ignore_unavailable: true
150158
})
151159
.then((resp) => {
152-
resolve(resp);
160+
resolve(resp)
153161
})
154162
.catch((err) => {
155-
reject(err);
156-
});
157-
});
163+
reject(err)
164+
})
165+
})
158166
}
159167

160168
function indexCreate(client) {
161169
return new Promise((resolve, reject) => {
162170
client.indices
163171
.create({
164-
index: process.env.ELASTICSEARCH_INDEX,
172+
index: process.env.ELASTICSEARCH_INDEX
165173
})
166174
.then((resp) => {
167-
resolve(resp);
175+
resolve(resp)
168176
})
169177
.catch((err) => {
170-
reject(err);
171-
});
172-
});
178+
reject(err)
179+
})
180+
})
173181
}
174182

175183
function indexBulk(client, result) {
176184
return new Promise((resolve, reject) => {
177-
client.bulk({
178-
body: result
179-
})
185+
client
186+
.bulk({
187+
body: result
188+
})
180189
.then((resp) => {
181-
resolve(resp);
190+
resolve(resp)
182191
})
183192
.catch((err) => {
184-
reject(err);
185-
});
186-
});
193+
reject(err)
194+
})
195+
})
187196
}
188197

189-
function create404Page () {
198+
function create404Page() {
190199
return {
191200
title: 'Page Not Found',
192201
mediaType: 'text/html',
193202
src: { stem: '404' },
194203
out: { path: '404.html' },
195-
pub: { url: '/404.html', rootPath: '' },
204+
pub: { url: '/404.html', rootPath: '' }
196205
}
197206
}
198207

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@
3535
"dependencies": {
3636
"@antora/cli": "^2.3",
3737
"@antora/site-generator-default": "^2.3",
38+
"@asciidoctor/core": "^2.2.5",
39+
"@elastic/elasticsearch": "^7.16.0",
3840
"asciidoctor-kroki": "^0.15.4",
3941
"cheerio": "^1.0.0-rc.10",
40-
"elasticsearch": "^16.7.2",
4142
"html-entities": "2.3.2",
4243
"lodash": "^4.17.21"
4344
},

0 commit comments

Comments
 (0)