Yanting Lin
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • 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
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
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
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# Jboss + API server + AngularJS integrate with Jenkins in Docker compose 這是我們目前整體的開發版系統架構圖![](https://i.imgur.com/lkXBWsT.png) 以下教學是基於 VAssistantDocker 在 bitbucket上的原始碼 ## AngularJS deploy to Jboss ### 將Angular Distribution 丟到 Jboss的 wildfly web server 0. 修改vassitantWeb/src/index.html 把這行 `<base href="/">` 改成 `<base href=".">` 這個之後的change再修掉就好XD 1. 把初始的Angular原始碼下以下指令 ```shell ng build ``` 會看到dist長出來的結構如下圖: ![](https://i.imgur.com/C2W72LL.png) 2. 進入Jboss containter (以下二擇一) MAC: ```shell bash -c "clear && docker exec -it jboss_Backend bash" ``` Windows git bash: ```shell docker exec -i jboss_Backend bash ``` 3. 新增 testAngular 資料夾 (in jboss container) ```shell cd /opt/jboss/wildfly/ mkdir testAngular ``` 4. 修改 standalone.xml (in jboss container) ```shell vi /opt/jboss/wildfly/standalone/configuration/standalone.xml ``` 修改下列部分成這樣 ![](https://i.imgur.com/ZeOjuBs.png) > 在default-host跟handler下面加,是參考[這裡](https://stackoverflow.com/a/34399062) :::warning 記得存檔後要重開jboss ::: 5. 把剛剛build好的angular的檔案複製到 jboss container :::info 由於還不曉得jboss container 的user密碼,先直接用docker cp 把dist的丟過去 最終目標應該是用jenkins的container透過指令丟過去 ::: 確認自己在 vassistantWeb/dist/ 的資料夾內後, 下以下指令 ```shell docker cp . jboss_Backend:/opt/jboss/wildfly/testAngular/ ``` 查看jboss container的`/opt/jboss/wildfly/testAngular/` 目錄應該會長這樣 ![](https://i.imgur.com/A5WliYm.png) 6. 打開server <ip or domain name>:8080/testAngular/ 就可以看到以下畫面,應該就表示完成了 ![](https://i.imgur.com/ibL0RZ9.png) ## WildFly and Jenkins 容器資料夾共用 先前有提到 [Angular佈署在WildFly上](http://blog.lyt.tw/2018/01/web-service-angular-wildfly.html) 可以怎麼做的其中一個方法    假設我們在Jenkins Container(容器) 已經測試也Build好Angular的dist檔案 那要怎麼樣把檔案丟到WildFly的容器上呢?    如果使用檔案傳輸等方式會需要帳號密碼,會有安全性要考量 這個時候我們可以利用Docker內建的Volumes,掛載共同的資料夾 現在,我們已有兩個容器"jboss_Backend"與"jenkins" 在docker-compose.yml所在資料夾下 還有兩個資料夾 `jenkins/`跟`jboss-backend/`,裡面有各自的Dockerfile    首先,我們需要在我們docker-compose.yml做以下設定 (1). 最下方宣告掛載的Volumes名稱 e.g., web-dist-volume   要注意volumes跟service是同一個階層的 (2). 設定jboss-backend跟jenkins的掛載名稱與目錄名稱 ![](https://i.imgur.com/USCfgmM.png)    接著,需要在jenkins資料夾下的Dockerfile加上下列幾行資訊 用root創建資料夾,比較不會遇到權限問題 最後一併把資料夾的擁有者給指定的使用者,e.g., jenkins 並且要記得切回使用者jenkins ![](https://i.imgur.com/pTkidxJ.png) 完成之後,在該目錄下 ```shell docker build --force-rm -t jenkins/jenkins:ytTest . ``` force-rm 只是強迫移除掉原有的tag (如果有的話) 原有的image也不會消失,只是tag被拿掉 jenkins/jenkins是image name ytTest則是tag    同樣的道理,我們在jboss-backend資料夾下的Dockerfile做類似的設定 只是這邊原有的Dockerfile就會把 ${JBOSS_HOME}下的目錄擁有者設成jboss 所以就不用特別調整 ![](https://i.imgur.com/JS0T0mq.png) 完成後,一樣要下 ```shell docker build --force-rm -t jboss/wildfly:ytTest . ```    最後再到docker-compose.yml目錄下執行`docker-compose up` 這樣子,就能夠在兩者之間分享檔案啦! ## Jenkins x BitBucket x Angular x WildFly 上次有提到透過[Container檔案共用](http://blog.lyt.tw/2018/01/docker-container.html),可以讓Jenkins Build好的檔案放到部署的資料夾 回顧先前提到的系統架構圖 現在,我們要先以Jenkins為中心 從BitBucket取得程式碼,Build Angular的程式碼,部署到WildFly上 雖然說是部署,但這Case其實就是複製到某資料夾而已 ![](https://i.imgur.com/lkXBWsT.png) 在說明開始前有以下假設: 1. 已經完成 [Angular佈署在WildFly上](http://blog.lyt.tw/2018/01/web-service-angular-wildfly.html) ``` 本來的 testAngular 這邊改成 angular-dist ``` 2. 已經完成[Container檔案共用](http://blog.lyt.tw/2018/01/docker-container.html) 3. Jenkins已經安裝好預設的plugin 跟 **Nodejs Plugin** Note: karma plugin 不在本次的說明範圍 大致有三大步驟: I. 安裝Nodejs的運行版本 II. 設定到bitbucket的ssh key III. Jenkins 組態設定Build and deploy ### I. 安裝Nodejs的運行版本 1. 到Jenkins首頁,點選管理Jenkins ![](https://i.imgur.com/yYTzXhj.png) 2. 點選 Global Tool Configuration ![](https://i.imgur.com/4sBHbJp.png) 3. 往下滑到NodeJS區塊,點選NodeJS安裝 ![](https://i.imgur.com/yJ4FlXq.png) 4. 填寫Nodejs相關資訊 我們以 nodejs 8.9.3為例 名稱方便辨識即可(e.g., nodeJS 8.9.3),Version就選擇 8.9.3 由於是Angular開發,我們要安裝 @angular/cli,也讓npm版本是最新的(5.5以前有bug) ![](https://i.imgur.com/bPCEUMP.png) ### II. 設定到bitbucket的ssh key 5. 假設我們已經透過 Keygen 產生一組 `id_rsa`與`id_rsa.pub` 並且把他放到 jenkin容器下的 `/var/jenkins_home/.ssh/` 目錄 該目錄應該會長這樣 (known_hosts可以先忽略) ![](https://i.imgur.com/jIOdKK6.png) :::warning Jenkins的預設設定,也是抓id_rsa與id_rsa.pub這兩個名稱,若不需要不建議更改 ::: 6. 接著,到我們的BitBucket專案的設定裡面選取Access keys → Add Key ![](https://i.imgur.com/NtkvwWe.png) 7. Label命名好之後,將`id_rsa.pub`貼在 Key的欄位並新增 ![](https://i.imgur.com/NJHHUyw.png) ### III. Jenkins 組態設定Build and deploy 8. 到jenkins首頁點選新增作業 ![](https://i.imgur.com/o2NDfLr.png) 9. 命名並選取建置Free-Style專案 ![](https://i.imgur.com/ARinxx1.png) 10. 在原始碼管理把我們要建置的專案URL `git@bitbucket.org:OOOOO/XXXXX.git` 填在 Repository URL並新增 Credential Key ![](https://i.imgur.com/NAtGVRp.png) 11. Credentials 設定 Kind我們選擇 **SSH Username with private key** Username填寫好後 Private Key我們選擇From the Jenkins master ~/.ssh 密碼如果沒有沒設就不用,其他也暫時可以不用設定 ![](https://i.imgur.com/TNMmCUT.png) :::info 由於未來要自動化考量,傾向把那組Key放在 `/var/jenkins_home/.ssh/` 裡 這樣之後BitBucket才不需要一直新增新的Access Key ::: 12. 建置環境與建置設定 建置環境選取Provide Node & npm bin/ folder to PATH 版本就選取NodeJS 8.9.3 建置選擇 shell 在下方輸入 ```shell npm install ng build cp dist/* /angular-dist/ #看你們佈署在哪個目錄下 ``` ![](https://i.imgur.com/0HgUv1E.png) 13. 如果建置成功,我們就可以看到首頁了~ ![](https://i.imgur.com/xR7Pzmi.png) #### Docker 相關補充 進入 docker container ``` #以預設身份登入 bash -c "clear && docker exec -it jenkins bash" #已指定身份登入 (e.g., root) bash -c "clear && docker exec -u root -it jenkins bash" ```

Import from clipboard

Paste your markdown or webpage here...

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 lose 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?
Turn this template into a regular note and keep its content, versions, and comments.

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

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

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 and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

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.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully