Skip to content

Commit 4c37922

Browse files
authored
Add devspace (#28)
* initial commit * remove ref to dockerized MS SQL container * consolidate Dockerfile * drop compose file * move to it's own dir * simplify * egg= be nuts * more settings * add more extensions * drop commented-out settings * add additional packages * move dbt power user to recommended * flatten structure? * add sqlfluff * formatting json * drop pylance preference * move to recommended * experiment * no longer needed bc env is set * auto start terminal with dbt build * add PR dbt version back for CI tests * oopsie type * add docs * Update README.md * Update README.md
1 parent a6c56f1 commit 4c37922

10 files changed

+415
-2
lines changed

.devcontainer.json

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Update the VARIANT arg in docker-compose.yml to pick a Python version: 3, 3.8, 3.7, 3.6
2+
{
3+
"name": "dbt",
4+
"dockerFile" : "Dockerfile",
5+
"settings": {
6+
"terminal.integrated.defaultProfile.linux#": "/bin/sh",
7+
"files.associations": {
8+
"*.sql": "jinja-sql",
9+
"*.sqlfluff": "ini",
10+
"*.yml": "yaml",
11+
"**/target/**": ""
12+
},
13+
"sql.linter.executablePath": "/usr/local/bin/sqlfluff",
14+
"sql.format.enable": true,
15+
"sql.linter.run": "onType",
16+
"files.exclude": {
17+
"**/.git": true,
18+
"**/.svn": true,
19+
"**/.hg": true,
20+
"**/CVS": true,
21+
"**/.DS_Store": true,
22+
"**/__pycache__": true
23+
},
24+
"findrelated.workspaceRulesets": [
25+
{
26+
"name": "sql",
27+
"rules": [
28+
{
29+
"pattern": "^(.*/)?models/(.*/)?(.+\\.sql)$",
30+
"locators": [
31+
"**/compiled/**/$3"
32+
]
33+
},
34+
{
35+
"pattern": "^(.*/)?compiled/(.*/)?(.+\\.sql)$",
36+
"locators": [
37+
"**/run/**/$3"
38+
]
39+
},
40+
{
41+
"pattern": "^(.*/)?run/(.*/)?(.+\\.sql)$",
42+
"locators": [
43+
"**/models/**/$3"
44+
]
45+
}
46+
]
47+
}
48+
],
49+
"findrelated.applyRulesets": [
50+
"sql"
51+
],
52+
"findrelated.applyWorkspaceRulesets": [
53+
"sql"
54+
],
55+
"workbench.editor.highlightModifiedTabs": true,
56+
"workbench.editor.labelFormat": "medium",
57+
"workbench.editor.revealIfOpen": true,
58+
"editor.rulers": [
59+
99
60+
]
61+
},
62+
"extensions": [
63+
"bastienboutonnet.vscode-dbt",
64+
"dorzey.vscode-sqlfluff",
65+
"editorconfig.editorconfig",
66+
"amodio.find-related",
67+
"ms-azuretools.vscode-docker",
68+
"ms-python.python",
69+
"visualstudioexptteam.vscodeintellicode",
70+
"samuelcolvin.jinjahtml"
71+
],
72+
73+
"remoteUser": "vscode"
74+
}

.sqlfluff

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[sqlfluff]
2+
3+
dialect = ansi

.sqlfluffignore

Whitespace-only changes.

.vscode/extensions.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
3+
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
4+
5+
// List of extensions which should be recommended for users of this workspace.
6+
"recommendations": [
7+
"innoverio.vscode-dbt-power-user",
8+
"mechatroner.rainbow-csv",
9+
"yzhang.markdown-all-in-one"
10+
],
11+
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
12+
"unwantedRecommendations": [
13+
14+
]
15+
}

.vscode/tasks.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"version": "2.0.0",
3+
"presentation": {
4+
"echo": false,
5+
"reveal": "always",
6+
"focus": false,
7+
"panel": "dedicated",
8+
"showReuseMessage": true
9+
},
10+
"tasks": [
11+
{
12+
// The name that shows up in terminal tab
13+
"label": "dbt",
14+
// The task will launch a shell
15+
"type": "shell",
16+
"command": "dbt build",
17+
// Mark as a background task to avoid the spinner animation on the terminal tab
18+
"isBackground": true,
19+
"problemMatcher": [],
20+
21+
// Try start the task on folder open
22+
"runOptions": {
23+
"runOn": "folderOpen"
24+
},
25+
// Create the tasks in a terminal group
26+
"presentation": {
27+
"panel": "shared",
28+
"close": false,
29+
}
30+
}
31+
]
32+
}

Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM mcr.microsoft.com/vscode/devcontainers/python:3.9
2+
3+
ARG USER_UID=1000
4+
ARG USER_GID=$USER_UID
5+
6+
RUN if [ "$USER_GID" != "1000" ] || [ "$USER_UID" != "1000" ]; then groupmod --gid $USER_GID vscode && usermod --uid $USER_UID --gid $USER_GID vscode; fi
7+
8+
RUN pwd
9+
RUN ls
10+
COPY requirements.txt /tmp/
11+
RUN pip3 install --upgrade pip
12+
RUN pip3 install --requirement /tmp/requirements.txt
13+
14+
ENV DBT_PROFILES_DIR=/workspaces/jaffle_shop_duckdb

