Skip to content

Commit

Permalink
Added devcontainer for easy environment setup (DataTalksClub#327)
Browse files Browse the repository at this point in the history
* Added .devcontainer

Updated comment, line 84 of Dockerfile

* Update README.md

Added links for devcontainer VS Code extension and general devcontainer docs
  • Loading branch information
MartyC-137 authored Feb 25, 2023
1 parent 52277cc commit 19ceb21
Show file tree
Hide file tree
Showing 6 changed files with 302 additions and 0 deletions.
93 changes: 93 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.177.0/containers/go/.devcontainer/base.Dockerfile

# [Choice] Go version (use -bullseye variants on local arm64/Apple Silicon): 1, 1.16, 1.17, 1-bullseye, 1.16-bullseye, 1.17-bullseye, 1-buster, 1.16-buster, 1.17-buster
ARG VARIANT=1-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT}

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# Install powershell
ARG PS_VERSION="7.2.1"
# powershell-7.3.0-linux-x64.tar.gz
# powershell-7.3.0-linux-arm64.tar.gz
RUN ARCH="$(dpkg --print-architecture)"; \
if [ "${ARCH}" = "amd64" ]; then \
PS_BIN="v$PS_VERSION/powershell-$PS_VERSION-linux-x64.tar.gz"; \
elif [ "${ARCH}" = "arm64" ]; then \
PS_BIN="v$PS_VERSION/powershell-$PS_VERSION-linux-arm64.tar.gz"; \
elif [ "${ARCH}" = "armhf" ]; then \
PS_BIN="v$PS_VERSION/powershell-$PS_VERSION-linux-arm32.tar.gz"; \
fi; \
wget https://github.com/PowerShell/PowerShell/releases/download/$PS_BIN -O pwsh.tar.gz; \
mkdir /usr/local/pwsh && \
tar Cxvfz /usr/local/pwsh pwsh.tar.gz && \
rm pwsh.tar.gz

ENV PATH=$PATH:/usr/local/pwsh

RUN echo 'deb http://download.opensuse.org/repositories/shells:/fish:/release:/3/Debian_11/ /' | tee /etc/apt/sources.list.d/shells:fish:release:3.list; \
curl -fsSL https://download.opensuse.org/repositories/shells:fish:release:3/Debian_11/Release.key | gpg --dearmor | tee /etc/apt/trusted.gpg.d/shells_fish_release_3.gpg > /dev/null; \
apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get install -y --no-install-recommends \
fish \
tmux \
fzf \
&& apt-get clean

ARG USERNAME=vscode

# Download the oh-my-posh binary
RUN mkdir /home/${USERNAME}/bin; \
wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-$(dpkg --print-architecture) -O /home/${USERNAME}/bin/oh-my-posh; \
chmod +x /home/${USERNAME}/bin/oh-my-posh; \
chown ${USERNAME}: /home/${USERNAME}/bin;

# NOTE: devcontainers are Linux-only at this time but when
# Windows or Darwin is supported someone will need to improve
# the code logic above.

# Setup a neat little PowerShell experience
RUN pwsh -Command Install-Module posh-git -Scope AllUsers -Force; \
pwsh -Command Install-Module z -Scope AllUsers -Force; \
pwsh -Command Install-Module PSFzf -Scope AllUsers -Force; \
pwsh -Command Install-Module Terminal-Icons -Scope AllUsers -Force;

# add the oh-my-posh path to the PATH variable
ENV PATH "$PATH:/home/${USERNAME}/bin"

# Can be used to override the devcontainer prompt default theme:
ENV POSH_THEME="https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/clean-detailed.omp.json"

# Deploy oh-my-posh prompt to Powershell:
COPY Microsoft.PowerShell_profile.ps1 /home/${USERNAME}/.config/powershell/Microsoft.PowerShell_profile.ps1

# Deploy oh-my-posh prompt to Fish:
COPY config.fish /home/${USERNAME}/.config/fish/config.fish

# Everything runs as root during build time, so we want
# to make sure the vscode user can edit these paths too:
RUN chmod 777 -R /home/${USERNAME}/.config

# Override vscode's own Bash prompt with oh-my-posh:
RUN sed -i 's/^__bash_prompt$/#&/' /home/${USERNAME}/.bashrc && \
echo "eval \"\$(oh-my-posh init bash --config $POSH_THEME)\"" >> /home/${USERNAME}/.bashrc

# Override vscode's own ZSH prompt with oh-my-posh:
RUN echo "eval \"\$(oh-my-posh init zsh --config $POSH_THEME)\"" >> /home/${USERNAME}/.zshrc

# Set container timezone:
ARG TZ="UTC"
RUN ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime

# Required for Python - Confluent Kafka on M1 Silicon
RUN apt update && apt -y install software-properties-common gcc
RUN git clone https://github.com/edenhill/librdkafka
RUN cd librdkafka && ./configure && make && make install && ldconfig

# [Optional] Uncomment the next line to use go get to install anything else you need
# RUN go get -x github.com/JanDeDobbeleer/battery

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
14 changes: 14 additions & 0 deletions .devcontainer/Microsoft.PowerShell_profile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Import-Module posh-git
Import-Module PSFzf -ArgumentList 'Ctrl+t', 'Ctrl+r'
Import-Module z
Import-Module Terminal-Icons

Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete

$env:POSH_GIT_ENABLED=$true
oh-my-posh init pwsh --config $env:POSH_THEME | Invoke-Expression

# NOTE: You can override the above env var from the devcontainer.json "args" under the "build" key.

# Aliases
Set-Alias -Name ac -Value Add-Content
58 changes: 58 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Devcontainer for DataTalksClub Data Engineering Zoomcamp
This devcontainer sets up a development environment for this class. This can be used with both VS Code and GitHub Codespaces.

