---
# System prepended metadata

title: Jerry's  筆記

---


## 開發環境

### .Net Core
> .NET Core SDK(目前是6.0，但舊專案可能須同時安裝3.0)


### Figma (Page Design)
> [技轉-WiLES](https://www.figma.com/file/POhDtHlcgzcS5NDHTiE7Kp/%E6%8A%80%E8%BD%89-WiLES?node-id=4158-36807&t=bB2AaNDjPkEOGdnk-0)
> [WiLES Design Guide](https://www.figma.com/file/AuWam4u4hKvsUxE5tnq382/%F0%9F%94%86---%E6%8A%80%E8%BD%89-WiMES%2FWiLES-Design-Guide?node-id=403-1744&t=hhqKBfVFSCEraOyH-0)

### DB
> [DB File](https://wistron.sharepoint.com/:x:/r/teams/ML8CIMDev/Shared%20Documents/ML8%20Mgmt.%20Docs/Logistics%20Team%20Documents/LE/CR/LE%20WW%20Project_CR%20Review_2023.xlsx?d=wa68579fe6af54c66818c9e80303dfd6b&csf=1&web=1&e=8vZEyL)

### Install GitLab Project
```cmd=
$ git submodule update --init --recursive
$ dotnet restore
$ dotnet build
```
### VSCODE 

#### Plug (extensions)
```json
C# Extensions
C# Sort Usings
C# XML Documentation Comments
Prettier - Code formatter
Blazor Snippets
Blazor VSCode Extensions - Syncfusion(注意：此插件会影响VS Code操作git, 需要建立建Host专案的时候才需要启动，正常情况下禁用)
Microsoft.AspNetCore.Razor.VSCode.BlazorWasmDebuggingExtension
vscode-solution-explorer
```
#### Settings(settings.json)
```jsonld=
{
  "editor.formatOnType": true,
  "editor.formatOnSave": true,
  "workbench.sideBar.location": "left",
  "workbench.activityBar.visible": true,
  "highlightLine.borderStyle": "groove",
  "[json]": {
    "editor.defaultFormatter": "vscode.json-language-features"
  },
  "[csharp]": {
    "editor.defaultFormatter": "ms-dotnettools.csharp"
  }
}
```



<hr style="background-color:rgb(100, 100, 144);"/>


## GitLab(先申請)

### 2Auth
> install Twilio Authy (Or other 2Auth)
> [install](https://ahoy.twilio.com/twilio-brand-sales-1?cq_plac=&cq_net=g&cq_pos=&cq_med=&cq_plt=gp&utm_source=google&utm_medium=cpc&utm_term=twilio&utm_campaign=G_S_APAC_Brand_Brand_EN_TW_Phrase&gclid=CjwKCAjw_MqgBhAGEiwAnYOAep9nWxSIJs6WpQxw9ymmacmGh2WHm3ZW8viLbGTwe4C9WntDZETWFhoCL7wQAvD_BwE)
>  [How to use?](https://www.cyberbiz.io/support/?p=12873)

### 檔案位置(LE Blazor)
> WiLES > WiLES_BlzUI

### 舊系統位置
> Logistic > LMS > LE > WebClients 

<hr style="background-color:rgb(100, 100, 144);"/>

## Cross-Origin Resource Sharing (CORS)

### 設定
#### Startup.cs 
> 跨域cross
```vb=16
private static readonly string _myCorsConfig = "_myCorsConfig";
```
> Allow Cors Policy. 允許跨域 localhost:4001 , localhost:5001 兩個不同協定需要跨域需要開啟
```vb=52
services.AddCors(options =>
{
    options.AddPolicy(name: _myCorsConfig, builder =>
    {
        // Allow *
        builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin();
    });
});
```
> 别注意：如果缺少这句，则Blazor WebAssembly call API fail, 无法获取到API返回值信息
```vb=83
app.UseCors(_myCorsConfig); 
app.UseRouting();
```


<hr style="background-color:rgb(100, 100, 144);"/>

## Blazor

### Learning 

#### Teams

> ML8 WiLes > WiLES Common > 08.Traning > Blazor

#### 教材
> [wiki.js](https://cimokrwiki.k8sprd-whq.k8s.wistron.com/en/Platform/Blazortraining)
> [Blazor(包含程式碼、頁面呈現效果、教學文件)](https://gitlab-dev.wistron.com/11107391/blazor-training)


#### How to call API?
> [Blazor-Round2 後半段](https://wistron.sharepoint.com/teams/ML8WiLES/_layouts/15/stream.aspx?id=%2Fteams%2FML8WiLES%2FShared%20Documents%2FWiLES%20Common%2F08%2E%20Training%2FBlazor%2FBlazor%2DRound2%2D%E6%9C%83%E8%AD%B0%E9%8C%84%E8%A3%BD%2Emp4&referrer=Teams%2ETEAMS%2DELECTRON&referrerScenario=teamsSdk%2DopenFilePreview)

### 架構
> 主要檔案位置放置 CIM_REASONCDE_WW_BLZUI 資料夾
> 執行 > cd 切換至 CIM_REASONCDE_WW_SERVIER 執行
```cmd=
> dotnet watch run 
or dotnet run
``` 

![](https://i.imgur.com/RIKZUu4.png)



<hr style="background-color:rgb(100, 100, 144);"/>





## CCOE Vault 

![](https://hackmd.io/_uploads/Sy10mT0D3.png)

1. 刪除資料夾所有檔案 (需先備分)
> 只保留gikeep，等ARGOCD 
> 確定移除再進行下步驟 (ARGOCD common 資料夾完全不見)
> 可參考此commit https://gitlab.wistron.com/ccoe/releasemanagement/-/merge_requests/31021
> 
![](https://hackmd.io/_uploads/SkBXT2Cw3.png)

2. 
> 建立vault.taml；直接把common資料夾複製回來，並刪除cronjob.yaml
> 確定移除再進行下步驟 (ARGOCD common 長出來看到vault後)
> 可參考此commit https://gitlab.wistron.com/ccoe/releasemanagement/-/merge_requests/31023

![](https://hackmd.io/_uploads/HJ26_R0v2.png)


3. 
> 把剛剛 cronjob.yaml 建立回來
> 確定移除再進行下步驟 (ARGOCD cronjob 長出來看到其餘設定 DB-connection ...)
> 可參考此commit https://gitlab.wistron.com/ccoe/releasemanagement/-/merge_requests/31031

![](https://hackmd.io/_uploads/rkAk2RCv3.png)


4.  
> 將其他檔案丟回來
![](https://hackmd.io/_uploads/ByywkJk_h.png)


## CCOE API Upload
> [Gitops](https://wistron.sharepoint.com/sites/ITKM/project_management/Developing%20Document%20Library/Forms/AllItems.aspx?e=5%3Af2999f22f9764bcb993365fb5922d9cc&at=9&FolderCTID=0x01200084799033C5CB0541A671CDAB5272AFB6&OR=Teams%2DHL&CT=1665456128330&isAscending=true&referrer=Teams%2ETEAMS%2DELECTRON&referrerScenario=p2p%5Fns%2Dbim&web=1&sortField=LinkFilenameNoMenu&id=%2Fsites%2FITKM%2Fproject%5Fmanagement%2FDeveloping%20Document%20Library%2FSystem%20Space%2FML8%20CIM%20Dev%2FML8%20Training%2F01%2E%20CIM%20Development%2F03%2E%20CICD%2FGitOps%20%2D%20%E4%BD%BF%E7%94%A8ArgoCD%E4%BD%88%E7%BD%B2%E7%A8%8B%E5%BC%8F%E5%88%B0Rancher%20%28k8s%29%2D20220621%5F110118%2D%E6%9C%83%E8%AD%B0%E9%8C%84%E8%A3%BD%2Emp4&viewid=7520ca55%2D1fc9%2D46a3%2Dbfff%2D8fc3bee2eea4&parent=%2Fsites%2FITKM%2Fproject%5Fmanagement%2FDeveloping%20Document%20Library%2FSystem%20Space%2FML8%20CIM%20Dev%2FML8%20Training%2F01%2E%20CIM%20Development%2F03%2E%20CICD)

## CCOE APP memory 更新

1. app 更新
```
messupermiwwblzui:
  image:
    repository: "k8sprdwihcim/platform/messupermiwwblzui"
    tag: "0.6.0"
  limits:
    cpu: "1.2"
    memory: 8192Mi
  imagePullSecret: "wiles-harbor"
```
2. 查看開的 memory 多少  argo底下資料夾 ex wiles.yaml

```
# Namespace config: Namespace, ResourceQuota, LimitRange, NetworkPolicy
apiVersion: v1
kind: Namespace
metadata:
  name: wiles

---
apiVersion: v1
kind: ResourceQuota
metadata:
  name: resourcequota
  namespace: wiles
spec:
  hard:
    limits.cpu: "70"
    limits.memory: 200Gi
```

## DataHub 資料發佈

```python
from airflow import DAG
from airflow.utils.dates import days_ago
from datahub.operators.rdb_to_datahub import RDBToDatahubOperator
from airflow.operators.python import PythonOperator

default_args = {
    'owner':'10603117', #這裡可以查看minio的wihcim_members.json；若不在此名單會遇到權限阻擋。
}

dag = DAG(
    dag_id="wihcim_le_data",  # prefix必需是tenant id, 例如: de00 此dag_id 就等同於此py檔案檔名
    start_date=days_ago(1),
    schedule_interval='@daily', # monthly(每月) ； 多久跑一次
    default_args=default_args,
    tags=['wihcim'], # 顯示tag 可以按照專案去設定
    access_control={
        'wihcim': {'can_read', 'can_edit'}  # 設定DAG歸屬那個團隊[tenant id]與權限
    }
) 

# 當error時候顯示錯誤訊息
def on_task_failure(context):
    exception = context['exception']
    error_message = str(exception)
    error_traceback = str(exception.__traceback__)
    print(f'Task failed. Error message: {error_message}')
    print(f'Task failed. Traceback: {error_traceback}')
# Producer Task
whqcim_le_dn = RDBToDatahubOperator(
    task_id='whqcim_le_dn',
    rdb_type='postgres',  # 來源資料庫類型
    rdb_conn_id='wihcim_cimdatazone_ledash_prd',  # 來源數據的 Connection ID ； 查看minio 的connection ，實際上用到哪隻json可以查看裡面的DB設定 or 自己創建
    query='',  # 要發佈資料的 SQL ，對應下面topic ， 實際用到那些欄位可能要請owner 上 Data Service Portal 查看 
    datahub_topic='whq.cim.ledash.logisticsexpense_dn',  # 要發佈的 Topic , 上 Data Service Portal 查看 
    datahub_conn_id='wihcim_pro',  # Datahub 帳密的 Connection ID      
    dag=dag,
    on_failure_callback=on_task_failure  # error func
)

# call func 若多個可以 Task1 , Task2 
# 如果不想並行，想依序執行可以 Task1 > Task2 
whqcim_le_dn   

```

## 在CCOE 新增環境
![](https://hackmd.io/_uploads/BJbqVoXq2.png)
> 該範例由ARM-PRD 複製至 AKS-PRD
>[查看各環境相關網址](https://cloud-guidebook.wistron.com/services/Cloud-Readiness/#cluster-status-light-description)
1. 索取vault 帳密 
> 請PIC、IBU  至 [wicop](https://wicop-portal.k8sprd-whq.k8s.wistron.com/login)  查詢

2. 到Vault 新增連線字串(可以參考複製過來的環境相關設定)
![](https://hackmd.io/_uploads/SJPGFQmph.png)

3. 將要複製的環境直接copy過來
![](https://hackmd.io/_uploads/BJfa97QTn.png)
> value.yaml 記得修改 namespace, pvcName .. 相關變數，設定內容請參考IBU設定。
> 
> Azure 的 storageClassName : azurefile-csi-premium
> 
> ARM 的 storageClassName: ssd-io1
> 
![](https://hackmd.io/_uploads/B1n8447a2.png)

> Keycloak 服務開啟
> [參考此篇](https://cimokrwiki.k8sprd-whq.k8s.wistron.com/Platform/Portal)

> DEV,QAS  [Realm 環境網址](https://keycloak-dev.wistron.com/auth/realms/k8sdevwihwilms/protocol/openid-connect/auth?client_id=security-admin-console&redirect_uri=https%3A%2F%2Fkeycloak-dev.wistron.com%2Fauth%2Fadmin%2Fk8sdevwihwilms%2Fconsole%2F%23%2Frealms%2Fk8sdevwihwilms%2Fclients&state=a522f6d3-aac1-43aa-af17-6745d12d92ba&response_mode=fragment&response_type=code&scope=openid&nonce=4b7e3c6c-1936-4e7b-85a0-035f059ccb91&code_challenge=Q2cvx6RtOISb8hmOhCnImRRIm4nRfh3grTTz0kBYMg4&code_challenge_method=S256)
> 參考配置：
![](https://hackmd.io/_uploads/SkZ3pEXa2.png)
```
  keycloakUrl: https://keycloak-dev.wistron.com/auth/ 
  keycloakRealm: k8sdevwihwilms 
```

> PRD  [Realm 環境網址](https://keycloak-prd.wistron.com/auth/realms/k8sprdwihk8swihwilms.prd/protocol/openid-connect/auth?client_id=security-admin-console&redirect_uri=https%3A%2F%2Fkeycloak-prd.wistron.com%2Fauth%2Fadmin%2Fk8sprdwihk8swihwilms.prd%2Fconsole%2F%23%2Frealms%2Fk8sprdwihk8swihwilms.prd%2Fclients&state=a81e8b13-6b0c-4232-96f9-4d83387ad795&response_mode=fragment&response_type=code&scope=openid&nonce=0642fd49-a802-4b40-8acb-c98a68dbe23b&code_challenge=lwkQnMCcKdoW-ZIeOqb19mIFnGBv--eCX3o3x16VBr4&code_challenge_method=S256)
> 
> 參考配置：
![](https://hackmd.io/_uploads/H19wTNQT3.png)
![Uploading file..._gzxk9qqul]()
```
  keycloakRealm: K8sprdwhqk8swhqwiles.prd
  keycloakClientId: wiles-aks-prd-portalwebui
```

## CCOE - minio rabbitmq 重新產生

### step 1
1. 將 common -> charts -> rabbitmq 整包下下來
2. 將 common -> Chats.yaml -> rabiitmq dependencies 註解
3. 將 platform -> values.yaml 中 tags jobs 關閉
![](https://hackmd.io/_uploads/ryF9nRrin.png)
4. 將 platgorm -> charts -> minio 整包下下來
5. 將 platgorm -> templates -> pvc.yaml 下下來

### step 2

1. 等待argo將rabbitmq 不見後進行步驟3

![](https://hackmd.io/_uploads/Sk4z60Ho3.png)


### step 3





### Portal 環境

> 進行以下設定 ， [後面網域可參考此](https://cloud-guidebook.wistron.com/services/Cloud-Readiness/#cluster-status-light-description)
```
value.yaml
  host: wiles-portal.southeastasia.azure.wistron.com
```
>  ex:

```
wiles-portal.southeastasia.azure.wistron.com

```