Skip to content

Commit

Permalink
Generate secret.ts dynamically from environment variables before build.
Browse files Browse the repository at this point in the history
Fix #148.
  • Loading branch information
seanwu1105 committed Nov 3, 2020
1 parent c6474f5 commit d7a019d
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
coverage-reports: ./coverage/cobertura-coverage.xml

- name: Build Ionic
run: ionic build
run: npm run build

- name: Build Android
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: npm install

- name: Build Ionic
run: ionic build -- --base-href=/capture-lite/
run: npm run build -- --base-href=/capture-lite/

- name: Deploy
uses: JamesIves/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
npm install -g @angular/cli
npm install -g @ionic/cli
npm install
ionic build
npm run build
npx cap sync
cd android/
./gradlew assembleDebug
Expand Down
23 changes: 8 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@
| master | [![build](https://github.com/numbersprotocol/capture-lite/workflows/build/badge.svg)](https://github.com/numbersprotocol/capture-lite/actions?query=workflow%3Abuild) | [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/45ae18aaa6a7474497e0efd818452a46)](https://www.codacy.com/gh/numbersprotocol/capture-lite?utm_source=github.com&utm_medium=referral&utm_content=numbersprotocol/capture-lite&utm_campaign=Badge_Coverage) | [![Codacy Badge](https://app.codacy.com/project/badge/Grade/45ae18aaa6a7474497e0efd818452a46)](https://www.codacy.com/gh/numbersprotocol/capture-lite?utm_source=github.com&utm_medium=referral&utm_content=numbersprotocol/capture-lite&utm_campaign=Badge_Grade) |
| develop | [![build](https://github.com/numbersprotocol/capture-lite/workflows/build/badge.svg?branch=develop)](https://github.com/numbersprotocol/capture-lite/actions?query=workflow%3Abuild) | [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/45ae18aaa6a7474497e0efd818452a46?branch=develop)](https://www.codacy.com/gh/numbersprotocol/capture-lite?utm_source=github.com&utm_medium=referral&utm_content=numbersprotocol/capture-lite&utm_campaign=Badge_Coverage) | [![Codacy Badge](https://app.codacy.com/project/badge/Grade/45ae18aaa6a7474497e0efd818452a46?branch=develop)](https://www.codacy.com/gh/numbersprotocol/capture-lite?utm_source=github.com&utm_medium=referral&utm_content=numbersprotocol/capture-lite&utm_campaign=Badge_Grade)

## Internal Branch

__This is an internal branch which cannot be built without further configurations.__

### Ignore Secrets in Git

1. Create an empty `secret.ts` file with empty variables (e.g. empty string).
1. Push the empty secret file to remote repo so the CI can still build the project.
1. Make git ignore the modification of the secret file locally with the command `git update-index --skip-worktree <secret file path>`.
1. Now, you can modify the secret file without the fear of pushing it to the public repo.

> You don't even need to add the secret file to `.gitignore`.
## Highlight Features

* Generate digital proofs on media assets created.
Expand All @@ -39,10 +26,16 @@ Install the dependencies.
npm i
```

Set the system environment variable `NUMBERS_STORAGE_BASE_URL` before build the app by appending the following string in `~/.profile`:

``` txt
export NUMBERS_STORAGE_BASE_URL="THE PRIVATE BASE URL"
```

Preview the app in web browser.

``` bash
ionic serve
npm run serve
```

### Verification
Expand Down Expand Up @@ -101,7 +94,7 @@ If your operating system is Linux, set the `linuxAndroidStudioPath` in `capacito
Before running the app with Android Studio, build and sync the dependencies and web assets.

``` bash
ionic build
npm run build
npx cap sync
```

Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
"homepage": "https://numbersprotocol.io/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build-android": "ionic build && cap sync && cap open android",
"test": "ng test",
"test-ci": "ng test --no-watch --no-progress --browsers=ChromeHeadlessCI",
"lint": "ng lint",
"e2e": "ng e2e"
"preconfig": "node set-secret.js",
"serve": "npm run preconfig && ionic serve",
"build": "npm run preconfig && ionic build",
"build-android": "npm run build && cap sync && cap open android",
"test": "npm run preconfig && ng test",
"test-ci": "npm run preconfig && ng test --no-watch --no-progress --browsers=ChromeHeadlessCI",
"lint": "npm run preconfig && ng lint",
"e2e": "npm run preconfig && ng e2e"
},
"private": true,
"dependencies": {
Expand Down Expand Up @@ -63,4 +64,4 @@
"typescript": "~3.9.7"
},
"description": "Capture lite app."
}
}
14 changes: 14 additions & 0 deletions set-secret.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require('fs');

// Configure Angular `secret.ts` file path
const targetPath = './src/environments/secret.ts';

// `secret.ts` file structure
const envConfigFile = `export const secret = {
numbersStorageBaseUrl: '${process.env.NUMBERS_STORAGE_BASE_URL}'
};
`;
fs.writeFile(targetPath, envConfigFile, err => {
if (err) { throw console.error(err); }
else { console.log(`Angular secrets.ts file generated correctly at ${targetPath} \n`); }
});
79 changes: 0 additions & 79 deletions src/app/components/header/header.component.html

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';

import { of, zip } from 'rxjs';
import { concatMap, concatMapTo, first, map, pluck } from 'rxjs/operators';
import { base64ToBlob$ } from 'src/app/utils/encoding/encoding';
import {
PreferenceManager,
} from 'src/app/utils/preferences/preference-manager';

import { PreferenceManager } from 'src/app/utils/preferences/preference-manager';
import { secret } from '../../../../environments/secret';
import { Proof } from '../../data/proof/proof';
import { Signature } from '../../data/signature/signature';
import {
SerializationService,
} from '../../serialization/serialization.service';
import { baseUrl } from './secret';
import { SerializationService } from '../../serialization/serialization.service';

export const enum TargetProvider {
Numbers = 'Numbers'
}

const baseUrl = secret.numbersStorageBaseUrl;
const preference = PreferenceManager.NUMBERS_STORAGE_PUBLISHER_PREF;
const enum PrefKeys {
Enabled = 'enabled',
Expand Down
1 change: 0 additions & 1 deletion src/app/services/publisher/numbers-storage/secret.ts

This file was deleted.

0 comments on commit d7a019d

Please sign in to comment.