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

相关推荐
绝无仅有1 天前
腾讯面试文章解析:MySQL慢查询,存储引擎,事务,结构算法等总结与实战
后端·面试·github
逛逛GitHub1 天前
这个 OCR 开源项目天花板,杀疯了。
github
徐sir(徐慧阳)1 天前
搭建属于自己的网站HEXO静态页(二)发布网站到gihub
服务器·node.js·github·hexo
哈喽哈喽哈喽~1 天前
推送文件到github ---服务器关键配置内容
运维·服务器·经验分享·github
Bruce-li__1 天前
CI/CD流水线全解析:从概念到实践,结合Python项目实战
开发语言·python·ci/cd
技术爬爬虾1 天前
AI编程新王Codex详细攻略,一期视频精通,附免费使用方法
程序员·github
散峰而望1 天前
基本魔法语言分支和循环 (二) (C语言)
c语言·开发语言·github·visual studio
期待のcode1 天前
gitee与github远程仓库
gitee·github
半桔2 天前
【IO多路转接】IO 多路复用之 select:从接口解析到服务器实战
linux·服务器·c++·github·php
Moment2 天前
为什么 Electron 项目推荐使用 Monorepo 架构 🚀🚀🚀
前端·javascript·github