一、Github Actions
1、ci.yml
name: CIon: [ push ]jobs:build:runs-on: ubuntu-lateststeps:- name: Checkout codeuses: actions/checkout@v3- name: Set up Gouses: actions/setup-go@v4with:go-version: 1.23.0- name: Cache Go modulesuses: actions/cache@v3with:path: |~/.cache/go-build~/go/pkg/modkey: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}restore-keys: |${{ runner.os }}-go-- name: Build Go projectrun: |go env -w CGO_ENABLED=0go env -w GOPROXY=https://goproxy.cn,directgo env -w GOPRIVATE=github.comgo mod tidygo build -trimpath -ldflags "-s -w" -o core_api api/core.gogo build -trimpath -ldflags "-s -w" -o core_rpc rpc/core.go- name: Verify core_api existsrun: |if [ ! -f core_api ]; thenecho "core_api file not found!"exit 1fi- name: Set up Docker Buildxuses: docker/setup-buildx-action@v2- name: Log in to Alibaba Cloud ACRenv:ACR_REGISTRY: ${{ secrets.ACR_REGISTRY }}ACR_USERNAME: ${{ secrets.ACR_USERNAME }}ACR_PASSWORD: ${{ secrets.ACR_PASSWORD }}run: echo $ACR_PASSWORD | docker login $ACR_REGISTRY -u $ACR_USERNAME --password-stdin- name: Build and push Docker image - APIenv:ACR_REGISTRY: ${{ secrets.ACR_REGISTRY }}run: |docker build -t $ACR_REGISTRY/【你的acr地址】:latest -f Dockerfile-api .docker push $ACR_REGISTRY/【你的acr地址】:latest- name: Build and push Docker image - RPCenv:ACR_REGISTRY: ${{ secrets.ACR_REGISTRY }}run: |docker build -t $ACR_REGISTRY/【你的acr地址】:latest -f Dockerfile-rpc .docker push $ACR_REGISTRY/【你的acr地址】:latest
2、添加 Secrets
这里有一个tabs,即:【Secrets】、【Variables】
我们需要根据 ci.yml中设置的进行对应的选择
我们需要根据 ci.yml 中的变量名进行赋值
- ACR_REGISTRY:registry.cn-beijing.aliyuncs.com
- ACR_USERNAME:xxxx
- ACR_PASSWORD:xxxx