Skip to content

Commit fd127e4

Browse files
Merge pull request #265 from DefangLabs/linda-golang
golang changes
2 parents 97ed6bc + 90ed5e3 commit fd127e4

File tree

17 files changed

+392
-102
lines changed

17 files changed

+392
-102
lines changed

.github/workflows/deploy-changed-samples.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ jobs:
8181
TEST_MB_DB_PASS: ${{ secrets.TEST_MB_DB_PASS }}
8282
TEST_MB_DB_PORT: ${{ secrets.TEST_MB_DB_PORT }}
8383
TEST_MB_DB_USER: ${{ secrets.TEST_MB_DB_USER }}
84+
TEST_MONGO_INITDB_ROOT_USERNAME: ${{ secrets.TEST_MONGO_INITDB_ROOT_USERNAME }}
85+
TEST_MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.TEST_MONGO_INITDB_ROOT_PASSWORD }}
8486
TEST_NC_DB: ${{ secrets.TEST_NC_DB }}
8587
TEST_NC_S3_ENDPOINT: ${{ secrets.TEST_NC_S3_ENDPOINT }}
8688
TEST_NC_S3_BUCKET_NAME: ${{ secrets.TEST_NC_S3_BUCKET_NAME }}

samples/golang-http-form/README.md

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,51 @@
44

55
This Go application demonstrates a simple form submission using the standard net/http library. Users can input their first name into a form, and upon submission, they will be greeted personally by the application.
66

7-
## Features
7+
## Prerequisites
88

9-
1. Simple form to submit a user's first name.
10-
2. Personalized greeting displayed in response to the form submission
9+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
10+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
11+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
1112

12-
## Essential Setup Files
13+
## Development
1314

14-
1. A [Dockerfile](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/).
15-
2. A [compose file](https://docs.defang.io/docs/concepts/compose) to define and run multi-container Docker applications (this is how Defang identifies services to be deployed). (compose.yaml file)
15+
To run the application locally, you can use the following command:
1616

17-
## Prerequisite
17+
```bash
18+
docker compose up --build
19+
```
1820

19-
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
20-
2. If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc), make sure you have properly [authenticated your AWS account (optional)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
21+
## Configuration
22+
23+
For this sample, you will not need to provide [configuration](https://docs.defang.io/docs/concepts/configuration).
24+
25+
If you wish to provide configuration, see below for an example of setting a configuration for a value named `API_KEY`.
26+
27+
```bash
28+
defang config set API_KEY
29+
```
30+
31+
## Deployment
32+
33+
> [!NOTE]
34+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
35+
36+
### Defang Playground
37+
38+
Deploy your application to the Defang Playground by opening up your terminal and typing:
39+
```bash
40+
defang compose up
41+
```
42+
43+
### BYOC (AWS)
2144

22-
## A Step-by-Step Guide
45+
If you want to deploy to your own cloud account, you can use Defang BYOC:
2346

24-
1. Open the terminal and type `defang login`
25-
2. Type `defang compose up` in the CLI
26-
3. Your app should be up and running with Defang in minutes!
47+
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`.
48+
2. Run in a terminal that has access to your AWS environment variables:
49+
```bash
50+
defang --provider=aws compose up
51+
```
2752

2853
---
2954

samples/golang-http/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,52 @@
44

55
A very simple example of a Go service that listens on a port and returns information about the request.
66

7+
## Prerequisites
8+
9+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
10+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
11+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
12+
13+
## Development
14+
15+
To run the application locally, you can use the following command:
16+
17+
```bash
18+
docker compose up --build
19+
```
20+
21+
## Configuration
22+
23+
For this sample, you will not need to provide [configuration](https://docs.defang.io/docs/concepts/configuration).
24+
25+
If you wish to provide configuration, see below for an example of setting a configuration for a value named `API_KEY`.
26+
27+
```bash
28+
defang config set API_KEY
29+
```
30+
31+
## Deployment
32+
33+
> [!NOTE]
34+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
35+
36+
### Defang Playground
37+
38+
Deploy your application to the Defang Playground by opening up your terminal and typing:
39+
```bash
40+
defang compose up
41+
```
42+
43+
### BYOC (AWS)
44+
45+
If you want to deploy to your own cloud account, you can use Defang BYOC:
46+
47+
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`.
48+
2. Run in a terminal that has access to your AWS environment variables:
49+
```bash
50+
defang --provider=aws compose up
51+
```
52+
753
---
854

955
Title: Go HTTP Server

samples/golang-mongodb-atlas/README.md

Lines changed: 0 additions & 44 deletions
This file was deleted.

samples/golang-mongodb-atlas/compose.yaml

Lines changed: 0 additions & 18 deletions
This file was deleted.
File renamed without changes.

samples/golang-mongodb/README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Go & MongoDB
2+
3+
[![1-click-deploy](https://defang.io/deploy-with-defang.png)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-golang-mongodb-template%26template_owner%3DDefangSamples)
4+
5+
This sample is a task manager application that uses Go and MongoDB, deployed with Defang.
6+
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+
9+
## Prerequisites
10+
11+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
12+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
13+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
14+
15+
## Development
16+
17+
To run the application locally, you can use the following command:
18+
19+
```bash
20+
docker compose up --build
21+
```
22+
23+
## Configuration
24+
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration):
25+
26+
> 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.
27+
28+
### `MONGO_INITDB_ROOT_USERNAME`
29+
The username for the MongoDB database.
30+
```bash
31+
defang config set MONGO_INITDB_ROOT_USERNAME
32+
```
33+
34+
### `MONGO_INITDB_ROOT_PASSWORD`
35+
The password for the MongoDB database.
36+
```bash
37+
defang config set MONGO_INITDB_ROOT_PASSWORD
38+
```
39+
40+
### Using MongoDB Atlas
41+
42+
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:
43+
44+
```yaml
45+
services:
46+
app:
47+
environment:
48+
- MONGO_URI # empty values are read from defang config
49+
```
50+
51+
## Deployment
52+
53+
> [!NOTE]
54+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
55+
56+
### Defang Playground
57+
58+
Deploy your application to the Defang Playground by opening up your terminal and typing:
59+
```bash
60+
defang compose up
61+
```
62+
63+
### BYOC (AWS)
64+
65+
If you want to deploy to your own cloud account, you can use Defang BYOC:
66+
67+
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`.
68+
2. Run in a terminal that has access to your AWS environment variables:
69+
```bash
70+
defang --provider=aws compose up
71+
```
72+
73+
---
74+
75+
Title: Go & MongoDB
76+
77+
Short Description: A simple Go application that manages tasks with MongoDB.
78+
79+
Tags: Go, MongoDB, Atlas, Task Manager
80+
81+
Languages: golang
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)