Deploy Using Pulumi
At the time of writing, the Defang Pulumi Provider only works with Defang Playground. We are working on BYOC support.
This tutorial will show you how to deploy Minio with Pulumi using the Defang Provider.
Pre-requisites
Step 1 - Authenticate With Defang
Make sure you are logged into the Defang CLI. Don't worry about the Pulumi CLI for now.
Step 2 - Configure the Pulumi Backend
Navigate to your project directly. (If you don't have a project yet, try one of our samples)
Pulumi uses the pulumi login
command to select a backend. In this tutorial, we will use the Local Filesystem backend for simplicity. When you are ready to deploy to production, you will probably want to look into other Pulumi backend options.
Run the following command to "login" to the filesystem backend in the local directory.
pulumi login file://./
This will make the Pulumi CLI store the state of your infrastructure in the current directory.
Step 3 - Initialize the Pulumi Project
Run the following command to set your encryption passphrase for this terminal session:
export PULUMI_CONFIG_PASSPHRASE="super-secure-passphrase"
Now let's initialize the Pulumi project:
pulumi new typescript -y --force
This will create a new Pulumi project in the current directory and will create a Pulumi stack called dev
by default. We use the --force
flag because the directory isn't empty (we created a folder when we logged in with the Pulumi CLI).
Run the following command to add to the .gitignore
file:
echo ".pulumi" >> .gitignore
Step 4 - Write Your Pulumi Code
Create an index.ts
file to contain your Pulumi code. This code will describe our services, our service's dependencies, and our service's configuration.
import * as defang from '@defang-io/pulumi-defang/lib';
export const service = new defang.DefangService('minio', {
name: 'minio',
image: 'quay.io/minio/minio',
// starts the server with the console address set to :9001
command: ['server', '--console-address', ':9001', '/data'],
// Set the root username
environment: {
MINIO_ROOT_USER: 'minio',
},
secrets: [
// Set the root password as a secret which will be encrypted at rest
{
source: 'MINIO_ROOT_PASSWORD',
value: 'minio123',
},
],
// Run a healthcheck every 30 seconds
healthcheck: {
test: ['CMD', 'curl', 'http://localhost:9000/minio/health/live'],
interval: 30,
timeout: 5,
retries: 3,
},
// Expose the server on port 9000 and the console on port 9001
ports: [
{
target: 9000,
protocol: 'http',
mode: 'ingress',
},
{
target: 9001,
protocol: 'http',
mode: 'ingress',
},
],
});
Step 5 - Deploy to Defang
Now we're ready to deploy to Defang with Pulumi! Run the following command to deploy your service:
pulumi up --stack=dev
Step 6 - Monitor the Deployment
You can monitor the deployment by running the following command:
defang tail --name minio
Logging Into Minio
The Defang Playground will give you a domain, which you can obtain by running the following command:
defang ls | grep 'minio.*9001'
If you navigate to the domain in your browser, you will be prompted to log in. Use the username minio
and the password minio123
.
Clean Up
To clean up the deployment, run the following command:
pulumi destroy --stack=dev
See the Pulumi concept docs for more information about the Defang Pulumi Provider.