ruby GitHub操作-跨作业共享服务

tzcvj98z  于 2023-02-18  发布在  Ruby
关注(0)|答案(1)|浏览(185)

我想知道如何在GitHub操作中的作业之间共享服务容器。在当前的工作流程中,容器在build步骤后被销毁。

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

env:
  RAILS_ENV: test
  RACK_ENV: test
  RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
  POSTGRES_PASSWORD: postgres15
  POSTGRES_USERNAME: postgres
  POSTGRES_HOST: localhost

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Initialize Ruby
        uses: ruby/setup-ruby@v1
        with:
          bundler-cache: true
      - name: Setup Rails
        run: bin/setup
    services:
      postgres:
        image: postgres:15.1-alpine
        ports:
          - 5432:5432
        env:
          POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
          POSTGRES_USER: ${{ env.POSTGRES_USERNAME }}
        # needed because the postgres container does not provide a healthcheck
        options: >-
          --health-cmd pg_isready 
          --health-interval 10s 
          --health-timeout 5s 
          --health-retries 5

  test:
    runs-on: ubuntu-latest
    needs: [ build ]
    steps:
      - name: Lint Ruby
        run: bundle exec rubocop
      - name: Run tests
        run: bin/rails test:all

  coverage:
    runs-on: ubuntu-latest
    needs: [ build, test ]
    steps:
      - uses: joshmfrankel/simplecov-check-action@main
        with:
          minimum_suite_coverage: 98
          minimum_file_coverage: 90
          github_token: ${{ secrets.GITHUB_TOKEN }}
          check_job_name: coverage
bqujaahr

bqujaahr1#

根据文档,您不能跨作业共享服务容器。
https://docs.github.com/en/actions/using-containerized-services/about-service-containers
您可以为工作流中的每个作业配置服务容器。GitHub为工作流中配置的每个服务创建一个新的Docker容器,并在作业完成时销毁该服务容器。作业中的步骤可以与同一作业中的所有服务容器通信。但是,您不能在复合操作中创建和使用服务容器。

相关问题