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

Conversation

jeancochrane
Copy link
Contributor

@jeancochrane jeancochrane commented Aug 18, 2023

Three problems that emerged out of merging the data catalog branch into master (#78):

  1. Docs are not deploying because we neglected to set up environment variables properly for the prod context
  2. Updating the dbt cache can fail due to a naive mv call that is not actually performing the correct directory renaming
  3. $MODIFIED_RESOURCES_ONLY can be set to false when we want it to be true in cases where we have to restore the cache from the restore-keys fallback

This PR fixes those three problems.

Comment on lines +34 to +35
- name: Configure dbt environment
uses: ./.github/actions/configure_dbt_environment
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

@jeancochrane jeancochrane force-pushed the jeancochrane/fix-dbt-prod-deploy-problems branch from e31e62e to 068ddad Compare August 18, 2023 19:22
Comment on lines -84 to -87
- name: Move dbt manifest directory to update cache
run: mv "$TARGET_DIR" "$STATE_DIR"
working-directory: ${{ env.PROJECT_DIR }}
shell: bash
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.

Comment on lines +36 to +38
# 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
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.

Comment on lines +48 to +55
# 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
)
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!

@jeancochrane jeancochrane marked this pull request as ready for review August 18, 2023 19:37
@jeancochrane jeancochrane requested a review from a team as a code owner August 18, 2023 19:37
Comment on lines +34 to +35
- name: Configure dbt environment
uses: ./.github/actions/configure_dbt_environment
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

Comment on lines +48 to +55
# 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
)
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!

@jeancochrane jeancochrane merged commit cda69a8 into master Aug 18, 2023
3 checks passed
@jeancochrane jeancochrane deleted the jeancochrane/fix-dbt-prod-deploy-problems branch August 18, 2023 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants