【devops】Github Actions Secrets | 如何在Github中设置CI的Secret供CI的yaml使用

一、Github Actions

1、ci.yml

yaml 复制代码
name: CI

on: [ push ]


jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up Go
        uses: actions/setup-go@v4
        with:
          go-version: 1.23.0

      - name: Cache Go modules
        uses: actions/cache@v3
        with:
          path: |
            ~/.cache/go-build
            ~/go/pkg/mod
          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-

      - name: Build Go project
        run: |
          go env -w CGO_ENABLED=0
          go env -w GOPROXY=https://goproxy.cn,direct
          go env -w GOPRIVATE=github.com
          go mod tidy
          go build -trimpath -ldflags "-s -w" -o core_api api/core.go
          go build -trimpath -ldflags "-s -w" -o core_rpc rpc/core.go

      - name: Verify core_api exists
        run: |
          if [ ! -f core_api ]; then
            echo "core_api file not found!"
            exit 1
          fi
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Log in to Alibaba Cloud ACR
        env:
          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 - API
        env:
          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 - RPC
        env:
          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 中的变量名进行赋值

相关推荐
GoGeekBaird2 小时前
GoHumanLoopHub开源上线,开启Agent人际协作新方式
人工智能·后端·github
草梅友仁12 小时前
草梅 Auth 1.4.0 发布与 ESLint v9 更新 | 2025 年第 33 周草梅周报
vue.js·github·nuxt.js
寻月隐君13 小时前
硬核实战:从零到一,用 Rust 和 Axum 构建高性能聊天服务后端
后端·rust·github
CoderJia程序员甲17 小时前
GitHub 热榜项目 - 日榜(2025-08-16)
人工智能·ai·开源·github
python_13620 小时前
web请求和响应
java·spring·github
一只拉古1 天前
DevOps 的 Linux 基础(第一部分)
linux·自动化运维·devops
一宿君1 天前
Github 9 个惊艳的开源 NL2SQL 项目
sql·nlp·github
x10n91 天前
GitHub宕机时的应急协作方案
github
运维开发王义杰1 天前
YAML:锚点深度解析,告别重复,拥抱优雅的配置艺术
ci/cd·gitlab
SirLancelot12 天前
K8s-kubernetes(二)资源限制-详细介绍
微服务·云原生·容器·kubernetes·k8s·devops·kubelet