Quantcast
Channel: 小惡魔 – 電腦技術 – 工作筆記 – AppleBOY
Viewing all articles
Browse latest Browse all 325

用 GitHub Actions 上傳 Docker Image 到 AWS ECR

$
0
0

最近正打算使用 GitHub Actions 來串接 AWS 服務 (ECR + ECS),上網找了一堆 ECR 套件,發現就連 AWS 官方都只有實作 Login 進 ECR,後面編譯跟上傳動作就需要自己寫,可以看看底下是 AWS 官方套件的範例:

    - name: Login to Amazon ECR
      id: login-ecr
      uses: aws-actions/amazon-ecr-login@v1

    - name: Build, tag, and push image to Amazon ECR
      env:
        ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
        ECR_REPOSITORY: my-ecr-repo
        IMAGE_TAG: ${{ github.sha }}
      run: |
        docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
        docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

    - name: Logout of Amazon ECR
      if: always()
      run: docker logout ${{ steps.login-ecr.outputs.registry }}

覺得蠻神奇的是為什麼不把 Plugin 寫更完整些,讓使用者不用再執行 docker 指令,所以我直接把 Drone 官方套件直接改寫支援 GitHub Actions 服務,詳細的操作文件可以參考這邊

教學影片

如果對於課程內容有興趣,可以參考底下課程。

如果需要搭配購買請直接透過 FB 聯絡我,直接匯款(價格再減 100

使用方式

本篇會使用兩種 CI/CD 工具,分別是 DroneGitHub Actions,詳細檔案內容可以參考這邊。底下是使用 Drone CI/CD:

- name: publish
  pull: always
  image: plugins/ecr
  settings:
    access_key:
      from_secret: aws_access_key_id
    secret_key:
      from_secret: aws_secret_access_key
    repo: api-sample
    region: ap-northeast-1
    registry:
      from_secret: registry
    auto_tag: true
    daemon_off: false
    dockerfile: Dockerfile
  when:
    event:
      exclude:
      - pull_request

底下是使用 GitHub Actions

build:
  name: upload image
  runs-on: ubuntu-latest
  steps:
  - uses: actions/checkout@master
  - name: upload image to ECR
    uses: appleboy/docker-ecr-action@v0.0.2
    with:
      access_key: ${{ secrets.aws_access_key_id }}
      secret_key: ${{ secrets.aws_secret_access_key }}
      registry: ${{ secrets.registry }}
      cache_from: ${{ secrets.cache }}
      repo: api-sample
      region: ap-northeast-1

兩種使用方式都是一樣的,會用 Drone CI/CD,那使用 GitHub Actions 也不會有問題,另外還支援了 cache_from,省下了一點部署的時間,時間取決於跑的專案 Image 大小了。


Viewing all articles
Browse latest Browse all 325

Trending Articles


Girasoles para colorear


mayabang Quotes, Torpe Quotes, tanga Quotes


Tagalog Quotes About Crush – Tagalog Love Quotes


OFW quotes : Pinoy Tagalog Quotes


Long Distance Relationship Tagalog Love Quotes


Tagalog Quotes To Move on and More Love Love Love Quotes


5 Tagalog Relationship Rules


Best Crush Tagalog Quotes And Sayings 2017


Re:Mutton Pies (lleechef)


FORECLOSURE OF REAL ESTATE MORTGAGE


Sapos para colorear


tagalog love Quotes – Tiwala Quotes


Break up Quotes Tagalog Love Quote – Broken Hearted Quotes Tagalog


Patama Quotes : Tagalog Inspirational Quotes


Pamatay na Banat and Mga Patama Love Quotes


Tagalog Long Distance Relationship Love Quotes


BARKADA TAGALOG QUOTES


“BAHAY KUBO HUGOT”


Vimeo 10.7.0 by Vimeo.com, Inc.


Vimeo 10.7.1 by Vimeo.com, Inc.