-
Notifications
You must be signed in to change notification settings - Fork 6
104 lines (94 loc) · 4.12 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: build and push image
on:
workflow_dispatch:
inputs:
branch:
description: 'Build Docs Version From Branch, only main'
required: true
default: 'main'
jobs:
build:
runs-on: ubuntu-latest
steps:
- id: checkout
uses: actions/checkout@v3
with:
ref: ${{ inputs.branch }}
- name: branch status
run: |
git status
- name: Prepare
id: prep
run: |
COMMIT_ID=$(git rev-parse HEAD)
SHORT_COMMIT_ID=$(git rev-parse --short HEAD)
ACR_REGISTRY=registry.cn-hangzhou.aliyuncs.com
ACR_NAMESPACE=ack-cos
ACR_IMAGE_NAME=matrixonecloud-docs.cn
ACR_IMAGE_TAG=${{ inputs.branch }}_${COMMIT_ID}
# Set output parameters.
# https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
echo "commit_id=${COMMIT_ID}" >> $GITHUB_OUTPUT
echo "short_commit_id=${SHORT_COMMIT_ID}" >> $GITHUB_OUTPUT
echo "acr_registry_name=${ACR_REGISTRY}" >> $GITHUB_OUTPUT
echo "acr_namespace=${ACR_NAMESPACE}" >> $GITHUB_OUTPUT
echo "acr_image_name=${ACR_IMAGE_NAME}" >> $GITHUB_OUTPUT
echo "acr_image_tag=${ACR_IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: show info on the ${{ inputs.branch }} branch, commit ${{ steps.prep.outputs.commit_id }}
id: branch_commit
env:
ACR_REGISTRY: ${{ steps.prep.outputs.acr_registry_name }}
ACR_NAMESPACE: ${{ steps.prep.outputs.acr_namespace }}
ACR_IMAGE_NAME: ${{ steps.prep.outputs.acr_image_name }}
ACR_IMAGE_TAG: ${{ steps.prep.outputs.acr_image_tag }}
run: |
echo "commit_id:${{ steps.prep.outputs.commit_id }}"
echo "short_commit_id:${{ steps.prep.outputs.short_commit_id }}"
echo "acr_registry_name:${{ env.ACR_REGISTRY }}"
echo "acr_namespace:${{ env.ACR_NAMESPACE }}"
echo "acr_image_name:${{ env.ACR_IMAGE_NAME }}"
echo "acr_image_tag:${{ env.ACR_IMAGE_TAG }}"
- name: Git Config
run: |
git fetch --all
git config --global user.email ${{ secrets.GITUSEREMAIL }}
git config --global user.name ${{ secrets.GITUSERNAME }}
- name: login to aliyun ACR
env:
ACR_REGISTRY: ${{ steps.prep.outputs.acr_registry_name }}
uses: aliyun/acr-login@v1
with:
login-server: ${{ env.ACR_REGISTRY }}
username: '${{ secrets.ALIYUN_DOCKER_USER }}'
password: '${{ secrets.ALIYUN_DOCKER_PASSWORD }}'
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Build ${{ inputs.branch }} && Push
uses: docker/build-push-action@v4
env:
ACR_REGISTRY: ${{ steps.prep.outputs.acr_registry_name }}
ACR_NAMESPACE: ${{ steps.prep.outputs.acr_namespace }}
ACR_IMAGE_NAME: ${{ steps.prep.outputs.acr_image_name }}
ACR_IMAGE_TAG: ${{ steps.prep.outputs.acr_image_tag }}
with:
context: . # remove git-context restriction https://github.com/docker/build-push-action#git-context
push: true
tags: |
${{ env.ACR_REGISTRY }}/${{ env.ACR_NAMESPACE }}/${{ env.ACR_IMAGE_NAME }}:${{ env.ACR_IMAGE_TAG }}
${{ env.ACR_REGISTRY }}/${{ env.ACR_NAMESPACE }}/${{ env.ACR_IMAGE_NAME }}:latest
- name: ALI ACR Image Name and Tag from branch ${{ inputs.branch }} ${{ steps.prep.outputs.short_commit_id }}
env:
REGISTRY: ${{ steps.prep.outputs.acr_registry_name }}
NAMESPACE: ${{ steps.prep.outputs.acr_namespace }}
IMAGE_NAME: ${{ steps.prep.outputs.acr_image_name }}
IMAGE_TAG: ${{ steps.prep.outputs.acr_image_tag }}
run: |
echo "${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}"
echo "${{ env.IMAGE_TAG }}"
echo "${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}"
- name: Log out of ALI ACR
env:
REGISTRY: ${{ steps.prep.outputs.acr_registry_name }}
if: always()
run: docker logout ${{ env.REGISTRY }}