|
2 | 2 |
|
3 | 3 | [](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-golang-mongodb-atlas-template%26template_owner%3DDefangSamples)
|
4 | 4 |
|
5 |
| -## Overview |
| 5 | +This sample is a task manager application that uses Go and MongoDB Atlas, deployed with Defang. |
6 | 6 |
|
7 |
| -This sample is is a web-based task manager designed to help users manage their tasks efficiently. It allows users to add, delete, and view tasks in a simple and intuitive interface. This application is ideal for anyone looking to enhance their productivity by keeping track of their daily activities. There is a go.mod file that includes dependencies for the Dockerfile to install |
| 7 | +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. |
8 | 8 |
|
9 |
| -## Features |
| 9 | +There is a environment variable named `MONGO_URI` for the `MONGODB` connection string. In the `compose.yaml` file, be sure to put your MongoDB URI, i.e. |
| 10 | + `mongodb+srv://<username>:<pwd>@host`. |
10 | 11 |
|
11 |
| -Create Tasks: Users can add new tasks with descriptions. |
12 |
| -Delete Tasks: Users can remove tasks when they are completed or no longer needed. |
13 |
| -View Tasks: Users can view a list of their current tasks. |
| 12 | +## Prerequisites |
14 | 13 |
|
15 |
| -## Technology |
| 14 | +1. Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 15 | +2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account |
| 16 | +3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/) |
16 | 17 |
|
17 |
| -Backend: The application is built with Go (Golang), utilizing the powerful net/http standard library for handling HTTP requests and responses. |
18 |
| -Database: MongoDB is used for storing tasks. It is a NoSQL database that offers high performance, high availability, and easy scalability. |
19 |
| -Frontend: Basic HTML and JavaScript are used for the frontend to interact with the backend via API calls. |
20 |
| -Environment: Designed to run in containerized environments using Docker, which ensures consistency across different development and production environments. |
| 18 | +## Development |
21 | 19 |
|
22 |
| -## Prerequisite |
| 20 | +To run the application locally, you can use the following command: |
23 | 21 |
|
24 |
| -1. Download [Defang CLI](https://github.com/DefangLabs/defang) |
25 |
| -2. If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc), make sure you have properly [authenticated your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) |
26 |
| - Plus, make sure that you have properly set all environment variables up |
27 |
| -3. There is a environment variable named MONGO_URI for the MONGODB connection string, in the compose file, be sure to put your mongodb URI, i.e. |
28 |
| - mongodb+srv://<username>:<pwd>@host |
| 22 | +```bash |
| 23 | +docker compose up --build |
| 24 | +``` |
| 25 | + |
| 26 | +## Configuration |
| 27 | +For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration): |
| 28 | + |
| 29 | +> 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. |
| 30 | +
|
| 31 | +### `MONGODB_URI` |
| 32 | +A URI for MongoDB that should have a format of `mongodb+srv://<username>:<pwd>@host`. |
| 33 | +```bash |
| 34 | +defang config set MONGODB_URI |
| 35 | +``` |
| 36 | + |
| 37 | +## Deployment |
| 38 | + |
| 39 | +> [!NOTE] |
| 40 | +> Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 41 | +
|
| 42 | +### Defang Playground |
| 43 | + |
| 44 | +Deploy your application to the Defang Playground by opening up your terminal and typing: |
| 45 | +```bash |
| 46 | +defang compose up |
| 47 | +``` |
| 48 | + |
| 49 | +### BYOC (AWS) |
29 | 50 |
|
30 |
| -## A Step-by-Step Guide |
| 51 | +If you want to deploy to your own cloud account, you can use Defang BYOC: |
31 | 52 |
|
32 |
| -1. Open the terminal and type `defang login` |
33 |
| -2. Type `defang compose up` in the CLI |
34 |
| -3. Your app should be up and running with Defang in minutes! |
| 53 | +1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and check that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`. |
| 54 | +2. Run in a terminal that has access to your AWS environment variables: |
| 55 | + ```bash |
| 56 | + defang --provider=aws compose up |
| 57 | + ``` |
35 | 58 |
|
36 | 59 | ---
|
37 | 60 |
|
|
0 commit comments