Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dbt production deploy problems #82

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions .github/workflows/build_and_test_dbt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,35 @@ jobs:
- name: Configure dbt environment
uses: ./.github/actions/configure_dbt_environment

- name: Cache dbt state directory
# We have to use the separate `restore`/`save` actions instead of the
# unified `cache` action because only `restore` provides access to the
# `cache-matched-key` and `cache-primary-key` outputs as of v3
Comment on lines +36 to +38
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a frustrating difference! Note the outputs of the restore action vs. the outputs of the cache action.

- name: Restore dbt state cache
id: cache
uses: actions/cache@v3
uses: actions/cache/restore@v3
with:
path: ${{ env.PROJECT_DIR }}/${{ env.STATE_DIR }}
key: ${{ env.CACHE_NAME }}-${{ env.CACHE_KEY }}
restore-keys: |
${{ env.CACHE_NAME }}-master

- if: ${{ steps.cache.outputs.cache-hit == 'true' }}
# If we restore the cache from the `restore-keys` key, the `cache-hit`
# output will be 'false' but the `cache-matched-key` output will be
# the name of the `restore-keys` key; we want to count this case as a hit
- if: |
steps.cache.outputs.cache-hit == 'true' ||
steps.cache.outputs.cache-matched-key == format(
'{0}-master', env.CACHE_NAME
)
Comment on lines +48 to +55
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This workflow run has three attempts where I tested each of the possible cases:

  1. Attempt #1: Branch cache exists; exact cache key hit ➡️ this block evaluates True
  2. Attempt #2: Deleted branch cache, but master branch cache exists; partial cache key hit ➡️ this block evaluates True
  3. Attempt #3: Deleted both branch cache and master branch cache; no cache key hit ➡️ this block evaluates False

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Sheesh, this is very confusing behavior. And weird that the actions maintainers don't provide access to the cache- vars in actions/cache. Nice work on the fast debugging!

name: Set command args to build/test modified resources
run: echo "MODIFIED_RESOURCES_ONLY=true" >> "$GITHUB_ENV"
shell: bash

- if: ${{ steps.cache.outputs.cache-hit != 'true' }}
- if: |
steps.cache.outputs.cache-hit != 'true' &&
steps.cache.outputs.cache-matched-key != format(
'{0}-master', env.CACHE_NAME
)
name: Set command args to build/test all resources
run: echo "MODIFIED_RESOURCES_ONLY=false" >> "$GITHUB_ENV"
shell: bash
Expand Down Expand Up @@ -81,7 +95,8 @@ jobs:
working-directory: ${{ env.PROJECT_DIR }}
shell: bash

- name: Move dbt manifest directory to update cache
run: mv "$TARGET_DIR" "$STATE_DIR"
working-directory: ${{ env.PROJECT_DIR }}
shell: bash
Comment on lines -84 to -87
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error in question:

Run mv "$TARGET_DIR" "$STATE_DIR"
mv: cannot move 'target' to 'state/target': Directory not empty
Error: Process completed with exit code 1.

Saving the cache explicitly with the actions/cache/save action resolves this problem.

- name: Update dbt state cache
uses: actions/cache/save@v3
with:
path: ${{ env.PROJECT_DIR }}/${{ env.TARGET_DIR }}
key: ${{ env.CACHE_NAME }}-${{ env.CACHE_KEY }}
3 changes: 3 additions & 0 deletions .github/workflows/deploy_dbt_docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
role-to-assume: ${{ secrets.AWS_IAM_ROLE_TO_ASSUME_ARN }}
aws-region: us-east-1

- name: Configure dbt environment
uses: ./.github/actions/configure_dbt_environment
Comment on lines +34 to +35
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error in question:

Run dbt docs generate --target "$TARGET"
18:26:[23](https://github.com/ccao-data/data-architecture/actions/runs/5905883640/job/16020814093#step:6:24)  Running with dbt=1.5.5
18:[26](https://github.com/ccao-data/data-architecture/actions/runs/5905883640/job/16020814093#step:6:27):23  Encountered an error:
Runtime Error
  The profile 'athena' does not have a target named ''. The valid target names for this profile are:
   - dev
   - ci
   - prod
Error: Process completed with exit code 2.

Previously we had been hardcoding the target "ci" so I hadn't noticed that we were missing this step.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I should've caught this too. Tricky tricky


- name: Generate docs
run: dbt docs generate --target "$TARGET"
working-directory: ${{ env.PROJECT_DIR }}
Expand Down