You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Cloud-init中跳过GitHub Actions Runner注册的三次回车交互

解决GitHub Actions Runner注册的交互自动化问题

要自动跳过config.sh执行时的三次回车交互,只需给命令添加--unattended参数——这个参数会让Runner以非交互式模式完成注册,自动接受默认的工作目录、服务条款等选项。

修改后的Cloud-init文件

同时修正了原文件里的格式错误(比如curl的-L后缺空格、SHA256校验字符串格式问题),优化了部分命令的冗余操作:

#cloud-config
runcmd:
- mkdir react
- cd react
- curl -o actions-runner-linux-x64-2.300.2.tar.gz -L https://github.com/actions/runner/releases/download/v2.300.2/actions-runner-linux-x64-2.300.2.tar.gz
- echo "ed5bf2799c1ef7b2dd607df66e6b676dff8c44fb359c6fedc9ebf7db53339f0c  actions-runner-linux-x64-2.300.2.tar.gz" | shasum -a 256 -c
- tar xzf ./actions-runner-linux-x64-2.300.2.tar.gz
# 添加--unattended参数跳过注册交互
- ./config.sh --url https://github.com/yuuval/react-deploy-aws --token AVYXWHVAXX2TB4J63XBJCIDDYB6TA --unattended
- sudo ./svc.sh install
- sudo ./svc.sh start
# 加-y参数避免nginx安装时的交互确认
- sudo apt install nginx -y
# 简化目录跳转命令
- cd /home/ubuntu/react/_work/react-deploy-aws/react-deploy-aws
- cd /etc/nginx/sites-available
- sudo rm default
# 格式化nginx配置内容,避免换行混乱
- echo 'server {
    listen 80 default_server;
    server_name _;
    location / {
        root /home/ubuntu/react/_work/react-deploy-aws/react-deploy-aws/build;
        try_files $uri /index.html;
    }
}' | sudo tee /etc/nginx/sites-available/default
- sudo service nginx restart
# 递归设置权限,替代逐个目录执行chmod
- sudo chmod -R +x /home/ubuntu/react/_work

Terraform文件的小修正

原provider配置里的region填了可用区us-east-1b,应该改为区域名us-east-1:

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "~> 4.16"
    }
  }
  required_version = ">= 1.2.0"
}

provider "aws" {
  region = "us-east-1" # 修正为区域名,而非可用区
}

data "template_file" "nginx" {
  template = file("./cloud-init.yaml")
}

resource "aws_security_group" "gradebook" {
  name        = "gradebook"
  description = "Security group for Gradebook server"

  ingress {
    protocol    = "tcp"
    from_port   = 22
    to_port     = 22
    cidr_blocks = ["0.0.0.0/0"]
  }

  ingress {
    protocol    = "tcp"
    from_port   = 80
    to_port     = 80
    cidr_blocks = ["0.0.0.0/0"]
  }

  ingress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }

  ingress {
    protocol    = "tcp"
    from_port   = 443
    to_port     = 443
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    protocol    = "-1"
    from_port   = 0
    to_port     = 0
    cidr_blocks = ["0.0.0.0/0"]
  }
}

resource "aws_instance" "web_server" {
  ami           = "ami-0574da719dca65348"
  instance_type = "t2.small"
  vpc_security_group_ids = [aws_security_group.gradebook.id]
  user_data     = data.template_file.nginx.rendered

  tags = {
    Name = "GradebookWebServer"
  }
}

补充说明

  1. --unattended参数会自动使用当前目录作为Runner工作目录,默认接受GitHub服务条款,完全跳过注册环节的交互
  2. 给apt install加-y是为了避免安装软件时的确认提示
  3. 用chmod -R递归设置权限,比逐个目录执行更高效,也避免遗漏

内容的提问来源于stack exchange,提问作者crvxッ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 23:50:25