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

相关推荐
semantist@语校9 小时前
语校网500所里程碑:日本语言学校数据库的标准化与可追溯机制
大数据·数据库·人工智能·百度·语言模型·oracle·github
CoderJia程序员甲21 小时前
GitHub 热榜项目 - 日榜(2025-10-01)
ai·开源·github·ai编程·github热榜
Elastic 中国社区官方博客1 天前
CI/CD 流水线与 agentic AI:如何创建自我纠正的 monorepos
大数据·运维·数据库·人工智能·搜索引擎·ci/cd·全文检索
紫钺-高山仰止1 天前
【Pyzmq】python 跨进程线程通信 跨平台跨服务器通信
服务器·python·github
芥子沫1 天前
GitHub 使用技巧
github·使用技巧·代码管理
Lin_Aries_04211 天前
基于 CI/CD(Jenkins)将 Spring Boot 应用自动部署到 Kubernetes 集群
spring boot·ci/cd·docker·容器·自动化·jenkins
圆肖1 天前
[陇剑杯 2021]简单日志分析(问3)
前端·经验分享·github
Akshsjsjenjd1 天前
Nginx 访问控制、用户认证、HTTPS配置实操手册
nginx·https·github
uhakadotcom1 天前
入门教程:常用的 Python 第三方库:python-logstash
后端·面试·github
绝无仅有1 天前
资深面试之MySQL 问题及解答(一)
后端·面试·github