---
# System prepended metadata

title: Order image 參數設定說明
tags: [Training]

---

###### tags: `Training`

# Order image 參數設定說明


## 事前準備的環境
* **DB IP**:
    * MongoDB -- 架設在DBS
    * SQL -- 架設在DBS
    * Redis (前台+後台) -- 架設在本地Docker Container

* **VM 連線資訊**
  ssh://centos@10.134.202.151:22
  密碼: foxconn

# 加入環境變數
## Docker Images 要帶入的 環境變數

### **總共有4個Image，分為子應用與主應用，以下為所有Image都需要的參數**
process.env
* **MONGO_DB** 
    * mongo 的連線帳密與 IP
    * ex: mongodb://192.168.120.4/fixo
* **SQL_DB**
    * maria 的連線帳密與 IP
    * ex: mariadb://root:foxconn@172.17.0.3:3306/order
* **REDIS_IP**
    * redis 的連線 IP
* **ROOT_URL**
    * 完整個網站 ROOT_URL
    * ex: http://10.62.164.163:8188
* **CAS_SERVER**
    * cas server IP
* **ADMIN_API**
    * SSO 列表呼叫的 API root URL
* **FIXO_API**
    * FIXO API 的 root URL
* **ORIGIN_IP**
    * 填入主應用的 ROOT URL
    * ex: "[\"http://10.62.164.163:8090\"]"
* **SESSION_DOMAIN** 
    * 當主子網域不同時使用
    * 填入主子網域最大共同級域名
* **COOKIE_DOMAIN** 
    * (react 用 切換語系)
    * 與FiXo的coolie domain 相同
* **FIXO_WEB_URL** (react 用)
    * fixo web 的 root url
* **REACT_APP_CURRENCY** (react 用)
    * 幣值
    * ex: "NT"

### **framework 才有的 ENV** (註冊子應用，以下填入子應用的URL)
* **REACT_APP_ENTRY_ORDER**
    * Order 子應用的網址
* **REACT_APP_ENTRY_METER**
    * Meter 子應用的網址

# 加入ETC Hosts

* 因為現在沒有真的解析所以需要
 --add-host [Hostname]:[IPAddress]

* **主子應用的網域**
central.lh-3.jadecloud.local:10.134.202.150 
service.lh-3.jadecloud.local:10.134.202.150 

* **FiXo 的網域**
console.lh-3.jadecloud.local:10.134.202.15
osapi.lh-3.jadecloud.local:10.134.202.15
fixoapi.lh-3.jadecloud.local:10.134.202.15
sso.lh-3.jadecloud.local:10.134.202.26 



## Docker Compose
因為上面要改的參數重複性很高，而且每次要一個一個把container跑起來真的很麻煩，所以就寫了 Docker compose 管理

