# Viewer

Note: It is recommended to run this package locally and deploy it live to production using the instructions in the root [README.md](../../README.md). The instructions below may be outdated.

## About

A tiled scene viewer using [openlayers](https://openlayers.org/) to display the following DL platform services:

* `tiles/v2/composite`
* `metadata/v1/scenes`

## Development

Install npm dependencies:

    $ npm install

Map the hostname `1337.descarteslabs.com` to your localhost. E.g., under Linux and OS X, add this line to your `/etc/hosts` file:

    127.0.0.1 1337.descarteslabs.com

Run a local dev server:

    $ npm run serve

You can now open the app locally at https://1337.descarteslabs.com

## Deployment

When you wish to deploy a new Viewer release, you have to do the following:

### Tag a new Viewer release.

#### 1. Get master to a state that's ready for a release.

The two primary tasks you should complete are:

* Merge any PRs that contain changes that you want to be included.

* Thoroughly test the [master branch deployment](https://viewer.descarteslabs.com/master).

#### 2. Bump the version in a new branch.

Create a `feat/bump-version` branch.  `feat/version-bump` is also fine. :)

There are three version bump options, in accordance with [semver](https://semver.org/):

* If the change is a patch, run:
```
    $ npm version patch
```

* If the change entails a minor release, run:
```
    $ npm version minor
```

* If the change entails a major release, run:
```
    $ npm version major
```

This `npm version <patch|minor|major>` command will both bump the patch/minor/major version number in package.json and will create  
the corresponding git tag.  See the [documentation](https://docs.npmjs.com/cli/version) for details.

#### 3. Push this branch and open a PR.

The review process for this PR should be pretty short.

#### 4. Publish a release in GitHub.  

Make sure to summarize all changes since the last tagged release in the release notes.

#### 5. Verify that tagged release deployment functions as expected.

You can verify that the tagged release operates as expected at https://viewer.descarteslabs.com/<viewer_version_tag>,
where <viwer_version_tag> is the git tag for this release.  Note that the bundle from the tagged release build has to be
pushed to GCS before this can be viewed.

### Update the `APP_VERSION` environment variable in the [Viewer k8s deployment manifest](https://github.com/descarteslabs/monorepo/blob/master/descarteslabs/services/apps/viewer/k8s/deployment.yaml).

#### 1. In a new branch, set the `APP_VERSION` environment variable to `<viewer_version_tag>` in the [Viewer k8s deployment manifest](https://github.com/descarteslabs/monorepo/blob/master/descarteslabs/services/apps/viewer/k8s/deployment.yaml).  

Create a `viewer/deploy/<viewer_version_tag>` branch, where `<viewer_version_tag>` is the new Viewer version tag.

This will change the default route of the Flask application to point to the JavaScript bundle associated with this  
tagged release.

#### 2. (Optional) Update the image.

If changes have been made to the Flask app that you wish to release, you'll also have to update the image in the [manifest](https://github.com/descarteslabs/monorepo/blob/master/descarteslabs/services/apps/viewer/k8s/deployment.yaml).

#### 3. Push this branch and open a PR.

The review process for this PR should be pretty short.  Upon merging the PR, the Spinnaker pipeline will start executing.

#### 4. Monitor the Spinnaker pipeline execution.

Pipeline execution can be monitored [here](https://spinnaker.descarteslabs.com/#/applications/viewer/executions).

#### 5. Manually verify the platform-lab Viewer deployment.

The pipeline will require manual verification of the platform-lab deployment before deploying to production.  
Confirm that the Viewer deployment is correct and proceed.

#### 6. Check production deployment.
   
You should be able to see the updated deployment [here](https://viewer.descarteslabs.com).  You may need to do a hard
refresh to see the changes.  Confirm that the desired version is deployed by checking the newly tagged release against
the version number in the "Help" section of Viewer. 
