Skip to content

Commit

Permalink
Merge pull request #186 from phovea/release-1.1.0
Browse files Browse the repository at this point in the history
Release 1.1.0
  • Loading branch information
Christian Lehner authored Oct 1, 2019
2 parents a192b93 + 6808120 commit 5b58455
Show file tree
Hide file tree
Showing 17 changed files with 542 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jobs:
build:
working_directory: ~/phovea
docker:
- image: circleci/node:6-browsers
- image: circleci/node:8-browsers
tags:
- /v\d+.\d+.\d+.*/
steps:
Expand Down
1 change: 1 addition & 0 deletions generators/_init-python/templates/plain/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def to_version(v):
url=pkg['homepage'],
description=pkg['description'],
long_description=read_it('README.md'),
long_description_content_type='text/markdown',
keywords=pkg.get('keywords', ''),
author=pkg['author']['name'],
author_email=pkg['author']['email'],
Expand Down
4 changes: 2 additions & 2 deletions generators/_init-web/templates/package.tmpl.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"build"
],
"engines": {
"npm": ">= 3",
"node": ">= 6"
"npm": ">= 6.4",
"node": ">= 8.16"
},
"scripts": {
"compile": "tsc",
Expand Down
2 changes: 1 addition & 1 deletion generators/_init-web/templates/plain/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jobs:
build:
working_directory: ~/phovea
docker:
- image: circleci/node:6-browsers
- image: circleci/node:8-browsers
tags:
- /v\d+.\d+.\d+.*/
steps:
Expand Down
2 changes: 1 addition & 1 deletion generators/_init-web/templates/plain/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: circleci/node:6-browsers
image: circleci/node:8-browsers

variables:
GIT_DEPTH: "1"
Expand Down
175 changes: 175 additions & 0 deletions generators/clone-repo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
'use strict';
const Base = require('yeoman-generator').Base;
const chalk = require('chalk');
const {
simplifyRepoUrl
} = require('../../utils/repo');
const version = require('../../utils/version');

function failed(spawnResult) {
return spawnResult.status !== 0;
}

/**
* Clone a given repository and supports version ranges for git tags.
* @see https://docs.npmjs.com/misc/semver#advanced-range-syntax
*/
class Generator extends Base {

constructor(args, options) {
super(args, options);

this.argument('repository', {
alias: 'r',
defaults: '',
type: String,
required: true
});

// Note for Windows Powershell
// Using caret version range like `-b '^v2.0.0'` does not work!
// Instead you must escape the caret sign as explained in
// https://stackoverflow.com/a/5254713/940219
// Correct version: `-b '^^^^v2.0.0'`
this.option('branch', {
alias: 'b',
defaults: 'master',
required: false,
type: String
});

// Note for Windows Powershell
// Using `-e '--depth 1'` does not work!
// Instead add an additional space at the beginning
// to the argument value: `-e ' --depth 1'`
this.option('extras', {
alias: 'e',
defaults: '',
type: String
});

// no prompt implemented
this.option('cwd', {
defaults: '',
type: String
});

// no prompt implemented
this.option('dir', {
alias: 'd',
defaults: '',
type: String
});
}

prompting() {
return this.prompt([{
type: 'input',
name: 'repository',
message: 'Repository URL',
required: true,
default: this.args.length > 0 ? this.args[0] : undefined,
when: this.args.length === 0,
validate: (d) => d.length > 0
}, {
type: 'input',
name: 'branch',
message: 'Git branch or tag',
required: true,
default: this.options.branch,
when: this.options.branch === '',
validate: (d) => d.length > 0
}, {
type: 'input',
name: 'extras',
message: 'Additional git clone parameters',
required: false,
default: this.options.extras || undefined,
when: this.options.extras === undefined
}]).then((props) => {
this.cwd = this.options.cwd || undefined;
this.cloneDirName = (this.options.dir === '') ? this.options.dir : ` ${this.options.dir}`; // add space at the beginning
this.options.repository = props.repository || this.args[0];
this.options.branch = props.branch || this.options.branch;
this.options.extras = props.extras || this.options.extras;
this.options.extras = (this.options.extras === '') ? this.options.extras : ` ${this.options.extras}`; // add space at the beginning
});
}

writing() {
return this._cloneRepo(this.options.repository, this.options.branch, this.options.extras, this.cloneDirName);
}

_cloneRepo(repoUrl, branch, extras, cloneDirName) {
if (!version.isGitCommit(branch)) {
// modify branch name, if it is an advance version tag
// otherwise just use the branch name as it is
if (version.isAdvancedVersionTag(branch)) {
this.log(chalk.white(`found branch with version range`), chalk.green(branch), chalk.white(`for`), chalk.green(repoUrl));

const line = `ls-remote --tags ${repoUrl}`;
this.log(chalk.white(`fetching possible version tags:`), `git ${line}`);
const r = this._spawn('git', line.split(/ +/));

if (failed(r)) {
this.log(chalk.red(`failed to fetch list of tags from git repository`), `status code: ${r.status}`);
this.log(r.stderr.toString());
return this._abort(`failed to fetch list of tags from git repository - status code: ${r.status}`);
}

const gitLog = r.stdout.toString();
const gitVersions = version.extractVersionsFromGitLog(gitLog);
this.log(chalk.white(`found the following version tags: `), gitVersions);

const highestVersion = version.findHighestVersion(gitVersions, branch);
if (!highestVersion) {
this.log(chalk.red(`failed to find git version tag for given version range`));
return this._abort(`failed to find git version tag for given version range`);
}

this.log(chalk.white(`use version tag`), chalk.green(highestVersion), chalk.white(`as branch name`));
branch = highestVersion;
}

const line = `clone -b ${branch}${extras || ''} ${repoUrl}${cloneDirName}`;
this.log(chalk.white(`clone repository:`), `git ${line}`);
return this._spawnOrAbort('git', line.split(/ +/));
}
// clone a specific commit
const line = `clone ${extras || ''} ${repoUrl}${cloneDirName}`;
this.log(chalk.white(`clone repository:`), `git ${line}`);
return this._spawnOrAbort('git', line.split(/ +/)).then(() => {
const line = `checkout ${branch}`;
this.log(chalk.white(`checkout commit:`), `git ${line}`);
let repoName = simplifyRepoUrl(repoUrl);
repoName = repoName.slice(repoName.lastIndexOf('/') + 1);
return this._spawnOrAbort('git', line.split(/ +/), {
cwd: `${this.cwd}/${repoName}`
});
});
}

_abort(msg) {
return Promise.reject(msg ? msg : 'Step Failed: Aborting');
}

_spawn(cmd, argline, cwd) {
const options = cwd === false ? {} : Object.assign({
cwd: this.cwd,
stdio: ['inherit', 'pipe', 'pipe'] // pipe `stdout` and `stderr` to host process
}, cwd || {});
return this.spawnCommandSync(cmd, Array.isArray(argline) ? argline : argline.split(' '), options);
}

_spawnOrAbort(cmd, argline, cwd) {
const r = this._spawn(cmd, argline, cwd);
if (failed(r)) {
this.log(r.stderr.toString());
return this._abort(`failed: "${cmd} ${Array.isArray(argline) ? argline.join(' ') : argline}" - status code: ${r.status}`);
}
return Promise.resolve(r);
}

}

module.exports = Generator;
2 changes: 1 addition & 1 deletion generators/init-app/templates/processed/deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM nginx:alpine

MAINTAINER Samuel Gratzl <[email protected]>
LABEL maintainer="[email protected]"

ENV PHOVEA_API_SERVER=api
ENV PHOVEA_NGINX_PORT=80
Expand Down
34 changes: 12 additions & 22 deletions generators/init-product/templates/plain/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,19 @@ function createQuietTerminalAdapter() {
* runs yo internally
* @param generator
* @param options
* @param cwd
* @param {string} cwd
* @param {string[]|string} args
*/
function yo(generator, options, cwd) {
function yo(generator, options, cwd, args) {
const yeoman = require('yeoman-environment');
// call yo internally
const yeomanEnv = yeoman.createEnv([], {cwd, env}, quiet ? createQuietTerminalAdapter() : undefined);
yeomanEnv.register(require.resolve('generator-phovea/generators/' + generator), 'phovea:' + generator);
const _args = Array.isArray(args) ? args.join(' ') : args || '';
return new Promise((resolve, reject) => {
try {
console.log(cwd, chalk.blue('running yo phovea:' + generator));
yeomanEnv.run('phovea:' + generator, options, resolve);
yeomanEnv.run(`phovea:${generator} ${_args}`, options, resolve);
} catch (e) {
console.error('error', e, e.stack);
reject(e);
Expand All @@ -310,28 +312,16 @@ function yo(generator, options, cwd) {

function cloneRepo(p, cwd) {
// either of them has to be defined
p.name = p.name || (p.repo ? fromRepoUrl(p.repo) : '');
p.name = p.name || fromRepoUrl(p.repo);
p.repo = p.repo || `phovea/${p.name}`;
p.branch = p.branch || 'master';

if (p.symlink && fs.existsSync(p.symlink)) {
console.log(cwd, chalk.yellow(`symlink ${path.resolve(p.symlink)} -> ${cwd}/${p.name}`));
// use a symlink instead
// see https://nodejs.org/api/fs.html#fs_fs_symlinksync_target_path_type
return fs.ensureSymlinkAsync(path.resolve(p.symlink), `${cwd}/${p.name}`, 'junction'); // for windows
}

if (/^[0-9a-f]+$/gi.test(p.branch)) {
// clone a specific commit
console.log(cwd, chalk.blue(`running git clone -n ${toRepoUrl(p.repo)} ${p.name}`));
return spawn('git', ['clone', '-n', toRepoUrlWithUser(p.repo), p.name], {cwd}).then(() => {
console.log(cwd, chalk.blue(`running git checkout ${p.branch}`));
return spawn('git', ['checkout', p.branch], {cwd: cwd + '/' + p.name});
});
}

console.log(cwd, chalk.blue(`running git clone --depth 1 -b ${p.branch} ${toRepoUrl(p.repo)} ${p.name}`));
return spawn('git', ['clone', '--depth', '1', '-b', p.branch, toRepoUrlWithUser(p.repo), p.name], {cwd});
return yo('clone-repo', {
branch: p.branch,
extras: '--depth 1',
dir: p.name,
cwd
}, cwd, toRepoUrlWithUser(p.repo)); // pass repo url as argument
}

function resolvePluginType(p, dir) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM caleydo/phovea_python:v1.1

MAINTAINER Samuel Gratzl <[email protected]>
LABEL maintainer="[email protected]"
WORKDIR /phovea
RUN printf "from phovea_server import launch\nlaunch.run()\n" > /phovea/launch.py

# install dependencies last step such that everything before can be cached
COPY requirements*.txt docker_packages.txt docker_script*.sh ./
RUN (!(test -s docker_packages.txt) || (apt-get update && \
(cat docker_packages.txt | xargs apt-get install -y))) && \
(pip install --no-cache-dir -r requirements.txt)
(cat docker_packages.txt | xargs apt-get install -y))) && \
(pip install --no-cache-dir -r requirements.txt)
RUN (!(test -f docker_script.sh) || (bash ./docker_script.sh))

COPY ./build/source ./
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM caleydo/phovea_python:v1.1-dev

MAINTAINER Samuel Gratzl <[email protected]>
LABEL maintainer="[email protected]"
WORKDIR /phovea

# install dependencies last step such that everything before can be cached
Expand Down
Loading

0 comments on commit 5b58455

Please sign in to comment.