之後遇到的[網路問題](https://hackmd.io/v1ovhuU6RlOcyRAecUQLsg?view)就在有機會整理一篇講講了
* docker-compose.yml
```=yml
version: "2"
services:
  dcasentry.order.portal:
    image: order.portal
    container_name: dcas.order.portal
    ports:
      - "8188:8188"
    extra_hosts:
      - ${host_entry_sso}
      - ${host_entry_framework}
      - ${host_entry_subservice}
      - ${host_region_fixoapi}
      - ${host_region_osapi}
      - ${host_region_fixoweb}
      - ${host_region_subservice}
    restart: always
    #volumes:
    environment:
      MONGO_DB: ${MONGO_DB}
      SQL_DB: ${SQL_DB}
      REDIS_IP: ${PORTAL_REDIS_IP}
      ROOT_URL: ${SERVICE_ROOT_URL}
      CAS_SERVER: ${PORTAL_CAS_SERVER}
      ADMIN_API: ${ADMIN_API}
      FIXO_API: ${FIXO_API}
      ORIGIN_IP: ${ORIGIN_IP}
      FIXO_WEB_URL: ${FIXO_WEB_URL}
      SESSION_DOMAIN: ${SESSION_DOMAIN}
      COOKIE_DOMAIN: ${COOKIE_DOMAIN}
      REACT_APP_CURRENCY: ${REACT_APP_CURRENCY}
    networks:
      - order_net
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "200"
    mem_limit: 100m

  dcasentry.frame.portal:
    image: frame.portal
    container_name: dcas.frame.portal
    ports:
      - "8090:8090"
    extra_hosts:
      - ${host_entry_sso}
      - ${host_entry_framework}
      - ${host_entry_subservice}
      - ${host_region_fixoapi}
      - ${host_region_osapi}
      - ${host_region_fixoweb}
      - ${host_region_subservice}
    restart: always
    #volumes:
    environment:
      MONGO_DB: ${MONGO_DB}
      SQL_DB: ${SQL_DB}
      REDIS_IP: ${PORTAL_REDIS_IP}
      ROOT_URL: ${FRAME_ROOT_URL}
      CAS_SERVER: ${PORTAL_CAS_SERVER}
      ADMIN_API: ${ADMIN_API}
      FIXO_API: ${FIXO_API}
      ORIGIN_IP: ${ORIGIN_IP}
      FIXO_WEB_URL: ${FIXO_WEB_URL}
      SESSION_DOMAIN: ${SESSION_DOMAIN}
      COOKIE_DOMAIN: ${COOKIE_DOMAIN}
      REACT_APP_CURRENCY: ${REACT_APP_CURRENCY}
      REACT_APP_ENTRY_ORDER: ${PORTAL_REACT_APP_ENTRY_ORDER}
    networks:
      - order_net
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "200"
    mem_limit: 100m

  dcasentry.order.mgmt:
    image: order.mgmt
    container_name: dcas.order.mgmt
    ports:
      - "8088:8088"
    extra_hosts:
      - ${host_entry_sso}
      - ${host_entry_framework}
      - ${host_entry_subservice}
      - ${host_region_fixoapi}
      - ${host_region_osapi}
      - ${host_region_fixoweb}
      - ${host_region_subservice}
    restart: always
    #volumes:
    environment:
      MONGO_DB: ${MONGO_DB}
      SQL_DB: ${SQL_DB}
      REDIS_IP: ${MGMT_REDIS_IP}
      ROOT_URL: ${SERVICE_ROOT_URL}
      CAS_SERVER: ${PORTAL_CAS_SERVER}
      ADMIN_API: ${ADMIN_API}
      FIXO_API: ${FIXO_API}
      ORIGIN_IP: ${ORIGIN_IP}
      FIXO_WEB_URL: ${FIXO_WEB_URL}
      SESSION_DOMAIN: ${SESSION_DOMAIN}
      COOKIE_DOMAIN: ${COOKIE_DOMAIN}
      REACT_APP_CURRENCY: ${REACT_APP_CURRENCY}
    networks:
      - order_net
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "200"
    mem_limit: 100m

  dcasentry.frame.mgmt:
    image: frame.mgmt
    container_name: dcas.frame.mgmt
    ports:
      - "8888:443"
    extra_hosts:
      - ${host_entry_sso}
      - ${host_entry_framework}
      - ${host_entry_subservice}
      - ${host_region_fixoapi}
      - ${host_region_osapi}
      - ${host_region_fixoweb}
      - ${host_region_subservice}
    restart: always
    #volumes:
    environment:
      MONGO_DB: ${MONGO_DB}
      SQL_DB: ${SQL_DB}
      REDIS_IP: ${MGMT_REDIS_IP}
      ROOT_URL: ${FRAME_ROOT_URL}
      CAS_SERVER: ${PORTAL_CAS_SERVER}
      ADMIN_API: ${ADMIN_API}
      FIXO_API: ${FIXO_API}
      ORIGIN_IP: ${ORIGIN_IP}
      FIXO_WEB_URL: ${FIXO_WEB_URL}
      SESSION_DOMAIN: ${SESSION_DOMAIN}
      COOKIE_DOMAIN: ${COOKIE_DOMAIN}
      REACT_APP_CURRENCY: ${REACT_APP_CURRENCY}
      REACT_APP_ENTRY_ORDER: ${PORTAL_REACT_APP_ENTRY_ORDER}
    networks:
      - order_net
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "200"
    mem_limit: 100m

#networks:
#  default:
#    driver: bridge

networks:
  order_net:
    external:
      name: order_net
```

* .env (設定檔，不同環境只要改這份就好)
```=sh
order_version=v4.0.0

# common
MONGO_DB=mongodb://fixo:fixofixo@192.168.130.4/fixo
SQL_DB=mariadb://order:order@192.168.130.9:3306/order
ADMIN_API=https://sso.lh-3.jadecloud.local
FIXO_API=http://fixoapi.lh-3.jadecloud.locali
FIXO_WEB_URL=https://console.lh-3.jadecloud.local
ORIGIN_IP=["https://console.lh-3.jadecloud.local","https://mtjade.lh-3.jadecloud.local"]
SESSION_DOMAIN=.lh-3.jadecloud.local
FIXO_WEB_URL=https://console.lh-3.jadecloud.local
COOKIE_DOMAIN=.lh-3.jadecloud.local
REACT_APP_CURRENCY=NT

# ROOT_URL
FRAME_ROOT_URL=https://mtjade.lh-3.jadecloud.local
SERVICE_ROOT_URL=https://service.lh-3.jadecloud.local


# portal
PORTAL_REDIS_IP=172.20.0.3
PORTAL_CAS_SERVER=https://sso.lh-3.jadecloud.local/portal
PORTAL_REACT_APP_ENTRY_ORDER=https://service.lh-3.jadecloud.local/portal/order

# mgmt
MGMT_REDIS_IP=172.20.0.2
MGMT_CAS_SERVER=https://sso.lh-3.jadecloud.local/admin
MGMT_REACT_APP_ENTRY_ORDER=https://service.lh-3.jadecloud.local/mgmt/order

host_entry_sso=sso.lh-3.jadecloud.local:10.134.202.26
host_entry_framework=mtjade.lh-3.jadecloud.local:10.134.202.15
host_entry_subservice=service.lh-3.jadecloud.local:10.134.202.15

host_region_fixoapi=fixoapi.lh-3.jadecloud.local:10.134.202.15
host_region_osapi=osapi.lh-3.jadecloud.local:10.134.202.15
host_region_fixoweb=console.lh-3.jadecloud.local:10.134.202.15
host_region_subservice=service.console.lh-3.jadecloud.local:10.134.202.15
```

## 加入排程

```
$ crontab -e
```
貼上排程

```
0 9 * * * /bin/bash /home/centos/dcas-order/task/curlMail.js
```