README.md

+48
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,47 @@ dbt docs serve
158158
```
159159
</details>
160160

161+
<details>
162+
<summary>GitHub Codespaces / Dev Containers </summary>
163+
164+
#### Steps
165+
166+
1. Ensure you have Codespaces enabled for your GitHub organization or turned on as a beta feature if you're an individual user
167+
2. Click the green **Code** button on near the top right of the page of this repo's homepage (you may already be on it)
168+
3. Instead of cloning the repo like you normally would, intead select the **Codespaces** tab of the pop out, then "Create codespace on `duckdb`"
169+
![dbt_full_deploy_commands](images/open_in_codespaces.png)
170+
4. Wait for codespace to boot (~1 min?)
171+
5. Decide whether you'd like to use the Web IDE or open the codespace in your local environment
172+
6. When the codespace opens, a Task pane will show up and call `dbt build` just to show you how it's done
173+
7. Decide whether or not you'd like the **dbt Power User extension** installed
174+
8. Open up a new terminal and type `dbt build`!
175+
9. Explore some of the bells and whistles (see below)
176+
177+
If you don't have Codespaces or would like to just run the environment in a local Docker container, you can by:
178+
1. Having Docker Desktop installed
179+
2. Install the "Remote - Containers" extension"
180+
2. Clone the repo and open it in VSCode
181+
3. Click **Reopen in Container** and wait for container to spin up
182+
![Reopen in Container](https://user-images.githubusercontent.com/8158673/181360469-c6f3eb94-6b65-4a8f-93a0-3438d182ee66.png)
183+
4. Continue from step 6 above
184+
185+
186+
#### bells and whistles
187+
188+
There's some bells and whistles defined in the [.devcontainer.json]().devcontainer.json) that are worth calling out. Also a great reference is the [Setting up VSCode for dbt](https://dbt-msft.github.io/dbt-msft-docs/docs/guides/vscode_setup/) guide.
189+
190+
1. there is syntax highlighting provided by the `vdcode-dbt` extension. However, it is configured such that files in your `target/run` and `target/compiled` folder are not syntax highlighted, as a reminder that these files are not where you should be making changes!
191+
2. basic `sqlfluff` linting is enabled as you type. Syntax errors will be underlined in red at the error, and will also be surfaced in the **Problems** tab of the Terminal pane. It's configured to lint as you type.
192+
3. Autocompletion is enabled for generic dbt macros via the `vdcode-dbt` extension. For example, if you type `macro` you'll notice a pop up that you can select with the arrow keys then click tab to get a macro snippet.
193+
![image](https://user-images.githubusercontent.com/8158673/181362230-2c00d666-6131-4619-93aa-2e30d9c2bfea.png)
194+
![image](https://user-images.githubusercontent.com/8158673/181362274-fa7d71ff-07fc-4b4a-97c3-a0464fbe4c7d.png)
195+
4. the `find-related` extension allows an easy shortcut to navigating using `CMD`+`R`to jump from
196+
- a model file to it's corresponding compiled version,
197+
- from a compiled file to either the original model file or the version in `target/run`
161198

162199

200+
</details>
201+
163202
### Step-by-step explanation
164203

165204
To get up and running with this project:
@@ -247,6 +286,8 @@ To get up and running with this project:
247286
```
248287
</details>
249288

289+
290+
250291
*Why a 2nd activation of the virtual environment?*
251292
<details>
252293
<summary>This may not be necessary for many users, but might be for some. Read on for a first-person report from @dbeatty10.</summary>
@@ -392,6 +433,13 @@ This is a known issue in DuckDB. If you are using DBeaver, this means shutting d
392433
393434
Very worst-case, deleting the database file will get you back in action (BUT you will lose all your data).
394435
436+
437+
#### GitHub Codespaces and VSCode Remote Container
438+
439+
If you're using a privacy-forward browser such as Firefox and Brave, or a tracking-cookie-blocking extension like UBlock Origin or Privacy Badger, you may see the below error. You can either change your cookie settings, use a browser like Chrome, or just ignore the error because it doesn't affect the demo
440+
441+
![image](https://user-images.githubusercontent.com/8158673/181361459-294f807c-d990-4366-a4ab-d91cefcbc820.png)
442+
395443
---
396444
For more information on dbt:
397445
- Read the [introduction to dbt](https://docs.getdbt.com/docs/introduction)

0 commit comments

Comments
 (0)