Skip to content

Commit

Permalink
Feature/preinstall (#601)
Browse files Browse the repository at this point in the history
* Preinstall script

* Manually install global @angular/cli

* Optimize Travis

* Change timeout to more sane levels

* Move configuration to config

* Move openapi code generation to scripts

* Silent install

* Update README.md [skip ci]

* nvm version file

* Try using nvm version

* Update README.md [skip ci]

* What happens when you lint with broken imports

* Rename config variable

* Fix

* Use variable

* Comment [skip ci]

* Just removing it to avoid confusion
  • Loading branch information
garyluu authored Apr 12, 2019
1 parent c8ad19d commit 7bb6463
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 77 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v10.13.0
22 changes: 10 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
sudo: required
dist: trusty
language: node_js
node_js:
- '10.13.0'
services:
- postgresql
jdk:
Expand All @@ -12,41 +10,41 @@ cache:
directories:
# we also need to cache folder with Cypress binary
- ~/.cache
env:
global:
- WEBSERVICE_VERSION="1.6.0-beta.4"
addons:
firefox: "latest"
postgresql: "9.6"
chrome: stable

install:
- ./scripts/install-travis-script.sh
- npm ci

jobs:
include:
- stage: unit test
name: "Lint, Unit Test, and Prod Test"
script:
- ng lint
- ng test --watch=false --code-coverage --browsers ChromeHeadless
- ng version
- npx ng lint
- npm run build.prod
- npx ng test --watch=false --code-coverage --browsers ChromeHeadless
- npm install --no-save codecov
- stage: integration test
name: "Cypress Group 1"
env:
- TEST='cypress/integration/group1/**/*'
script: ./scripts/run-travis-script.sh
script:
- ./scripts/run-travis-script.sh
- stage: integration test
name: "Cypress Group 2"
env:
- TEST='cypress/integration/group2/**/*'
script: ./scripts/run-travis-script.sh
script:
- ./scripts/run-travis-script.sh
- stage: integration test
name: "Cypress Group 3"
env:
- TEST='cypress/integration/group3/**/*'
script: ./scripts/run-travis-script.sh
script:
- ./scripts/run-travis-script.sh

script: echo "overriding test"

Expand Down
45 changes: 18 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ This project was generated with [Angular CLI](https://github.com/angular/angular

### Prerequisites

Angular CLI requires Node and NPM. See [.travis.yml](.travis.yml) for the correct versions of Node, NPM and Angular CLI.
Then make sure Angular CLI has been properly set up.
- Java 8+
- Node and its included NPM (see [.nvmrc](.nvmrc) for the correct version of node to install)
- wget

[Install NPM and Node](https://nodejs.org/en/download/package-manager/)
Install NPM and Node using nvm:
```
$curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
$sudo apt-get install -y nodejs
$nodejs -v
v7.10.0
$npm -v
4.2.0
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
```
Follow https://docs.npmjs.com/getting-started/fixing-npm-permissions#option-two-change-npms-default-directory to fix permissions and then...
Close current terminal and open a new one or `source ~/.bashrc`
```
nvm install 10.13.0
```
Optionally, install a global Angular CLI in order to execute `ng` commands without prepending `npx`.
Otherwise, prepend `npx` to every command in this README if a global @angular/cli was not installed.
Before installing, follow https://docs.npmjs.com/getting-started/fixing-npm-permissions#option-two-change-npms-default-directory to fix permissions if needed.

```
$npm i -g @angular/[email protected]
Expand All @@ -55,7 +57,7 @@ cd dockstore-ui2
git checkout develop
git pull
npm ci
CI=true npm ci
```

Check to make sure Angular CLI has been properly set up
Expand Down Expand Up @@ -94,18 +96,6 @@ The Dockstore class in [src/app/shared/dockstore.model.ts](src/app/shared/dockst

In `dockstore-webservice`, the `dockstore.yml` being served <b>must be edited to include the client IDs</b>.

## Pre-build/serve
<!--
Possible bash command
export WEBSERVICE_VERSION=`grep -oP 'WEBSERVICE_VERSION="\K[0-9].[0-9].[0-9]' .travis.yml`
-->
Run `export WEBSERVICE_VERSION=`[dockstore release version](https://github.com/dockstore/dockstore-ui2/blob/develop/.travis.yml#L12), for example `export WEBSERVICE_VERSION=1.5.3`.

Run `npm run prebuild` before running or building the project. This command will:
- generate a file which contains the UI tag version
- download the openapi codegen
- generate code from the swagger.yaml

## Development server

Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. Run `ng serve --host 0.0.0.0` in order to serve your site to other computers on the same network.
Expand All @@ -121,7 +111,8 @@ Run `ng g component component-name` to generate a new component. You can also us

## Build

Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build.
Optionally override the webservice version using `npm config set dockstore-ui2:webservice_version ${WEBSERVICE_VERSION}
Run `npm run build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `npm run build.prod` for a production build.

## Running unit tests

Expand All @@ -131,9 +122,9 @@ Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.

Run `$(npm bin)/cypress open` or `$(npm bin)/cypress run` to execute the end-to-end tests via Cypress.io.
Before running the tests make sure you:
- have a postgresql database
- serve the app via `ng serve`.
- run the Dockstore webservice
- have a webservice jar in the root directory
- have the Dockstore webservice jar in the root directory and run it (see scripts/run-webservice-script.sh for guideline)

## Documentation Generation

Expand All @@ -143,7 +134,7 @@ To manually run it:
npm install -g @compodoc/compodoc
npm run compodoc
```
Then go to `docs/index.html`
Then open `docs/index.html` with browser

## Further help

Expand Down
2 changes: 1 addition & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function resetDB() {
before(() => {
cy.exec('PGPASSWORD=dockstore psql -h localhost -f scripts/resetDb.sql -U dockstore -d webservice_test');
cy.exec('PGPASSWORD=dockstore psql -h localhost -f travisci/db_dump.sql webservice_test -U dockstore');
cy.exec('java -jar dockstore-webservice-*.jar db migrate -i 1.5.0,1.6.0 travisci/web.yml');
cy.exec('java -jar dockstore-webservice.jar db migrate -i 1.5.0,1.6.0 travisci/web.yml');
});
}
export function setTokenUserViewPort() {
Expand Down
6 changes: 3 additions & 3 deletions git.version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ const tag$ = new Observable<string>(s => {
});

observableCombineLatest(revision$, tag$)
.subscribe(([revision, tag]) => {
console.log(`tag: '${tag}', version: '${process.env.WEBSERVICE_VERSION}', revision: '${revision}'`);
.subscribe(([revision, tag]) => {
console.log(`tag: '${tag}', version: '${process.env.npm_package_config_webservice_version}', revision: '${revision}'`);

const content = '// this file is automatically generated by git.version.ts script\n' +
`export const versions = {tag: '${tag}', version: '${process.env.WEBSERVICE_VERSION}', revision: '${revision}'};\n`;
`export const versions = {tag: '${tag}', version: '${process.env.npm_package_config_webservice_version}', revision: '${revision}'};\n`;

fs.writeFileSync(
'src/app/footer/versions.ts',
Expand Down
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
"name": "dockstore-ui2",
"version": "2.3.0",
"license": "Apache License 2.0",
"config": {
"webservice_version": "1.6.0"
},
"scripts": {
"ng": "ng",
"start": "ng serve",
"prebuild:tsnode": "ts-node git.version.ts",
"prebuild:downloadcodegen": "wget --no-verbose http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.3.4/openapi-generator-cli-3.3.4.jar -O openapi-generator-cli-3.3.4.jar",
"prebuild:generatecode": "rm -Rf src/app/shared/swagger && java -jar openapi-generator-cli-3.3.4.jar generate -i https://raw.githubusercontent.com/ga4gh/dockstore/${WEBSERVICE_VERSION}/dockstore-webservice/src/main/resources/swagger.yaml -l typescript-angular -o src/app/shared/swagger -c swagger-config.json",
"prebuild": "npm run prebuild:tsnode && npm run prebuild:downloadcodegen && npm run prebuild:generatecode",
"prebuild.prod": "npm run prebuild:tsnode && npm run prebuild:downloadcodegen && npm run prebuild:generatecode",
"build.prod": "ng build --progress false --prod",
"build": "ng build --progress false",
"ng": "npx ng",
"start": "npx ng serve --progress=false",
"webservice": "./scripts/run-webservice-script.sh",
"prebuild": "ts-node git.version.ts && ./scripts/generate-openapi-script.sh",
"prebuild.prod": "npm run prebuild",
"build.prod": "npx ng build --progress false --prod",
"build": "npx ng build --progress false",
"compodoc": "npx compodoc -p src/tsconfig.compodoc.json --output docs",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
"test": "npx ng test",
"lint": "npx ng lint",
"e2e": "npx ng e2e"
},
"private": true,
"dependencies": {
Expand Down
10 changes: 10 additions & 0 deletions scripts/generate-openapi-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
set -o xtrace

GENERATOR_VERSION="3.3.4"
wget --no-verbose http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/${GENERATOR_VERSION}/openapi-generator-cli-${GENERATOR_VERSION}.jar -O openapi-generator-cli.jar
rm -Rf src/app/shared/swagger
java -jar openapi-generator-cli.jar generate -i https://raw.githubusercontent.com/ga4gh/dockstore/$npm_package_config_webservice_version/dockstore-webservice/src/main/resources/swagger.yaml -l typescript-angular -o src/app/shared/swagger -c swagger-config.json
14 changes: 0 additions & 14 deletions scripts/install-travis-script.sh

This file was deleted.

10 changes: 2 additions & 8 deletions scripts/run-travis-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ set -o pipefail
set -o nounset
set -o xtrace

psql -c "create user dockstore with password 'dockstore' createdb;" -U postgres
psql -c "ALTER USER dockstore WITH superuser;" -U postgres
psql -c 'create database webservice_test with owner = dockstore;' -U postgres
psql -f travisci/db_dump.sql webservice_test
java -jar dockstore-webservice-${WEBSERVICE_VERSION}.jar db migrate -i 1.5.0,1.6.0 travisci/web.yml
java -jar dockstore-webservice-${WEBSERVICE_VERSION}.jar server travisci/web.yml 1>/dev/null &

npm run webservice
npm run build
ng serve --progress=false &
npm run start &
./scripts/wait-for.sh
cypress run --record --config defaultCommandTimeout=10000 --spec ${TEST}
15 changes: 15 additions & 0 deletions scripts/run-webservice-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
set -o xtrace

wget -O dockstore-webservice.jar --no-verbose --tries=10 https://artifacts.oicr.on.ca/artifactory/collab-release/io/dockstore/dockstore-webservice/${npm_package_config_webservice_version}/dockstore-webservice-${npm_package_config_webservice_version}.jar
chmod u+x dockstore-webservice.jar
psql -c "create user dockstore with password 'dockstore' createdb;" -U postgres
psql -c "ALTER USER dockstore WITH superuser;" -U postgres
psql -c 'create database webservice_test with owner = dockstore;' -U postgres
psql -f travisci/db_dump.sql webservice_test
java -jar dockstore-webservice.jar db migrate -i 1.5.0,1.6.0 travisci/web.yml
java -jar dockstore-webservice.jar server travisci/web.yml 1>/dev/null &

0 comments on commit 7bb6463

Please sign in to comment.