HackMD
    • Create new note
    • Create a note from template
    • Options
    • Versions
    • Transfer ownership
    • Delete this note
    • Template
    • Save as template
    • Insert from template
    • Export
    • Dropbox
    • Google Drive
    • Gist
    • Import
    • Dropbox
    • Google Drive
    • Gist
    • Clipboard
    • Download
    • Markdown
    • HTML
    • Raw HTML
    • ODF (Beta)
    • PDF (Beta)
    • 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
      Owners
      • Owners
      • Signed-in users
      • Everyone
      Owners Signed-in users Everyone
    • Write
      Owners
      • Owners
      • Signed-in users
      • Everyone
      Owners Signed-in users Everyone
    • More (Comment, Invitee)
    • Publishing

      After the note is published, everyone on the web can find and read this note.
      See all published notes on profile page.

    • More (Comment, Invitee)
    • Commenting Enable
      Disabled Forbidden Owners Signed-in users Everyone
    • Permission
      Owners
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Invitee
    • No invitee
Menu Sharing Create Help
Create Create new note Create a note from template
Menu
Options
Versions Transfer ownership Delete this note
Export
Dropbox Google Drive Gist
Import
Dropbox Google Drive Gist Clipboard
Download
Markdown HTML Raw HTML ODF (Beta) PDF (Beta)
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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
More (Comment, Invitee)
Publishing

After the note is published, everyone on the web can find and read this note.
See all published notes on profile page.

More (Comment, Invitee)
Commenting Enable
Disabled Forbidden Owners Signed-in users Everyone
Permission
Owners
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Invitee
No invitee
   Published      
   owned this note    owned this note
   Linked with GitHub
  • Watch - Be notified of any changes
  • Never - Never be notified
--- 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

Editing is for members only

With current role, you can only comment.
Learn how

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.

Transfer ownership

    or

      Create a note from template

      Create a note from template

      Oops...
      This template is not available.
      All
      • All
      • Team
      No template found.

      Create a template

      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 Facebook Sign in via GitHub Sign in via Google

      New to HackMD? Sign up

      Help

      Documents

      Features
      YAML Metadata
      Slide Example
      Book Example

      Cheatsheet

      Example
      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~~
      19th 19^th^
      H2O H~2~O
      Inserted text ++Inserted text++
      Marked text ==Marked text==
      Link [link text](https:// "title")
      Image ![image alt](https:// "title")
      Code `Code`
      var i = 0;
      ```javascript
      var i = 0;
      ```
      :smile: :smile:
      Externals {%youtube youtube_id %}
      LaTeX $L^aT_eX$

      This is a alert area.

      :::info
      This is a alert area.
      :::

      Versions

      Versions

      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?