HackMD
    • Sharing Link copied
    • /edit
    • View mode
      • Edit mode
      • View mode
      • Book mode
      • Slide mode
      Edit mode View mode Book mode Slide mode
    • Note Permission
    • Read
      • Only me
      • Signed-in users
      • Everyone
      Only me Signed-in users Everyone
    • Write
      • Only me
      • Signed-in users
      • Everyone
      Only me Signed-in users Everyone
    • More (Comment, Invitee)
    • Publishing
    • Commenting Enable
      Disabled Forbidden Owners Signed-in users Everyone
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Invitee
    • No invitee
    • Options
    • Versions
    • Transfer ownership
    • Delete this note
    • Template
    • Save as template
    • Insert from template
    • Export
    • Google Drive Export to Google Drive
    • Gist
    • Import
    • Google Drive Import from Google Drive
    • Gist
    • Clipboard
    • Download
    • Markdown
    • HTML
    • Raw HTML
Menu Sharing Help
Menu
Options
Versions Transfer ownership Delete this note
Export
Google Drive Export to Google Drive Gist
Import
Google Drive Import from Google Drive Gist Clipboard
Download
Markdown HTML Raw HTML
Back
Sharing
Sharing Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
More (Comment, Invitee)
Publishing
More (Comment, Invitee)
Commenting Enable
Disabled Forbidden Owners Signed-in users Everyone
Permission
Owners
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Invitee
No invitee
   owned this note    owned this note      
Published Linked with
Like BookmarkBookmarked
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
--- tags: cofacts GA: UA-98468513-3 --- Running Cofacts on Laptop: README ==== Video Intro {%youtube vAym6ABz0og%} ## Prerequisite - [`git`](https://git-scm.com/downloads) for cloning repositories - [`Node.js >= 8`](https://nodejs.org/en/download/package-manager/#nvm) for schema & seed - [`docker`](https://store.docker.com/search?type=edition&offering=communityd) & [`docker-compose`](https://docs.docker.com/compose/install/#install-compose) - 2GB memory in prod env ## Steps ### Clone repositories Please clone these 2 repositories: ```bash $ git clone https://github.com/cofacts/rumors-deploy.git $ git clone https://github.com/cofacts/rumors-db.git ``` The README of these directories are still under work. After the finishing touches, README of all repositories should share a same strucutre. #### `cofacts/rumors-deploy` This repository contains the deploy scripts (docker-compose.yml) that actually runs the components of Cofacts. There are 2 `docker-compose` YML files: - `docker-compose.sample.yml`: Minimal setup to get all Cofacts service running on a single computer. - `docker-compose.production.yml`: The actual setup (with secrets redacted) that is running on cofacts.g0v.tw . The differences are: - We run productin LINE bot service on heroku, thus there is no `line-bot` and `redis` in `docker-compose.production.yml` - Additionally, `nginx` is added as a reverse-proxy and serves https certificates. To run Cofacts on laptop, we can just use `docker-compose.sample.yml`. Run the following to create `docker-compose.yml` from the sample file so that we don't need to add extra arguments when invoking `docker-compose`. ```bash $ cd rumors-deploy rumors-deploy $ cp docker-compose.sample.yml docker-compose.yml ``` #### `cofacts/rumors-db` ### Inspecting logs It will be handy if we keep a terminal that shows logs of the following operations. Run the following in a *separate* terminal to ```bash rumors-deploy $ docker-compose logs -f ``` ### Start DB You need to prepare the permissions ```bash rumors-deploy $ docker-compose up -d db ``` :::warning ### Caveats If your are running into memory issue: Try changing kernel settings: https://www.elastic.co/guide/en/elasticsearch/reference/6.3/docker.html#docker-cli-run-prod-mode If all your elasticsearch indexes became read-only, : https://stackoverflow.com/a/34911897 ::: :::success You should be seeing the DB up and running here: http://localhost:62222/ ::: ### Initialize DB This repository contains the database mapping and the setup scripts. ```bash $ cd rumors-db $ npm i ``` Before we run any scripts, we will need to specify the url of elasticsearch database. Please open up the editor of your choice and edit `.env` to replace `localhost:62223` with `localhost:62222` : ```bash # In rumors-db's directory: # $ vim .env # Change localhost:62223 to localhost:62222 ``` Now we can run the scripts (remember to run `npm install` beforehand): ```bash # In rumors-db's directory: # $ npm run schema # creates Elasticsearch index & mappings $ npm run seed ``` ### Start other services [<img src="https://docs.google.com/drawings/d/1VfooYFnEb_mVx9Yso_u9evYD-nq-Y-mDSwsIlg7oDlw/pub?w=846&amp;h=467">](https://docs.google.com/drawings/d/1VfooYFnEb_mVx9Yso_u9evYD-nq-Y-mDSwsIlg7oDlw/edit) ```bash # In rumors-deploy's directory: # $ docker-compose up -d url-resolver # Run on localhost:4000 $ docker-compose up -d api # Run on localhost:5000 $ docker-compose up -d site # Run on localhost:3000 ``` ### Update `/etc/hosts` To connect API server and the site within docker network, we are using the hostname "`api`". Since the URL will go to the browser as well, we will need to teach the laptop about this hostname: ``` # /etc/hosts # Add the following line: 127.0.0.1 api ``` ### Get the LINE bot running! #### Get channel ID and secret for LINE chatbot Please follow the [official guide](https://developers.line.me/en/docs/messaging-api/getting-started/) to: - register LINE via email - register as a developer - create a "channel" - get channel access token https://developers.line.me/en/docs/messaging-api/building-bot/ #### Fill in tokens Edit `docker-compose.yml` in `rumors-deploy` to fill in: ```yml - LINE_CHANNEL_SECRET=<paste LINE@'s channel secret here> - LINE_CHANNEL_TOKEN=<paste LINE@'s channel token here> ``` ## Running on production machine ### Machine planning As explained when we introduce `docker-compose.production.yml`, we do not host rumors-line-bot on the same machine with other components. If you want to separate components to different machines, we suggest: - Put database and `rumors-api` together / as near as possible - `rumors-site` can be served in separate machine - `rumors-line-bot` can be served in separate machine - `url-resolver` can be served in separate machine ### Log management Choose one of the following: - [Using logrotated](https://sandro-keil.de/blog/logrotate-for-docker-container/) - [Using docker built-in log-rotate mechanism](https://medium.freecodecamp.org/how-to-setup-log-rotation-for-a-docker-container-a508093912b2) ### HTTPS

Import from clipboard

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lost their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.


Upgrade

All
  • All
  • Team
No template.

Create a template


Upgrade

Delete template

Do you really want to delete this template?

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

Sign in via GitHub

New to HackMD? Sign up

Help

  • English
  • 中文
  • 日本語

Documents

Tutorials

Book Mode Tutorial

Slide Example

YAML Metadata

Resources

Releases

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions

Versions

Upgrade now

Version named by    

More Less
  • Edit
  • Delete

Note content is identical to the latest version.
Compare with
    Choose a version
    No search result
    Version not found

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.