Skip to content

Commit 48ad450

Browse files
authored
Create alibabacloud.yml
1 parent f1eb67b commit 48ad450

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

.github/workflows/alibabacloud.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# This workflow will build and push a new container image to Alibaba Cloud Container Registry (ACR),
2+
# and then will deploy it to Alibaba Cloud Container Service for Kubernetes (ACK), when there is a push to the "master" branch.
3+
#
4+
# To use this workflow, you will need to complete the following set-up steps:
5+
#
6+
# 1. Create an ACR repository to store your container images.
7+
# You can use ACR EE instance for more security and better performance.
8+
# For instructions see https://www.alibabacloud.com/help/doc-detail/142168.htm
9+
#
10+
# 2. Create an ACK cluster to run your containerized application.
11+
# You can use ACK Pro cluster for more security and better performance.
12+
# For instructions see https://www.alibabacloud.com/help/doc-detail/95108.htm
13+
#
14+
# 3. Store your AccessKey pair in GitHub Actions secrets named `ACCESS_KEY_ID` and `ACCESS_KEY_SECRET`.
15+
# For instructions on setting up secrets see: https://developer.github.com/actions/managing-workflows/storing-secrets/
16+
#
17+
# 4. Change the values for the REGION_ID, REGISTRY, NAMESPACE, IMAGE, ACK_CLUSTER_ID, and ACK_DEPLOYMENT_NAME.
18+
#
19+
20+
name: Build and Deploy to ACK
21+
22+
on:
23+
push:
24+
branches: [ "master" ]
25+
26+
# Environment variables available to all jobs and steps in this workflow.
27+
env:
28+
REGION_ID: cn-hangzhou
29+
REGISTRY: registry.cn-hangzhou.aliyuncs.com
30+
NAMESPACE: namespace
31+
IMAGE: repo
32+
TAG: ${{ github.sha }}
33+
ACK_CLUSTER_ID: clusterID
34+
ACK_DEPLOYMENT_NAME: nginx-deployment
35+
36+
ACR_EE_REGISTRY: myregistry.cn-hangzhou.cr.aliyuncs.com
37+
ACR_EE_INSTANCE_ID: instanceID
38+
ACR_EE_NAMESPACE: namespace
39+
ACR_EE_IMAGE: repo
40+
ACR_EE_TAG: ${{ github.sha }}
41+
42+
permissions:
43+
contents: read
44+
45+
jobs:
46+
build:
47+
runs-on: ubuntu-latest
48+
environment: production
49+
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@v4
53+
54+
# 1.1 Login to ACR
55+
- name: Login to ACR with the AccessKey pair
56+
uses: aliyun/acr-login@v1
57+
with:
58+
region-id: "${{ env.REGION_ID }}"
59+
access-key-id: "${{ secrets.ACCESS_KEY_ID }}"
60+
access-key-secret: "${{ secrets.ACCESS_KEY_SECRET }}"
61+
62+
# 1.2 Build and push image to ACR
63+
- name: Build and push image to ACR
64+
run: |
65+
docker build --tag "$REGISTRY/$NAMESPACE/$IMAGE:$TAG" .
66+
docker push "$REGISTRY/$NAMESPACE/$IMAGE:$TAG"
67+
68+
# 1.3 Scan image in ACR
69+
- name: Scan image in ACR
70+
uses: aliyun/acr-scan@v1
71+
with:
72+
region-id: "${{ env.REGION_ID }}"
73+
access-key-id: "${{ secrets.ACCESS_KEY_ID }}"
74+
access-key-secret: "${{ secrets.ACCESS_KEY_SECRET }}"
75+
repository: "${{ env.NAMESPACE }}/${{ env.IMAGE }}"
76+
tag: "${{ env.TAG }}"
77+
78+
# 2.1 (Optional) Login to ACR EE
79+
- uses: actions/checkout@v4
80+
- name: Login to ACR EE with the AccessKey pair
81+
uses: aliyun/acr-login@v1
82+
with:
83+
login-server: "https://${{ env.ACR_EE_REGISTRY }}"
84+
region-id: "${{ env.REGION_ID }}"
85+
access-key-id: "${{ secrets.ACCESS_KEY_ID }}"
86+
access-key-secret: "${{ secrets.ACCESS_KEY_SECRET }}"
87+
instance-id: "${{ env.ACR_EE_INSTANCE_ID }}"
88+
89+
# 2.2 (Optional) Build and push image ACR EE
90+
- name: Build and push image to ACR EE
91+
run: |
92+
docker build -t "$ACR_EE_REGISTRY/$ACR_EE_NAMESPACE/$ACR_EE_IMAGE:$TAG" .
93+
docker push "$ACR_EE_REGISTRY/$ACR_EE_NAMESPACE/$ACR_EE_IMAGE:$TAG"
94+
# 2.3 (Optional) Scan image in ACR EE
95+
- name: Scan image in ACR EE
96+
uses: aliyun/acr-scan@v1
97+
with:
98+
region-id: "${{ env.REGION_ID }}"
99+
access-key-id: "${{ secrets.ACCESS_KEY_ID }}"
100+
access-key-secret: "${{ secrets.ACCESS_KEY_SECRET }}"
101+
instance-id: "${{ env.ACR_EE_INSTANCE_ID }}"
102+
repository: "${{ env.ACR_EE_NAMESPACE}}/${{ env.ACR_EE_IMAGE }}"
103+
tag: "${{ env.ACR_EE_TAG }}"
104+
105+
# 3.1 Set ACK context
106+
- name: Set K8s context
107+
uses: aliyun/ack-set-context@v1
108+
with:
109+
access-key-id: "${{ secrets.ACCESS_KEY_ID }}"
110+
access-key-secret: "${{ secrets.ACCESS_KEY_SECRET }}"
111+
cluster-id: "${{ env.ACK_CLUSTER_ID }}"
112+
113+
# 3.2 Deploy the image to the ACK cluster
114+
- name: Set up Kustomize
115+
run: |-
116+
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash /dev/stdin 3.8.6
117+
- name: Deploy
118+
run: |-
119+
./kustomize edit set image REGISTRY/NAMESPACE/IMAGE:TAG=$REGISTRY/$NAMESPACE/$IMAGE:$TAG
120+
./kustomize build . | kubectl apply -f -
121+
kubectl rollout status deployment/$ACK_DEPLOYMENT_NAME
122+
kubectl get services -o wide

0 commit comments

Comments
 (0)