This sample is a task manager application that uses Go and MongoDB, deployed with Defang.
HTML and JavaScript are used for the frontend to interact with the backend via API calls. There is a go.mod
file that includes dependencies for the Dockerfile to install.
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
To run the application locally, you can use the following command:
docker compose up --build
For this sample, you will need to provide the following configuration:
Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
The username for the MongoDB database.
defang config set MONGO_INITDB_ROOT_USERNAME
The password for the MongoDB database.
defang config set MONGO_INITDB_ROOT_PASSWORD
If you want to use MongoDB Atlas, you can set the URI with defang config set MONGO_URI
and remove the value from the MONGO_URI
environment variable so that it is read from defang config. For example, in your compose.yaml
file:
services:
app:
environment:
- MONGO_URI # empty values are read from defang config
If you want to use DocumentDB in AWS, you can add the x-defang-mongodb
extension to your compose.yaml
file:
services:
db:
x-defang-mongodb: true
This will automatically provision a DocumentDB cluster in your AWS account.
Note
Download Defang CLI
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Go & MongoDB
Short Description: A simple Go application that manages tasks with MongoDB.
Tags: Go, MongoDB, Atlas, Task Manager
Languages: golang