iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 29
1
Cloud Native

AWS高手同事離職後不止30天系列 第 29

= = 部門 Slack DevOps 頻道 GG了 > Travis to S3 III

  • 分享至 

  • xImage
  •  

前情提要

各位邦友,既然程式經過「套件安裝」「測試」「打包」之後,再來就是要進行「佈署」的事情(Travis CI 佈署支援)。只要涉及服務跟服務之間要溝通運作。就要經過「授權」「設定」的過程。由於Travis CI 要透過.travis.yml來跟「佈署提供者」互動。部份「設定」,要使用Travis CI Client來完成。

安裝Travis CI Client

小編電腦是Windows

  • 安裝ruby:RubyInstaller
  • 打開Git Bash輸入指令:ruby -v,確認安裝結果。
      $ ruby -v
      ruby 2.5.3p105 (2018-10-18 revision 65156) [x64-mingw32]
    
  • 用ruby的套件管理gem安裝Travis CI Client
    確認安裝結果:travis version
      $ gem install travis -v 1.8.9 --no-rdoc --no-ri
      $ travis version
        1.8.9
    

用Travis CLI完成.travis.yml deploy s3設定

  • 登入:travis login --pro
      $ travis login --pro
      We need your GitHub login to identify you.
      This information will not be sent to Travis CI, only to api.github.com.
      The password will not be displayed.
    
      Try running with --github-token or --auto if you don't want to enter your password anyway.
    
      Username: bebright
      Password for bebright: **************
      Successfully logged in as bebright!
    
  • 指令協助設定deploy(s3):travis setup s3
      $ travis setup s3
      Access key ID: AKIAIA2J7HXUI52NHMHA
      Secret access key: ****************************************
      Bucket: bright-travis-deploy
      Local project directory to upload (Optional): dist
      S3 upload directory (Optional):
      S3 ACL Settings (private, public_read, public_read_write,authenticated_read,
         bucket_owner_read, bucket_owner_full_control): private
      Encrypt secret access key? |yes|
      Push only from bebright/slack-demo? |yes|
    
    .travis.yml(新增設定)
      deploy:
        provider: s3
        access_key_id: AKIAIA2J7HXUI52NHMHA
        secret_access_key:
          secure: JPDcEKISOrS4YK31WC...太長了(省略)
        bucket: bright-travis-deploy
        local-dir: dist
        acl: private
        on:
          repo: bebright/slack-demo
    
  • .travis.yml(新增設定)
    skip_cleanup: true:這一行真的很雷,不加的話,travis會把你build出來的東西清掉,搞超久的@@。
      deploy:
        # 同上
        skip_cleanup: true
    

AWS S3 設定

  • 建立S3 bucket:bright-travis-deploy,建立步驟可參考這篇
  • 設定S3權限to IAM User:travis ci policy,建立步驟可參考這篇
    travis ci policy(JSON)
      {
          "Version": "2012-10-17",
          "Statement": [
              {
                  "Effect": "Allow",
                  "Action": [
                      "s3:DeleteObject",
                      "s3:DeleteObjectVersion",
                      "s3:GetBucketAcl",
                      "s3:GetObject",
                      "s3:GetObjectAcl",
                      "s3:GetObjectVersion",
                      "s3:GetObjectVersionAcl",
                      "s3:ListBucket",
                      "s3:PutObject",
                      "s3:PutObjectAcl",
                      "s3:PutObjectTagging"
                  ],
                  "Resource": [
                      "arn:aws:s3:::bright-travis-deploy/*"
                  ]
              }
          ]
      }
    

travis執行結果(略),直接看S3 Bucket

專案參考:
GitHub slack-demo
Travis CI slack-demo Builds


哇…今天「試」超~~~~~~久的…差點就在倒數第二天陣亡了。Orz

待續…


上一篇
= = 部門 Slack DevOps 頻道 GG了 > Travis to S3 II
下一篇
參加鐵人賽,其實是因為…
系列文
AWS高手同事離職後不止30天30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言