digger icon indicating copy to clipboard operation
digger copied to clipboard

Caching of terraform dependencies

Open ZIJ opened this issue 1 year ago • 8 comments

Digger feels slow; Francoi's suggestion is that we might not be using Github cache for terraform dependencies, so it always runs init from scratch

ZIJ avatar Nov 23 '23 12:11 ZIJ

assuming that digger is running terraform relatively standard, having a .terraformrc that has something like:

plugin_cache_dir   = "$HOME/.terraform.d/plugin-cache"

and then you use the cache restore/cache before/after digger runs in the pipeline should just work.

Or as an env variable:

PLUGIN_CACHE_DIR=$HOME/.terraform.d/plugin-cache

JoshuaJackson-jobvite avatar Mar 04 '24 18:03 JoshuaJackson-jobvite

Something like the following should work as an example:

name: Digger PR flow

on:
  pull_request:
    branches: ["main"]
    types: [closed, opened, synchronize, reopened]
  issue_comment:
    types: [created]
    if: startsWith(github.event.comment.body, 'digger')
  workflow_dispatch:

jobs:
  digger-job:
    runs-on: ubuntu-latest
    permissions:
      contents: write # required to merge PRs
      id-token: write # required for workload-identity-federation
      pull-requests: write # required to post PR comments
      statuses: write # required to validate combined PR status
      packages: read # required to read the packages
      actions: read
    steps:
      - name: create_cache_dir
        run: |
          mkdir -p $GITHUB_WORKSPACE/cache
      - uses: actions/cache/restore@v4
        id: restore_cache
        name: restore_cache
        with:
          path: ${{ github.workspace }}/cache
          key: ${{ runner.os }}-cache-${{ hashFiles('**/cache') }}
          restore-keys: |
            ${{ runner.os }}-cache-${{ hashFiles('**/cache') }}
            ${{ runner.os }}-cache
      - uses: diggerhq/[email protected]
        with:
          setup-aws: false
          no-backend: true
          disable-locking: true
          digger-hostname: "https://cloud.digger.dev"
          digger-organisation: "XXXX"
          digger-token: ${{ secrets.DIGGER_TOKEN }}
        env:
          GITHUB_OWNER: XXXXX
          TF_PLUGIN_CACHE_DIR: ${{ github.workspace }}/cache
      - uses: actions/cache/save@v4
        name: cache-save
        with:
          path: ${{ github.workspace }}/cache
          key: ${{ runner.os }}-${{ hashFiles('**/cache') }}

From my quick testing seems to be working.

JoshuaJackson-jobvite avatar Mar 04 '24 21:03 JoshuaJackson-jobvite

Assuming acceptable I can look into updating the documentation around it as applicable.

JoshuaJackson-jobvite avatar Mar 04 '24 21:03 JoshuaJackson-jobvite

@ZIJ any thoughts?

JoshuaJackson-jobvite avatar Mar 14 '24 16:03 JoshuaJackson-jobvite

@motatoes as this also relates to #142 should this be combined under just one of these...but also wanted to bring the proposal to your attention as well.

JoshuaJackson-jobvite avatar Mar 15 '24 22:03 JoshuaJackson-jobvite

Hey @JoshuaJackson-jobvite thanks a lot for this contribution ! This seems like an elegant solution and I think it would be great to have in our composite action

Would love to discuss with you a construction over slack:

Join me on Slack -- it’s a faster, simpler way to work. Sign up here, from any device: https://join.slack.com/t/diggertalk/shared_invite/zt-2f3j0ynm9-_tFTqgcqh_rPqfkFikPnLg

motatoes avatar Mar 16 '24 19:03 motatoes

Just checking in on this one to see how the internal testing might be going?

JoshuaJackson-jobvite avatar Mar 28 '24 15:03 JoshuaJackson-jobvite

Hey @JoshuaJackson-jobvite sorry got carried away with a big feature we are cooking. Once that's done in the next couple of days I will get around to this. It has not been forgotten! :)

motatoes avatar Mar 29 '24 09:03 motatoes