2

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.

2
  • 1
    Remember that the Github actions/cache is scoped to a particular branch (with some caveats for falling back to caches on the repo's default branch). So they may not be available for subsequent jobs if those jobs are created on a different branch. See elixirforum.com/t/using-github-action-cache/37922/4 for an example of caching artifacts in S3 for use by other branches. It would help with readability if your YAML retained the proper formatting. Commented Mar 16, 2021 at 13:01
  • Thanks for your answer. I confirm those will be used on the same branch. It is mostly to reduce build time. Commented Mar 16, 2021 at 13:20

2 Answers 2

0

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/[email protected]
        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
Sign up to request clarification or add additional context in comments.

3 Comments

True I do this on ubuntu for the UT but my issue is wheb you build within a container. I cannot cache becaus maybe it does not mount a volume to the underlying machine? I would like to build on Alpine to deploy an Alpine container.
Are you needing something more like github.com/marketplace/actions/docker-layer-caching ?
Basically the issue comes from runs-on: ubuntu-20.04 container: elixir:1.11-alpine --< this (I I build on the bare VM (ubuntu) the cache is working but inside the container nope (I am looking inot documentation they seems to mount a workspace volume but does not semm to work) The question is what should I put in path: of the cahce
0

I just encountered the same issue, where caching worked fine with a normal runner but failed when running inside a container. I found the answer here. Summary: install the zstd package before invoking the cache action.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.