digger
digger copied to clipboard
Caching of terraform dependencies
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
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
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.
Assuming acceptable I can look into updating the documentation around it as applicable.
@ZIJ any thoughts?
@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.
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
Just checking in on this one to see how the internal testing might be going?
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! :)