首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >容器的Github Action Cache问题

容器的Github Action Cache问题
EN

Stack Overflow用户
提问于 2021-03-16 18:28:31
回答 1查看 374关注 0票数 1

我有一个简短的问题,但我找不到文档(也许这是不可能的),我如何从容器中检索已构建的内容(如下图所示):

代码语言:javascript
复制
prod-dependencies:
name: Production Dependencies
runs-on: ubuntu-20.04
container: elixir:1.11-alpine
env:
MIX_ENV: prod
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Retrieve Cached Dependencies
uses: actions/cache@v2
id: mix-prod-cache
with:
path: |
${{ github.workspace }}/deps
${{ github.workspace }}/_build
key: PROD-${{ hashFiles('mix.lock') }}
- name: Install Dependencies
if: steps.mix-prod-cache.outputs.cache-hit != 'true'
run: |
apk add build-base rust cargo
mix do local.hex --force, local.rebar --force, deps.get --only prod, deps.compile

我需要在阿尔卑斯山上构建,因为我在阿尔卑斯山和一些C库上部署的Erlang VM是不同的。

因此,这里是我构建依赖项的地方,我想将它们放在缓存中以供后续作业使用,但缓存永远不会被填充。根据GitHub文档,挂载一个带有容器的卷来检索工件,但我肯定没有使用它。

非常感谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2021-03-16 22:50:41

这是一个使用action/cache@v2的带有Postgres数据库的Elixir应用程序的Github工作流示例。请注意,它为恢复deps_build目录定义了两个独立的步骤。在此工作流中,mix deps.getmix compile步骤始终在运行:如果恢复缓存,则它们的执行速度应该会非常快。

改编自this workflow

代码语言:javascript
复制
name: Test

on:
  pull_request:
    branches:
      - develop
    paths-ignore:
      - 'docs/**'
      - '*.md'

jobs:
  test:

    name: Lint and test

    runs-on: ubuntu-18.04

    env:
      MIX_ENV: test

    services:
      db:
        image: postgres:11
        ports: ['5432:5432']
        env:
          POSTGRES_PASSWORD: postgres
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
      - uses: actions/checkout@v2
      - uses: erlef/setup-elixir@v1
        with:
          otp-version: '23.1.2'
          elixir-version: '1.11.2'

      - name: Configure SSH for private Repos
        uses: webfactory/ssh-agent@v0.4.1
        with:
          ssh-private-key: ${{ secrets.HEADLESS_PRIV }}

      - name: Restore the deps cache
        uses: actions/cache@v2
        id: deps-cache-restore
        with:
          path: deps
          key: ${{ runner.os }}-deps-mixlockhash-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
          restore-keys: |
            ${{ runner.os }}-deps-

      - name: Restore the _build cache
        uses: actions/cache@v2
        id: build-cache-restore
        with:
          path: _build
          key: ${{ runner.os }}-build-mixlockhash-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
          restore-keys: |
            ${{ runner.os }}-build-

      - name: Get/update Mix dependencies
        run: |
          mix local.hex --force
          mix local.rebar
          mix deps.get

      - name: Compile
        run: mix compile

      - name: Create database
        run: mix ecto.create

      - name: Migrate database
        run: mix ecto.migrate

      - name: Test
        run: mix test
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66653352

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档