From a88b31b693bd5c861d974f4e0b0bd79efd9c0633 Mon Sep 17 00:00:00 2001 From: ljing Date: Fri, 11 Dec 2020 22:49:36 +0800 Subject: [PATCH 1/6] Create alibabacloud.yml This workflow will build and push a new container image to Alibaba Cloud Container Reigstry (ACR), and then will deploy it to Alibaba Cloud Container Service for Kubernetes (ACK), when a release is created. --- ci/alibabacloud.yml | 118 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 ci/alibabacloud.yml diff --git a/ci/alibabacloud.yml b/ci/alibabacloud.yml new file mode 100644 index 0000000..2226613 --- /dev/null +++ b/ci/alibabacloud.yml @@ -0,0 +1,118 @@ +# This workflow will build and push a new container image to Alibaba Cloud Container Reigstry (ACR), +# and then will deploy it to Alibaba Cloud Container Service for Kubernetes (ACK), when a release is created. +# +# To use this workflow, you will need to complete the following set-up steps: +# +# 1. Create an ACR repository to store your container images. +# You can use ACR EE instance for more security and better performance. +# For instructions see https://www.alibabacloud.com/help/doc-detail/142168.htm +# +# 2. Create an ACK cluster to run your containerized application. +# You can use ACK Pro cluster for more security and better performance. +# For instructions see https://www.alibabacloud.com/help/doc-detail/95108.htm +# +# 3. Store your AccessKey pair in GitHub Actions secrets named `ACCESS_KEY_ID` and `ACCESS_KEY_SECRET`. +# For instructions on setting up secrets see: https://developer.github.com/actions/managing-workflows/storing-secrets/ +# +# 4. Change the values for the REGION_ID, REGISTRY, NAMESPACE, IMAGE, ACK_CLUSTER_ID, and ACK_DEPLOYMENT_NAME. +# + +name: Build and Deploy to ACK + +on: + release: + types: [created] + +# Environment variables available to all jobs and steps in this workflow. +env: + REGION_ID: cn-hangzhou + REGISTRY: registry.cn-hangzhou.aliyuncs.com + NAMESPACE: namespace + IMAGE: repo + TAG: ${{ github.sha }} + ACK_CLUSTER_ID: clusterID + ACK_DEPLOYMENT_NAME: nginx-deployment + + ACR_EE_REGISTRY: myregistry.cn-hangzhou.cr.aliyuncs.com + ACR_EE_INSTANCE_ID: instanceID + ACR_EE_NAMESPACE: namespace + ACR_EE_IMAGE: repo + ACR_EE_TAG: ${{ github.sha }} + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + # 1.1 Login to ACR + - name: Login to ACR with the AccessKey pair + uses: aliyun/acr-login@v1 + with: + region-id: "${{ env.REGION_ID }}" + access-key-id: "${{ secrets.ACCESS_KEY_ID }}" + access-key-secret: "${{ secrets.ACCESS_KEY_SECRET }}" + + # 1.2 Buid and push image to ACR + - name: Build and push image to ACR + run: | + docker build --tag "$REGISTRY/$NAMESPACE/$IMAGE:$TAG" . + docker push "$REGISTRY/$NAMESPACE/$IMAGE:$TAG" + + # 1.3 Scan image in ACR + - name: Scan image in ACR + uses: aliyun/acr-scan@v1 + with: + region-id: "${{ env.REGION_ID }}" + access-key-id: "${{ secrets.ACCESS_KEY_ID }}" + access-key-secret: "${{ secrets.ACCESS_KEY_SECRET }}" + repository: "${{ env.NAMESPACE }}/${{ env.IMAGE }}" + tag: "${{ env.TAG }}" + + # 2.1 (Optional) Login to ACR EE + - uses: actions/checkout@v2 + - name: Login to ACR EE with the AccessKey pair + uses: aliyun/acr-login@v1 + with: + login-server: "https://${{ env.ACR_EE_REGISTRY }}" + region-id: "${{ env.REGION_ID }}" + access-key-id: "${{ secrets.ACCESS_KEY_ID }}" + access-key-secret: "${{ secrets.ACCESS_KEY_SECRET }}" + instance-id: "${{ env.ACR_EE_INSTANCE_ID }}" + + # 2.2 (Optional) Build and push image ACR EE + - name: Build and push image to ACR EE + run: | + docker build -t "$ACR_EE_REGISTRY/$ACR_EE_NAMESPACE/$ACR_EE_IMAGE:$TAG" . + docker push "$ACR_EE_REGISTRY/$ACR_EE_NAMESPACE/$ACR_EE_IMAGE:$TAG" + # 2.3 (Optional) Scan image in ACR EE + - name: Scan image in ACR EE + uses: aliyun/acr-scan@v1 + with: + region-id: "${{ env.REGION_ID }}" + access-key-id: "${{ secrets.ACCESS_KEY_ID }}" + access-key-secret: "${{ secrets.ACCESS_KEY_SECRET }}" + instance-id: "${{ env.ACR_EE_INSTANCE_ID }}" + repository: "${{ env.ACR_EE_NAMESPACE}}/${{ env.ACR_EE_IMAGE }}" + tag: "${{ env.ACR_EE_TAG }}" + + # 3.1 Set ACK context + - name: Set K8s context + uses: aliyun/ack-set-context@v1 + with: + access-key-id: "${{ secrets.ACCESS_KEY_ID }}" + access-key-secret: "${{ secrets.ACCESS_KEY_SECRET }}" + cluster-id: "${{ env.ACK_CLUSTER_ID }}" + + # 3.2 Deploy the image to the ACK cluster + - name: Set up Kustomize + run: |- + curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash /dev/stdin 3.8.6 + - name: Deploy + run: |- + ./kustomize edit set image REGISTRY/NAMESPACE/IMAGE:TAG=$REGISTRY/$NAMESPACE/$IMAGE:$TAG + ./kustomize build . | kubectl apply -f - + kubectl rollout status deployment/$ACK_DEPLOYMENT_NAME + kubectl get services -o wide From a921a9e19d1a3e6bf74ec10808dd9ad38bc5a34a Mon Sep 17 00:00:00 2001 From: ljing Date: Fri, 11 Dec 2020 23:02:57 +0800 Subject: [PATCH 2/6] Update alibabacloud.yml --- ci/alibabacloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/alibabacloud.yml b/ci/alibabacloud.yml index 2226613..5d457d6 100644 --- a/ci/alibabacloud.yml +++ b/ci/alibabacloud.yml @@ -1,4 +1,4 @@ -# This workflow will build and push a new container image to Alibaba Cloud Container Reigstry (ACR), +# This workflow will build and push a new container image to Alibaba Cloud Container Registry (ACR), # and then will deploy it to Alibaba Cloud Container Service for Kubernetes (ACK), when a release is created. # # To use this workflow, you will need to complete the following set-up steps: From b3f8b48094362f3348ce6b9906b17bc58f6284cc Mon Sep 17 00:00:00 2001 From: ljing Date: Fri, 11 Dec 2020 23:17:45 +0800 Subject: [PATCH 3/6] Create alibabacloud.properties.json --- alibabacloud.properties.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 alibabacloud.properties.json diff --git a/alibabacloud.properties.json b/alibabacloud.properties.json new file mode 100644 index 0000000..67de4c1 --- /dev/null +++ b/alibabacloud.properties.json @@ -0,0 +1,7 @@ +{ + "name": "Deploy to Alibaba Cloud ACK", + "description": "Deploy a container to Alibaba Cloud Container Service for Kubernetes (ACK).", + "creator": "Alibaba Cloud", + "iconName": "acr", + "categories": null +} From 08c2049aede657b06d8e398a0bc0b192cdf0d5bd Mon Sep 17 00:00:00 2001 From: ljing Date: Fri, 11 Dec 2020 23:26:26 +0800 Subject: [PATCH 4/6] Create alibabacloud.properties.json --- ci/properties/alibabacloud.properties.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 ci/properties/alibabacloud.properties.json diff --git a/ci/properties/alibabacloud.properties.json b/ci/properties/alibabacloud.properties.json new file mode 100644 index 0000000..bbee6df --- /dev/null +++ b/ci/properties/alibabacloud.properties.json @@ -0,0 +1,7 @@ +{ + "name": "Deploy to Alibaba Cloud ACK", + "description": "Deploy a container to Alibaba Cloud Container Service for Kubernetes (ACK).", + "creator": "Alibaba Cloud", + "iconName": "alibabacloud", + "categories": null +} From 90f8fd731d8251d8e803773036ddb9a817623548 Mon Sep 17 00:00:00 2001 From: ljing Date: Fri, 11 Dec 2020 23:39:46 +0800 Subject: [PATCH 5/6] Add icon --- icons/alibabacloud.svg | 1 + 1 file changed, 1 insertion(+) create mode 100644 icons/alibabacloud.svg diff --git a/icons/alibabacloud.svg b/icons/alibabacloud.svg new file mode 100644 index 0000000..c7acdab --- /dev/null +++ b/icons/alibabacloud.svg @@ -0,0 +1 @@ +AlibabacloudLogoGithub \ No newline at end of file From 14547bfc7977a2c28ac1914328643a671778dd7a Mon Sep 17 00:00:00 2001 From: ljing Date: Fri, 11 Dec 2020 23:40:14 +0800 Subject: [PATCH 6/6] Delete alibabacloud.properties.json --- alibabacloud.properties.json | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 alibabacloud.properties.json diff --git a/alibabacloud.properties.json b/alibabacloud.properties.json deleted file mode 100644 index 67de4c1..0000000 --- a/alibabacloud.properties.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "Deploy to Alibaba Cloud ACK", - "description": "Deploy a container to Alibaba Cloud Container Service for Kubernetes (ACK).", - "creator": "Alibaba Cloud", - "iconName": "acr", - "categories": null -}