Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.
47 changes: 47 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ########################################
# BUILDER IMAGE
# ########################################

FROM node:16.13.2-alpine3.14 as builder

WORKDIR /usr/src/build

RUN npm install -g pkg

# CREATE BINARY FOR OPENAPI
RUN npm install -g @redocly/openapi-cli
RUN pkg `which openapi` -o openapi

# CREATE BINARY FOR GH OPENAPI DOCS
COPY package.json package.json
COPY package-lock.json package-lock.json
COPY src src
COPY webpack.config.js webpack.config.js

RUN npm install
RUN npm run build
RUN pkg dist/bundle.js -o gh-openapi-docs

# ########################################
# FINAL IMAGE
# ########################################

FROM node:16.13.2-alpine3.14

WORKDIR /usr/local/bin

COPY --from=builder /usr/src/build/openapi openapi
COPY --from=builder /usr/src/build/gh-openapi-docs gh-openapi-docs

RUN npm install -g redoc-cli

RUN apk add git

WORKDIR /docs

RUN which openapi
RUN which redoc-cli
RUN which gh-openapi-docs
RUN ls -la /usr/local/lib/node_modules/redoc-cli/node_modules/redoc/bundles/redoc.standalone.js

ENTRYPOINT [ "gh-openapi-docs" ]
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
VERSION := $(shell cat package.json | grep version | rev | cut -f 1 -d ' ' | rev | tr -d '"' | tr -d ',')

Nothing:
@echo "No target provided. Stop."

.PHONY: docker-build
docker-build:
@docker build -t ga4gh/gh-openapi-docs:${VERSION} .

.PHONY: docker-publish
docker-publish:
@docker push ga4gh/gh-openapi-docs:${VERSION}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@ga4gh/gh-openapi-docs",
"description": "Build ReDoc API documentation for an OpenAPI specification and host on GitHub Pages",
"author": "James Eddy <[email protected]>",
"version": "0.2.2-rc3",
"version": "0.2.3-rc1",
"license": "Apache-2.0",
"repository": "github:ga4gh/gh-openapi-docs",
"main": "./src/lib/index.js",
Expand Down
8 changes: 4 additions & 4 deletions src/lib/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ const bundleSpec = async buildPage => {
'text': `${config.branchPath}/\n`
});
shell.exec(
`npx openapi bundle -f --output ${openApiJsonPath} ${specPath}`,
{silent: true}
`openapi bundle -f --output ${openApiJsonPath} ${specPath}`,
{silent: false}
);
shell.exec(
`npx openapi bundle -f --output ${openApiYamlPath} ${specPath}`,
{silent: true}
`openapi bundle -f --output ${openApiYamlPath} ${specPath}`,
{silent: false}
);
shell.rm('-rf', specDir);
};
Expand Down
1 change: 1 addition & 0 deletions src/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ program.version(pkg.version);
program
.option('-c --config <config>', `Path to local configuration options [default: ".spec-docs.json"]`, ".spec-docs.json")
.option('-d --dry-run [bool]', `Do not touch or write anything, but show the commands`, false)
.option('-o --output-dir <output_dir>', `Output directory containing built docs added to the current checkout of 'gh-pages'`, "publish")
.option('-v --verbose [bool]', `Verbose output`, false);
program.parse(process.argv)
let cliOpts = program.opts();
Expand Down
21 changes: 10 additions & 11 deletions src/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,24 @@ const localConfig = {
'yamlOutfile': 'openapi.yaml',
'jsonOutfile': 'openapi.json'
}
]
],
workingDir: process.cwd(), // process.env.PWD,
outputDir: cliOpts.outputDir || 'publish'
};

const constructBranchPath = (defaultBranch, currentBranch, root, branchPathBase) => {
if (currentBranch == defaultBranch) {
return root;
} else {
return path.join(root, branchPathBase, currentBranch.toLowerCase())
}
const constructBranchPath = (workingDir, outputDir, branchPathBase, currentBranch) => {
return path.join(workingDir, outputDir, branchPathBase, currentBranch.toLowerCase())
};

const deployConfig = {
branchPath: constructBranchPath(
localConfig.defaultBranch,
envConfig.branch,
envConfig.root,
localConfig.branchPathBase
localConfig.workingDir,
localConfig.outputDir,
localConfig.branchPathBase,
envConfig.branch
)
};

// Export the config object based on the NODE_ENV
// ==============================================
const config = merge(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import getRepoInfo from 'git-repo-info';
/*eslint no-process-env:0*/

var repoInfo = getRepoInfo();
repoInfo.branch = repoInfo.branch || process.env.TRAVIS_BRANCH || "undefined";
repoInfo.branch = repoInfo.branch || process.env.GITHUB_HEAD_REF || process.env.TRAVIS_BRANCH || "undefined";

const env = process.env.NODE_ENV;
const repoOrigin = origin.sync();
Expand Down
15 changes: 4 additions & 11 deletions src/lib/gh-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,15 @@ import fs from 'fs';
const log = new Log();

const fetchPages = () => {
shell.rm('-rf', '.ghpages-tmp');
shell.mkdir('-p', '.ghpages-tmp');
shell.rm('-rf', config.outputDir);
shell.mkdir('-p', config.outputDir);
var startDir = shell.pwd();
shell.cd('.ghpages-tmp');
log.log(`\nCloning 'gh-pages' branch into '${shell.pwd().stdout}'`);
shell.cd(config.outputDir);
log.log(`\nCloning 'gh-pages' branch into '${config.outputDir}'`);
shell.exec(
`git clone --depth=1 --branch=gh-pages ${config.repoOrigin} .`,
{silent: true}
);
shell.cp('-Rn', config.branchPathBase, config.root);
if (fs.existsSync(config.docsRoot)) {
shell.cp('-Rn', config.docsRoot, config.root);
shell.cp('-Rn', 'openapi.*', config.root);
}
shell.cd(startDir);
shell.rm('-rf', '.ghpages-tmp')
};

export { fetchPages };
4 changes: 2 additions & 2 deletions src/lib/redoc-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const setupUI = buildPage => {
});

shell.exec(
`npx redoc-cli bundle --output ${indexPath} ${openApiYamlPath} ${redocOpts}`,
{silent: true}
`redoc-cli bundle --output ${indexPath} ${openApiYamlPath} ${redocOpts}`,
{silent: false}
);
};

Expand Down