Github Action Cache question with containers

Viewed 1000

I got a quick question and I can't find docs on it (maybe it is impossible) How can I retrieve what has been built from a container (like this) :

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

I need to build on Alpine since I am deploying on Alpine and some C libs are different for the Erlang VM to work.

So here it is the place where I build dependencies and I want to put them on cache for the subsequent jobs but the cache is never populated. According to doc GitHub mount a volume with containers to retrieve artifacts but I must miss use it.

Thanks a lot for your help.

1 Answers

Here is a sample Github workflow for an Elixir app with a Postgres database that utilizes the action/cache@v2. Note that it defines 2 separate steps for restoring the deps and _build directories. In this workflow, the mix deps.get and mix compile steps are always run: they should execute very quickly if the cache is restored.

Adapted from this workflow

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
Related