Skip to content

Commit cf1b42b

Browse files
committed
chore: refactor GitHub Actions workflow to streamline ACR login and update Docker login actions
1 parent db875d0 commit cf1b42b

1 file changed

Lines changed: 23 additions & 32 deletions

File tree

.github/workflows/build.yaml

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77

88
env:
99
GIT_COMMIT: ${{ github.sha }}
10+
ACR_INSTANCE_ID: cri-0jrfa7tkgiwjzabf
1011

1112
permissions:
1213
contents: read
@@ -44,36 +45,12 @@ jobs:
4445
with:
4546
platforms: all
4647

47-
- uses: aliyun/configure-aliyun-credentials-action@v1
48-
id: aliyun-auth
49-
with:
50-
role-to-assume: "acs:ram::5621254376179407:role/docker"
51-
oidc-provider-arn: "acs:ram::5621254376179407:oidc-provider/github"
52-
role-session-name: "github-action-session"
53-
role-session-expiration: 1800
54-
audience: "sts.aliyuncs.com"
55-
5648
- name: Login to DockerHub
57-
uses: docker/login-action@v2
49+
uses: docker/login-action@v3
5850
with:
5951
username: ${{ secrets.DOCKERHUB_USERNAME }}
6052
password: ${{ secrets.DOCKERHUB_TOKEN }}
6153

62-
- name: Login to ghcr
63-
uses: docker/login-action@v2
64-
with:
65-
registry: ghcr.io
66-
username: ${{ github.actor }}
67-
password: ${{ github.token }}
68-
69-
- name: Login to ACR
70-
id: login-acr
71-
uses: aliyun/acr-login@v2.0.1
72-
with:
73-
login-server: https://container-registry.us-east-1.cr.aliyuncs.com
74-
region-id: "us-east-1"
75-
instance-id: cri-0jrfa7tkgiwjzabf
76-
7754
- name: Build and push
7855
uses: docker/bake-action@v5
7956
with:
@@ -118,25 +95,39 @@ jobs:
11895
audience: "sts.aliyuncs.com"
11996

12097
- name: Login to DockerHub
121-
uses: docker/login-action@v2
98+
uses: docker/login-action@v3
12299
with:
123100
username: ${{ secrets.DOCKERHUB_USERNAME }}
124101
password: ${{ secrets.DOCKERHUB_TOKEN }}
125102

126103
- name: Login to ghcr
127-
uses: docker/login-action@v2
104+
uses: docker/login-action@v3
128105
with:
129106
registry: ghcr.io
130107
username: ${{ github.actor }}
131108
password: ${{ github.token }}
132109

110+
- name: setup aliyun cli
111+
uses: aliyun/setup-aliyun-cli-action@v1
112+
113+
- name: get acr credential
114+
id: acr-cred
115+
run: |
116+
RESPONSE=$(aliyun cr GetAuthorizationToken --region us-east-1 --InstanceId ${{ env.ACR_INSTANCE_ID }})
117+
TEMP_USERNAME=$(echo "$RESPONSE" | jq -r '.TempUsername')
118+
AUTH_TOKEN=$(echo "$RESPONSE" | jq -r '.AuthorizationToken')
119+
120+
echo "::add-mask::$AUTH_TOKEN"
121+
122+
echo "username=$TEMP_USERNAME" >> $GITHUB_OUTPUT
123+
echo "password=$AUTH_TOKEN" >> $GITHUB_OUTPUT
124+
133125
- name: Login to ACR
134-
id: login-acr
135-
uses: aliyun/acr-login@v2.0.1
126+
uses: docker/login-action@v3
136127
with:
137-
login-server: https://container-registry.us-east-1.cr.aliyuncs.com
138-
region-id: "us-east-1"
139-
instance-id: cri-0jrfa7tkgiwjzabf
128+
registry: container-registry.us-east-1.cr.aliyuncs.com
129+
username: ${{ steps.acr-cred.outputs.username }}
130+
password: ${{ steps.acr-cred.outputs.password }}
140131

141132
- name: Build and push
142133
uses: docker/bake-action@v5

0 commit comments

Comments
 (0)