↓ 快轉到主要內容
Drone 自動打包Laravel imgae 並上傳到Google Cloud Registry(GCR)上
技術文章DockerGCP

Drone 自動打包Laravel imgae 並上傳到Google Cloud Registry(GCR)上

Posted by Alvin Chen on

Drone 自動打包Laravel imgae 並上傳到Google Cloud Registry(GCR)上

·652 字·2 分鐘
作者
Alvin Chen
相信寫 Code 可以改變世界

本篇主要是延伸上一篇 Drone 自動打包Laravel imgae 並上傳到docker hub上

的內容,將打包完成的docker image轉存到GCR上,有關Docker的建置方式請直接參考上一篇

其他參考文件:

http://plugins.drone.io/drone-plugins/drone-gcr/

OK,直接進入主題,要上傳到GCR上第一個步驟是需要到GCP上先產生憑證檔,讓Drone可以拿到憑證來上傳image

產生憑證檔
#

到GCP > API和憑證 點"建立憑證"

drone gcr

接著選擇服務帳戶

Drone GCR

輸入自訂的服務帳戶名稱後,按下建立

Drone GCR

接著選擇角色:

儲存空間 > Storage管理員 按下繼續

Drone GCR

接著按下"建立金鑰"

Drone GCR

右邊選單會跳出選項來,選擇JSON

Drone GCR

按下建立後,會跳出下載檔案,把JSON檔存下後續步驟會需要資訊

Drone Plugin : Drone GCR
#

這個plugin 是Drone docker 的延伸,其他參數可以參考Drone docker

範例中,我們跟上次一樣,把build好的image改上傳到GCR中

- name: publish_nginx
    image: plugins/gcr
    settings:
      registry: asia.gcr.io
      repo: PROJECT_ID/docker_compose_nginx_build
      tags: latest
      dockerfile: dockerfiles/dockerfile_for_nginx/Dockerfile
      json_key: >
        {
          "type": "service_account",
          "project_id": "XXX",
          "private_key_id": "XXX",
          "private_key": "XXX",
          "client_email": "access-storage@XXX.iam.gserviceaccount.com",
          "client_id": "XXX",
          "auth_uri": "https://accounts.google.com/o/oauth2/auth",
          "token_uri": "https://oauth2.googleapis.com/token",
          "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
          "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/access-storage%40XXX.iam.gserviceaccount.com"
        }

這個step中,

registry為asia.gcr.io是google cloud registry亞洲區的伺服器位置

repo 為 PROJECT_ID加上你的image name

json_key的內容就是我們上個步驟下載的JSON檔內容,貼上即可

以上全部完成後,只要將這個.drone.yml 隨著git push的github上就可以在image打包完成後直接上傳到GCR上了

上傳完成後,你就可以在GCP > container registry > 映像檔中 找到

Drone GCR

下一步,就要來完成透過上傳的image讓k8s 可以rolling update了