Tips and Tricks
Accessing credentials
Because the DDE is simply a container, you can inject credentials in any way you would have for existing development environment. Here are some ways to get your credentials inside the container.
Loading environment variables from a file
Another way to load credentials into your container is to specify a local file with the environment variables to set.
For example, if you create a .env
file inside the .devcontainer
folder, you can use it to set environment variables available anywhere inside your container.
{
"runArgs": ["--env-file", ".devcontainer/devcontainer.env"]
}
Mounting local files
If you are developing using a local Docker instance, you can provide Docker run arguments to mount files on your host computer inside the container. For example, you can easily mount your .aws
folder to ensure access to local AWS credentials without having to copy them.
To do this, edit your devcontainer.json
. The setting you need to add or modify is called mounts
. Here is an example of how you can reuse your AWS credentials inside the container.
{
"mounts": [
"source=${localEnv:HOME}/.aws,target=/home/gitpod/.aws,type=bind,consistency=cached"
]
}
You can use this method for any credentials stored on your host machine.
Variables in the DDE
There are a few core variables that the DDE makes available for its own and user scripting purposes:
Name | Value |
---|---|
REPO_ROOT | The path to the project folder etc /workspace/true-dataops22 |
VS_CODE_SERVER_SETTINGS_PATH | The path to the settings.json folder |
CI_COMMIT_REF_NAME | The name of the git branch currently checked out |
DATAOPS_BRANCH_NAME_PROD | The name of the branch used for production — defaults to main but can be overridden |
Keeping the workspace image up-to-date
To ensure that the image you are using is always the latest version, you can add an initialize command to your devcontainer.json
. This command runs before your container is created. Read more about lifecycle scripts.
{
"name": "DataOpsCDE",
"image": "dataopslive/dataops-development-workspace:5-latest",
"runArgs": ["--env-file", "${localEnv:HOME}/.devcontainer/devcontainer.env"],
"initializeCommand": [
"docker",
"pull",
"dataopslive/dataops-development-workspace:5-latest"
]
}
Adding container features
Dev containers can use "features" to gain extra functionality. VS Code gives you access to an index of these features by using the command palette to add them to your devcontainer.json
file.
To add a feature this way, follow these steps. In this example, we are adding "docker-in-docker" as a feature:
Open a project containing the
.devcontainer/devcontainer.json
file.Open the command palette, "cmd+shift+p" for Mac and "ctrl+shift+p" for Windows.
Search for Configure Container Features.
Search for "Docker-in-Docker.
Select the check box and click OK.
This should add an entry to your devcontainer.json
like this:
"features": {
"ghcr.io/devcontainers-contrib/features/cookiecutter:2": {}
}