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

Codespaces proof-of-concept #208

Merged
merged 17 commits into from
Nov 8, 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
32 changes: 32 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "dbt",
"image": "mcr.microsoft.com/devcontainers/python:1-3.10-bookworm",
"features": {
"ghcr.io/devcontainers-contrib/features/poetry:2": {},
"ghcr.io/devcontainers/features/terraform:1": {}
},
"customizations": {
"vscode": {
"settings": {
"dbt.queryLimit": 50,
"git.allowNoVerifyCommit": true,
"python.defaultInterpreterPath": ".venv/bin/python"
},
"extensions": [
"innoverio.vscode-dbt-power-user"
]
}
},
"secrets": {
"SNOWFLAKE_USER": {
"description": "Your Snowflake Username"
},
"SNOWFLAKE_PASSWORD": {
"description": "Your Snowflake Password"
},
"DBT_SCHEMA": {
"description": "The dev schema into which to build your dbt models (e.g. DBT_<YOURNAME>)"
}
Comment on lines +21 to +29
Copy link
Member Author

Choose a reason for hiding this comment

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

These are the secrets that you need to set in order to do dbt-related work in the codespace

},
"postCreateCommand": "poetry config virtualenvs.in-project true && poetry install && poetry run pre-commit install && mkdir -p ~/.dbt && cp .devcontainer/profiles.yml ~/.dbt"
}
14 changes: 14 additions & 0 deletions .devcontainer/profiles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
dse_snowflake:
target: snowflake_dev
outputs:
snowflake_dev:
type: snowflake
account: heb41095
authenticator: username_password_mfa
user: "{{ env_var('SNOWFLAKE_USER') }}"
password: "{{ env_var('SNOWFLAKE_PASSWORD') }}"
role: TRANSFORMER_DEV
warehouse: TRANSFORMING_XS_DEV
database: TRANSFORM_DEV
schema: "{{ env_var('DBT_SCHEMA') }}"
threads: 4
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ repos:
hooks:
- name: Dbt deps
id: dbt-deps
language: python
entry: dbt deps --project-dir=transform
language: system
entry: poetry run dbt deps --project-dir transform
Copy link
Member Author

Choose a reason for hiding this comment

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

Caught some real bugs in the pre-commit set-up when doing this!

always_run: false
pass_filenames: false
types: [sql]
Expand All @@ -103,7 +103,7 @@ repos:
hooks:
- id: sqlfluff
name: sqlfluff
language: python
language: system
description: "Lints sql files with `SQLFluff`"
types: [sql]
require_serial: true
Expand Down
54 changes: 54 additions & 0 deletions docs/codespaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Developing using Codespaces

GitHub Codespaces allow you to spin up an ephemeral development environment in VS Code
which includes a git repository, configurations, and pre-installed libraries.
It provides an easy way for developers to get started working in a repository,
especially if they are uncomfortable

## Creating a Codespace

Go to the "Code" dropdown from the main repository page,
select the three dot dropdown, and select "New with options..."
This will allow more configuration than the default codespace.

![Create a new codespace](images/create-new-codespace.png)

In the codespace configuration form, you will have an option to add "Recommended Secrets".
This is where you can add your personal Snowflake credentials to your codespace,
allowing for development against our Snowflake warehouse, including using dbt.
You should only add credentials for accounts that are protected by multi-factor authentication (MFA).

![Add codespace secrets](images/codespace-secrets.png)

After you have added your secrets, click "Create Codespace".
Building it may take a few minutes,
but then you should be redirected to a VS Code environment in your browser.

## Launching an existing Codespace

Once your codespace is created, you should be able to launch it
without re-creating it every time using the "Code" dropdown,
going to "Open in...", and selecting "Open in browser":

![Launch codespace](images/launch-codespace.png)

## Using a Codespace

Once you have created and configured a codespace,
you have access to a relatively full-featured VS Code-based development environment.
This includes:

* An integrated bash terminal
* dbt profiles configured
* All Python dependencies for the project
* All pre-commit hooks installed
* git configured using your GitHub account

### Usage notes

1. When you launch a new codespace, it can take a couple of minutes for all of the extensions to install. In particular, this means that the Python environment may not be fully set-up when you land in VS Code. We recommend closing existing terminal sessions and starting a new one once the extensions have finished installing.
1. The first time you make a commit, the pre-commit hooks will be installed. This may take a few minutes. Subsequent commits will take less time.
1. If the pre-commit hooks fail when making a commit, it will give you the opportunity to open the git logs to view the errors. If you are unable to fix the errors for whatever reason, you can always make a new commit from the command line with `--no-verify`:
```bash
git commit --no-verify -m "Your commit message"
```
Binary file added docs/images/codespace-secrets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/create-new-codespace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/launch-codespace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/setup.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Repository setup

These are instructions for individual contributors to set up the repository locally.
For instructions on how to develop using GitHub Codespaces, see [here](./codespaces.md).

## Install dependencies

### 1. Set up a Python virtual environment
Expand Down
9 changes: 6 additions & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@ markdown_extensions:
nav:
- Introduction: index.md
- Project Setup: setup.md
- Codespaces: codespaces.md
- Code Review: code-review.md
- Writing Documentation: writing-documentation.md
- Naming Conventions: naming-conventions.md
- Security Guidelines: security.md
- Cloud Infrastructure: cloud-infrastructure.md
- dbt: dbt.md
- dbt Performance: dbt-performance.md
- Snowflake: snowflake.md
- Writing Documentation: writing-documentation.md
- dbt Snowflake Project: dbt_docs_snowflake/index.html
- New Project Setup: new-project-setup.md
- dbt:
- Overview: dbt.md
- dbt Performance: dbt-performance.md
- dbt Snowflake Project: dbt_docs_snowflake/index.html
- Data:
- Building Footprints: data/footprints.md
- Learning:
Expand Down