【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 中的变量名进行赋值

相关推荐
至善迎风2 小时前
版本管理系统与平台(权威资料核对、深入解析、行业选型与国产平台补充)
git·gitee·gitlab·github·svm
fengfuyao9853 小时前
诊断并修复SSH连接Github时遇到的“connection closed“错误
运维·ssh·github
NocoBase3 小时前
6 个替代 Jira 的开源项目管理工具推荐
低代码·开源·github
2301_803554524 小时前
github上传步骤
github
ruanCat5 小时前
使用 github workflow 的 actions/setup-node 工作流,安装 pnpm 失败的 bug
github
Moonbit5 小时前
月报Vol.03: 新增Bitstring pattern支持,构造器模式匹配增强
后端·算法·github
先做个垃圾出来………6 小时前
Github操作
github
止观止8 小时前
GitHub自动化利器:Probot框架实战指南
运维·自动化·github
戎码江湖8 小时前
使用CI/CD部署项目(前端Nextjs)
ci/cd·自动部署项目·自动部署前端项目·github部署项目·一键部署项目
掘我的金9 小时前
galgamex 容器化部署实战:从 Dockerfile、Compose 到 Prisma 初始化与首个账号
github