Skip to content

Commit

Permalink
Merge pull request #320 from input-output-hk/docs-update
Browse files Browse the repository at this point in the history
Bump `cardano-graphql` dep to `1.0.0`,
  • Loading branch information
rhyslbw committed Jul 8, 2020
2 parents a9b722a + 3c52091 commit 70027f1
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 95 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -2,4 +2,4 @@ Changelog
=========

## 1.0.0
First release
First production-ready release.
41 changes: 28 additions & 13 deletions README.md
Expand Up @@ -5,14 +5,41 @@ Cardano Explorer App

A React app with GraphQL client interfacing with [Cardano GraphQL](https://github.com/input-output-hk/cardano-graphql).

### Environment Variables
See [environment](source/environment.ts) for defaults.
- `CARDANO_ERA`
- `CARDANO_NETWORK`
- `GRAPHQL_API_PROTOCOL`
- `GRAPHQL_API_HOST`
- `GRAPHQL_API_PORT`
- `GRAPHQL_API_PATH`
- `REAL_TIME_FACTOR`
- `GA_TRACKING_ID`
- `DEBUG`

## Build
```console
yarn && yarn static:build
```
## Deploy
The static bundle can be deployed using a standard web server. A simple [Node.js program](deploy/index.js)
is available for deploying the build to an AWS S3 bucket.

```console
AWS_ACCESS_KEY_ID=your_access_key_id \
AWS_SECRET_ACCESS_KEY=your_secret_access_key node \
./deploy/example_deployment.js
```

## Development
The environment is configured to access a remote managed deployment of the API,
however you can run a local stack using Docker and use a `.env` to work offline.
See [.env.example](.env.example)

### `yarn dev`
- Starts the development version of the app by default at http://localhost:4000
- Generates graphql typings from the referenced schema in `cardano-graphql-ts` and documents within the codebase.
- Generates graphql typings from the referenced schema in [`@cardano-graphql/client-ts`](https://github.com/input-output-hk/cardano-graphql/tree/master/packages/client-ts)
and documents within the codebase.
- Any changes to graphql documents will trigger the TypeScript generator.

### Storybook
Expand All @@ -28,15 +55,3 @@ The `develop` and PR branches are deployed continuously for the purpose of testi
#### Testnet
[![Netlify Status](https://api.netlify.com/api/v1/badges/16628b5d-b1f2-429b-a707-bbdec0564fe9/deploy-status)](https://cardano-explorer-testnet.netlify.app)

## Deployment
A simple [Node.js program](deploy/index.js) is available for deploying to an AWS S3 bucket.

### ENVs
\* optional
#### `CARDANO_ERA`: `byron | shelley`
#### `CARDANO_NETWORK`: `mainnet | testnet`
#### `GRAPHQL_API_PROTOCOL` : `https | http`
#### `GRAPHQL_API_HOST`
#### `GRAPHQL_API_PORT`
#### * `GA_TRACKING_ID`
https://support.google.com/analytics/answer/7372977?hl=en
12 changes: 0 additions & 12 deletions deploy/byron_testnet.js

This file was deleted.

7 changes: 3 additions & 4 deletions deploy/byron_mainnet.js → deploy/example_deployment.js
Expand Up @@ -3,10 +3,9 @@ const deploy = require('./index');
process.env.CARDANO_ERA = 'byron';
process.env.CARDANO_NETWORK = 'mainnet';
process.env.GRAPHQL_API_PROTOCOL = 'https';
process.env.GRAPHQL_API_HOST = 'cardano-graphql-mainnet.daedalus-operations.com';
process.env.GRAPHQL_API_HOST = 'a-cardano-graphql-deployment.com';
process.env.GRAPHQL_API_PORT = '443';

const branch = process.env.BRANCH || 'develop';
process.env.BUCKET = `byron-mainnet-${branch}-explorer`;
process.env.BUCKET = 'byron-mainnet-explorer';
process.env.AWS_DEFAULT_REGION = 'ap-southeast-2';

deploy();
49 changes: 25 additions & 24 deletions deploy/index.js
@@ -1,41 +1,42 @@
const { spawn } = require('child_process');
const upload = require('./upload');
const fs = require('fs');
const AWS = require('aws-sdk');
const readdir = require('recursive-readdir');
const mime = require('mime-types');

module.exports = async function deploy() {
const requiredEnvs = [
'CARDANO_ERA',
'CARDANO_NETWORK',
'GRAPHQL_API_PROTOCOL',
'GRAPHQL_API_HOST',
'GRAPHQL_API_PORT'
'AWS_ACCESS_KEY_ID',
'AWS_SECRET_ACCESS_KEY',
'AWS_DEFAULT_REGION',
'BUCKET'
];

requiredEnvs.forEach(env => {
const val = process.env[env];
if (!val) {
throw new Error(`Missing ${env} from the environment`);
}

console.log(`${env} = ${val}`);
});

const builder = spawn(`yarn`, ['static:build'], {
stdio: ['inherit', 'inherit', 'inherit'],
env: {
PATH: process.env.PATH,
...process.env
}
});
const targetBucket = process.env.BUCKET

await new Promise((resolve, reject) => {
builder.on('close', (code) => {
if (code !== 0) {
reject(new Error('Compilation failed'));
}
const uploadFolder = './build/static';
const s3 = new AWS.S3();

resolve();
})
});
const filesToUpload = await readdir(uploadFolder);

console.log(`Uploading to S3 bucket: ${targetBucket}`);

return filesToUpload.map(async (file) => {
const key = file.replace('build/static/', '');
const fileBuffer = fs.readFileSync(file);

await upload();
return s3.upload({
Key: key,
Bucket: targetBucket,
Body: fileBuffer,
ContentType: mime.lookup(key) || 'application/octet-stream'
}).promise();
})
};
36 changes: 0 additions & 36 deletions deploy/upload.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -32,7 +32,7 @@
}
},
"dependencies": {
"@cardano-graphql/client-ts": "^1.0.0-rc.13",
"@cardano-graphql/client-ts": "1.0.0",
"@types/react-addons-css-transition-group": "15.0.5",
"browser-update": "3.3.9",
"cardano-js": "0.3.0",
Expand Down
1 change: 1 addition & 0 deletions source/environment.ts
Expand Up @@ -18,6 +18,7 @@ export const environment = {
(process.env.CARDANO_NETWORK as CardanoNetwork) || CardanoNetwork.MAINNET,
},
DEBUG: process.env.DEBUG,
// https://support.google.com/analytics/answer/7372977?hl=en
GA_TRACKING_ID: process.env.GA_TRACKING_ID,
IS_CLIENT: isNavigatorDefined,
IS_SERVER: !isNavigatorDefined,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -1438,10 +1438,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@cardano-graphql/client-ts@^1.0.0-rc.13":
version "1.0.0-rc.13"
resolved "https://registry.yarnpkg.com/@cardano-graphql/client-ts/-/client-ts-1.0.0-rc.13.tgz#bf3bafc9b9b314a5c389dbbce6261ed09abbf91c"
integrity sha512-FEqNpUV7AzchsM4WooyEb9nNrgcDariLJiM+JXV/WyoLa4WKb6md1IttKuub+XrHixRcB7ZwmaFm+nhUV2kmcg==
"@cardano-graphql/client-ts@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@cardano-graphql/client-ts/-/client-ts-1.0.0.tgz#816d79006e33c715cf0a2e42a67e53e01ad17890"
integrity sha512-xCQMBHBDq6IGVSSaSs2tOpDKEVOWDdOb6qlmNKi8BOHO9BqWkiw5diy8faUCDj+10aAzdSbdCnId2N/TfTbyKg==

"@cnakazawa/watch@^1.0.3":
version "1.0.4"
Expand Down

0 comments on commit 70027f1

Please sign in to comment.