Once you have a development environment up, whether it is local or remote, you have a new challenge how can I get all the credentials I need (API tokens, certificate files, database strings, etc) into this environment safely? Answering this question is even more important in an ephemeral environment like a container or the cloud.
We are working with our friends at Doppler, to solve this very issue. Let me show you how to use Doppler with Daytona and Development Container.
If you prefer to watch, you can find the full video of the demo at the bottom of this page. 👇
What will we cover today?
In this tutorial, I'll walk you through effectively managing secrets when developing using Doppler, a secret management tool. We will start with an example I have modified from Doppler's University repo.
![Doppler's university repo Demo](https://www.datocms-assets.com/103916/1695804273-doppler_first-large.jpeg?auto=compress%2Cformat)
I will demonstrate how to use Doppler with either Daytona or Dev Container in general. I will show you how to install Doppler, set everything up, and ensure a smooth interaction between Doppler and Dev Container.
All we'll need to do is figure out a way to import all this information into the environment, which I will help you do throughout this tutorial.
Setting the Stage: What is Doppler?
Before we dive into the nuts and bolts, let's first understand what Doppler is. Doppler is a cutting-edge secret management tool that takes care of several aspects of your development environment. It's like your personal assistant, managing secrets, environment variables, and node environments, so you can focus on what you do best—coding.
As developers, we often find ourselves bogged down by the nitty-gritty of setting up and managing our environments. But with Doppler, it's like having a superpower that takes care of all these elements. Now, you might be thinking, "Okay, Doppler sounds cool, but how do I use it?" That's where Daytona comes in.
Enter Daytona: Your Dev Environment Savior
Daytona is a standardized development environment platform that uses Dev Container standard, developed by Microsoft, to ease the configuration and setup of your dev environments. It automates and standardizes workflows, giving you the freedom to focus on your code. Think of Daytona as your go-to platform for running Dev Container workloads. You can run it wherever you want—be it in your cloud or a data center—and it enables you to set up these remote environments quickly. All it takes is a click!
Daytona is, in our opinion, the best place to run your Dev Container workloads.
The Power Couple: Doppler and Daytona
Now that we've set the stage, let's dive into the exciting part—using Doppler with Daytona. To get started we have to install Doppler, configure it for the project, and launch the application with Doppler. Or, we could just use Dev Container.
"Doppler will take care of everythiong. The trick is, you just need to figure out a way to get all of that information into your environment."
![Doppler env vars setup](https://www.datocms-assets.com/103916/1695802439-doppler_envs-large.jpeg?auto=compress%2Cformat)
Setting up Dev Container
The Dev Container setup is the first step in this process.
![Devcontainer setup](https://www.datocms-assets.com/103916/1695802425-doppler_devcontainer-large.jpeg?auto=compress%2Cformat)
We're starting from an image—the default Dev Container image that Microsoft releases for node. We're adding a feature that I wrote for Doppler. This feature installs and configures Doppler for us, making the setup hassle-free.
1"features": {2 "ghcr.io/metcalfc/devcontainer-features/doppler:0": {}3}
The configuration comes in the form of environment variables. For our project, we're going to use Doppler to look for the Mandalorian gifs node project and within that, select the environment named dev.
1// Doppler eliminates the need for .env files! To enable, open workspace from the terminal by running `./bin/doppler-vscode.sh`2"containerEnv": {3 "DOPPLER_PROJECT": "mandalorian-gifs-node",4 "DOPPLER_CONFIG": "dev",5 "DOPPLER_TOKEN": "${localEnv:DOPPLER_TOKEN}" // Don't hard-code this!6},
And here it is how it looks in Doppler.
![Doppler Projects View](https://www.datocms-assets.com/103916/1695802434-doppler_projects-large.jpeg?auto=compress%2Cformat)
Injecting a Local Doppler Token
Next, we're going to inject a local token through Daytona.
If you're wondering how to get this Doppler token, it's straightforward. You can find everything well documented in the Doppler documentation under service tokens.
1# Create the Service Token2doppler configs tokens create token-name --plain
Once you have that token, you can go to Daytona, navigate to the environment variables, and create it.
![Dev Environment Vars in Daytona](https://www.datocms-assets.com/103916/1695802417-doppler_envvar-large.jpeg?auto=compress%2Cformat)
Customization and Launch
Now, if you want to do any customizations, you have the freedom to do so.
As an example, we're making sure that Prettier is installed to keep everything formatted just the way we like it.
1// Configure tool-specific properties.2"customizations": {3 // Configure properties specific to VS Code.4 "vscode": {5 "settings": {},6 "extensions": ["esbenp.prettier-vscode"]7 }8},
Dev Container also lets us control the lifecycle of the workspace. We are going to automate opening a preview window if the service starts on port 8080.
1"portsAttributes": {2 "8080": {3 "label": "Preview",4 "onAutoForward": "openPreview"5 }6},
Dev Container also supports a number of lifecycle scripts. For example, when the container is created, we want npm to pull the dependencies. Later when the user’s IDE attaches to the workspace we want to use Doppler to start the application.
1"postCreateCommand": "npm install --only dev --silent --no-audit",2"postAttachCommand": "doppler run -- npm start"
So we have the Dev Container file and now all we need is a place to run it. Here is where Daytona comes in. Daytona launches the workspace, fetches the container, injects the token, runs the lifecycle scripts and in the end we get a fully configured IDE with the application running. For us, it just took one click.
![Daytona launching workspace](https://www.datocms-assets.com/103916/1695802327-doppler_console-large.jpeg?auto=compress%2Cformat)
Wrapping Up
And that's it! All you need to do to use Doppler in a Dev Container environment is set a couple of environment variables and a token. It's a game-changer for developers, allowing you to focus on what matters without the hassle of managing your environment. For more information from Doppler’s point of view, check out their blog where they go into more detail on setting up the project in Doppler.
![Doppler and Daytona working together](https://www.datocms-assets.com/103916/1695802430-doppler_final-large.jpeg?auto=compress%2Cformat)
That's all for today! I hope this tutorial was helpful, and you're now equipped to use Doppler with Daytona like a pro. I livestream every Tuesday at 10:00 AM Pacific and cover topics just like this. Drop by and ask any questions you have or just say hello.
https://youtube.com/@daytonaio