## Getting Started
To continue, make sure you have [Visual Studio Code](https://code.visualstudio.com/) and [Docker Desktop](https://www.docker.com/products/docker-desktop/) installed OR use [GitHub Codespaces](https://github.com/features/codespaces).

**Option 1: Local VS Code**

1. Clone the repo and connect to it in VS Code:

```bash
$ cd your/desired/repo/location
$ git clone https://github.com/DataTalksClub/data-engineering-zoomcamp.git
```

1. Download the [`Dev Containers`](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension from the VS Code marketplace. Full docs on devcontainers [here](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)

2. Press Cmd + Shift + P (Mac) or Ctrl + Shift + P (Windows) to open the Command Pallette. Type in `Dev Containers: Open Folder in Container` and select the repo directory

3. Wait for the container to build and the dependencies to install

**Option 2: GitHub Codespaces**

1. Fork this repo

2. From the repo page in GitHub, select the green `<> Code` button and choose Codespaces

3. Click `Create Codespace on Main`, or checkout a branch if you prefer

4. Wait for the container to build and the dependencies to install

5. Start developing!


## Included Tools and Languages:

* `Python 3.9`
- `Pandas`
- `SQLAlchemy`
- `PySpark`
- `PyArrow`
- `Polars`
- `Prefect 2.7.7` and all required Python dependencies
- `confluent-kafka`
* `Google Cloud SDK`
* `dbt-core`
- `dbt-postgres`
- `dbt-bigquery`
* `Terraform`
* `Jupyter Notebooks for VS Code`
* `Docker`
* `Spark`
* `JDK` version 11
* [`Oh-My-Posh Powershell themes`](https://github.com/JanDeDobbeleer/oh-my-posh)
* Popular VS Code themes (GitHub, Atom One, Material Icons etc.)

## Customization
Feel free to modify the `Dockerfile`, `devcontainer.json` or `requirements.txt` file to include any other tools or packages that you need for your development environment. In the Dockerfile, you can customize the `POSH_THEME` environment variable with a theme of your choosing from [here](https://ohmyposh.dev/docs/themes)
4 changes: 4 additions & 0 deletions .devcontainer/config.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Activate oh-my-posh prompt:
oh-my-posh init fish --config $POSH_THEME | source

# NOTE: You can override the above env vars from the devcontainer.json "args" under the "build" key.
117 changes: 117 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.177.0/containers/go
{
"name": "oh-my-posh",
"build": {
"dockerfile": "Dockerfile",
"args": {
// Update the VARIANT arg to pick a version of Go: 1, 1.16, 1.17
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local arm64/Apple Silicon.
"VARIANT": "1.19-bullseye",
// Options:

"POSH_THEME": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/clean-detailed.omp.json",

// Override me with your own timezone:
"TZ": "America/Moncton",
// Use one of the "TZ database name" entries from:
// https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

"NODE_VERSION": "lts/*",
//Powershell version
"PS_VERSION": "7.2.7"
}
},
"runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],

"features": {
"ghcr.io/devcontainers/features/azure-cli:1": {
"version": "latest"
},
"ghcr.io/devcontainers/features/python:1": {
"version": "3.9"
},
"ghcr.io/devcontainers-contrib/features/curl-apt-get:1": {},
"ghcr.io/devcontainers-contrib/features/terraform-asdf:2": {},
"ghcr.io/devcontainers-contrib/features/yamllint:2": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/devcontainers-contrib/features/spark-sdkman:2": {
"jdkVersion": "11"
},
"ghcr.io/dhoeric/features/google-cloud-cli:1": {
"version": "latest"
}
},

// Set *default* container specific settings.json values on container create.
"customizations": {
"vscode": {
"settings": {
"go.toolsManagement.checkForUpdates": "local",
"go.useLanguageServer": true,
"go.gopath": "/go",
"go.goroot": "/usr/local/go",
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash"
},
"zsh": {
"path": "zsh"
},
"fish": {
"path": "fish"
},
"tmux": {
"path": "tmux",
"icon": "terminal-tmux"
},
"pwsh": {
"path": "pwsh",
"icon": "terminal-powershell"
}
},
"terminal.integrated.defaultProfile.linux": "pwsh",
"terminal.integrated.defaultProfile.windows": "pwsh",
"terminal.integrated.defaultProfile.osx": "pwsh",
"tasks.statusbar.default.hide": true,
"terminal.integrated.tabs.defaultIcon": "terminal-powershell",
"terminal.integrated.tabs.defaultColor": "terminal.ansiBlue",
"workbench.colorTheme": "GitHub Dark Dimmed",
"workbench.iconTheme": "material-icon-theme"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"actboy168.tasks",
"eamodio.gitlens",
"davidanson.vscode-markdownlint",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"github.vscode-pull-request-github",
"golang.go",
"ms-vscode.powershell",
"redhat.vscode-yaml",
"yzhang.markdown-all-in-one",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-toolsai.jupyter",
"akamud.vscode-theme-onedark",
"ms-vscode-remote.remote-containers",
"PKief.material-icon-theme",
"GitHub.github-vscode-theme"
]
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [3000],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pip3 install --user -r .devcontainer/requirements.txt --use-pep517",

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
16 changes: 16 additions & 0 deletions .devcontainer/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pandas==1.5.2
prefect==2.7.7
prefect-sqlalchemy==0.2.2
prefect-gcp[cloud_storage]==0.2.4
protobuf
pyarrow==10.0.1
pandas-gbq==0.18.1
psycopg2-binary==2.9.5
sqlalchemy==1.4.46
ipykernel
polars
dbt-core
dbt-bigquery
dbt-postgres
pyspark
confluent-kafka==1.9.2

0 comments on commit 19ceb21

Please sign in to comment.