-
Notifications
You must be signed in to change notification settings - Fork 0
42 lines (39 loc) · 1.59 KB
/
docker-image-2.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
name: Docker Image CI
on:
push:
branches: [ main ] # 或者你希望运行build job的分支
tags-ignore: [ '*' ] # 忽略tag,这样在push时不会触发package job
create: # 当创建一个新的tag时触发workflow
tags: [ 'p*' ] # 对所有tags触发
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: load source code
uses: actions/checkout@v4
- name: Setup Node.js 18
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install dependencies
run: npm install # Replace with your package manager if needed (e.g., yarn install)
- name: Build project # Add your specific build command here (e.g., npm run build)
run: npm run build
package:
runs-on: ubuntu-latest
needs: build # package job需要在build job之后运行
if: github.event_name == 'create' && startsWith(github.ref, 'refs/tags/') # 仅当触发事件是创建tag时运行
steps:
- name: Login to Aliyun Container Registry (ACR)
uses: aliyun/acr-login@v1 # 使用阿里云镜像服务action
with:
login-server: registry.cn-zhangjiakou.aliyuncs.com
region-id: cn-zhangjiakou
username: "${{ secrets.REGISTRY_USERNAME }}"
password: "${{ secrets.REGISTRY_PASSWORD }}"
- name: Build and Push Docker Image
run: |
pwd
ls
docker build -t registry.cn-zhangjiakou.aliyuncs.com/homek8s/mtt-assistant:${{ github.ref_name }} .
docker push registry.cn-zhangjiakou.aliyuncs.com/homek8s/mtt-assistant:${{ github.ref_name }}