GitHub Actions中ubuntu-latest是什么?与部署服务器Ubuntu是否有关?
GitHub Actions
runs-on 配置说明 核心结论:jobs.<job_id>.runs-on 配置的是工作流任务的执行运行器(Runner)环境,和你最终要部署的目标服务器没有直接关联。
各取值含义解释
ubuntu-latest:指使用GitHub官方托管的运行器,是GitHub免费提供的临时虚拟机,预装了最新稳定版Ubuntu系统以及常用的开发、构建工具,你工作流中定义的所有步骤(拉取代码、执行脚本、编译打包等)都会在这个虚拟机上运行,任务执行完成后虚拟机会被自动销毁,不会留存数据。self-hosted:指使用你自行托管的运行器,你可以在自己的服务器、本地设备上部署Runner服务,工作流的任务会直接在你自己的设备上执行,适合处理敏感数据、有特殊硬件需求或需要节省官方运行器配额的场景。
和目标部署服务器的关系
你配置的运行器环境和最终要部署的目标Ubuntu服务器是完全独立的两套环境:
你完全可以在ubuntu-latest的官方运行器上完成代码的编译、打包操作,再通过SSH、部署工具等把构建好的产物推送到你的目标服务器上即可,哪怕目标服务器的操作系统和运行器不一致,只要你构建出来的产物兼容目标服务器的运行环境就可以正常运行。
你当前YAML代码的小修正
你提供的代码中run字段缩进有误,需要和同级的name保持一致缩进,修正后的完整代码如下:
name: CI # Controls when the workflow will run on: # Triggers the workflow on push or pull request events but only for the master branch push: branches: [ master ] pull_request: branches: [ master ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" build: # The type of runner that the job will run on runs-on: ubuntu-latest # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 # Runs a single command using the runners shell - name: Run a one-line script run: echo Hello, world! # Runs a set of commands using the runners shell - name: Run a multi-line script run: | echo Add other actions to build, echo test, and deploy your project.
内容的提问来源于stack exchange,提问作者Maik Lowrey
相关产品推荐
相关产品推荐

