Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorg samples #4

Merged
merged 28 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
db4bf91
partial restructure
raphaeltm May 16, 2024
cb85150
consistent compose.yml
raphaeltm May 16, 2024
044db74
consistent compose.yml
raphaeltm May 16, 2024
8edb16e
check samples
raphaeltm May 16, 2024
8b1e9f2
Merge remote-tracking branch 'origin/main' into setup-samples
raphaeltm May 16, 2024
59aa0d8
edit gh action
raphaeltm May 16, 2024
e64ed16
edit gh action
raphaeltm May 16, 2024
e9a3a0f
edit gh action
raphaeltm May 16, 2024
e35a901
edit gh action
raphaeltm May 16, 2024
b812423
edit gh action
raphaeltm May 16, 2024
7229cc4
edit gh action
raphaeltm May 16, 2024
adb6a29
edit gh action
raphaeltm May 16, 2024
1b6995b
update action
raphaeltm May 16, 2024
5674a5c
add svelte
raphaeltm May 16, 2024
7fefbf6
update sample automation
raphaeltm May 16, 2024
2f13319
update sample automation
raphaeltm May 16, 2024
a7e7a44
nodejs rest api
raphaeltm May 16, 2024
7ebc7a2
fix readmes
raphaeltm May 16, 2024
f2c1ca5
next samples
raphaeltm May 16, 2024
4744216
switch to compose.yaml
raphaeltm May 16, 2024
0884bd0
complete nodejs samples
raphaeltm May 16, 2024
6a43de4
add all samples
raphaeltm May 16, 2024
0691cdf
don't add a compose checklist item if a pulumi.yaml file exists
raphaeltm May 16, 2024
102fcf4
check for Pulumi.yaml recursively
raphaeltm May 16, 2024
0ada8f1
if the checklist is empty, exit gracefully
raphaeltm May 16, 2024
b788384
if the checklist is empty, exit gracefully
raphaeltm May 16, 2024
09d71b5
if the checklist is empty, exit gracefully
raphaeltm May 16, 2024
45974bd
if the checklist is empty, exit gracefully
raphaeltm May 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
58 changes: 32 additions & 26 deletions .github/workflows/check-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,56 @@ on:
jobs:
check_samples:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Check for required files
- name: Run Checks
id: checks
run: |
for changed_file in $(git diff --name-only HEAD^); do
if [[ $changed_file == samples/* ]]; then
sample_dir=$(dirname $changed_file)
if [[ ! -f $sample_dir/README.md || ! -f $sample_dir/compose.yml ]]; then
echo "Missing README.md or compose.yml in $sample_dir"
exit 1
fi
fi
done
./scripts/check-sample-files.sh > checklist.txt

- name: Add checklist to PR description
uses: actions/github-script@v5
with:
script: |
const fs = require('fs');
const pr_number = context.issue.number;
const checklist = `
- [ ] I have tested that the sample runs locally
- [ ] I have tested that the sample runs in Defang Playground
- [ ] I have tested that the sample runs in BYOC
- [ ] I have documented any required config in the readme
- [ ] I have documented how to provision any third-party services in the readme
- [ ] I have documented how to run the sample in the readme (locally and with Defang)
`;
const marker = '## Samples Checklist';

// Read the checklist from the file
let checklist = fs.readFileSync('checklist.txt', 'utf8').trim();

if(!checklist) {
checklist = "✅"
}

// Get the current PR
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr_number
});

// Check if the checklist already exists in the PR description
if (!pullRequest.body.includes(checklist)) {
// Update the PR description with the checklist

let newBody;
const body = pullRequest.body || "";
const markerIndex = body.indexOf(marker);

if (markerIndex !== -1) {
// Replace the content below the marker
newBody = body.substring(0, markerIndex + marker.length) + "\n" + checklist;
} else {
// Append the checklist if the marker doesn't exist
newBody = body + "\n" + marker + "\n" + checklist;
}

// Update the PR description
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr_number,
body: pullRequest.body + "\n" + checklist
});
}
body: newBody
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ Plus, make sure that you have properly set your environment variables like `AWS_
1. Open the terminal and type `defang login`
2. Type `defang compose up` in the CLI
3. Now your application will be launched

---

Title: Django + Postgres

Short Description: A customer relationship management list project developed using Python Django framework, offering a starting point to help you quickly build your customer management system

Tags: django, postgres

Languages: python, sql
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 17 additions & 1 deletion samples/python/django/README.md → samples/django/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
This is a simple example of how to run Django on Defang. It is a simple Todo app that uses SQLite as the database (so data is *not* persisted between deployments). We will be putting together an example with a managed database soon.
# Django

This is a simple example of how to run Django on Defang. It is a simple Todo app that uses SQLite as the database.

### NOTE

This sample is a simple Django app that uses SQLite as the database, which will be reset every time you deploy. **It is not production-ready**. For production use cases, you should check out the Django + Postgres sample.

The app includes a management command which is run on startup to create a superuser with the username `admin` and password `admin`. This means you can login to the admin interface at `/admin/` and see the Django admin interface without any additional steps. The `example_app` is already registered and the `Todo` model is already set up to be managed in the admin interface.

Expand All @@ -19,3 +25,13 @@ Plus, make sure that you have properly set your environment variables like `AWS_
2. Open the terminal and type `defang login`
3. Type `defang compose up` in the CLI
4. Now your application will be launched

---

Title: Django

Short Description: A simple Django app that uses SQLite as the database

Tags: django, sqlite

Languages: python
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions samples/python/flask/README.md → samples/flask/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

This is a sample of a basic Flask TODO app. The items are stored in memory and are lost when the server is restarted, but it should give you a basic idea of how to get started with Flask on Defang. Note that alognside your .py file, include a requirements.txt so that the Dockerfile can install the necessary packages with pip.

### NOTE:
This sample is a simple Flask app that demonstrates how to create a TODO app using Flask. The items are stored in memory and are lost when the server is restarted. This sample is intended to provide a basic understanding of how to get started with Flask on Defang. **it is not intended for production use**. If you need something production ready, you should use a managed database like Postgres or MySQL.

## Essential Setup Files
1. A <a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/">Dockerfile</a>.
2. A <a href="https://docs.defang.io/docs/concepts/compose">compose file</a> to define and run multi-container Docker applications (this is how Defang identifies services to be deployed).
Expand All @@ -15,3 +18,13 @@ This is a sample of a basic Flask TODO app. The items are stored in memory and a
1. Open the terminal and type `defang login`
2. Type `defang compose up` in the CLI
3. Your app should be up and running with Defang in minutes!

---

Title: Simple Flask App

Short Description: A sample of a basic Flask TODO app

Tags: flask, python

Languages: python
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ This Go application demonstrates a simple form submission using the standard net
1. Open the terminal and type `defang login`
2. Type `defang compose up` in the CLI
3. Your app should be up and running with Defang in minutes!

---

Title: Go HTTP Form

Short Description: A simple Go application that demonstrates form submission using the net/http library

Tags: go, http, form

Languages: go

File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions samples/golang-http/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# HTTP Echo Server

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

---

Title: Go HTTP Server

Short Description: A simple Go application that echoes back the request

Tags: go, http

Languages: go
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ mongodb+srv://<username>:<pwd>@host
1. Open the terminal and type `defang login`
2. Type `defang compose up` in the CLI
3. Your app should be up and running with Defang in minutes!

---

Title: Go MongoDB Atlas

Short Description: A simple Go application that manages tasks with MongoDB Atlas

Tags: go, mongodb, atlas, task manager

Languages: go
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@ echo "Hello" | curl -H "Content-Type: application/text" -d @- https://xxxxxxxx/p
or
```
cat prompt.txt | curl -H "Content-Type: application/text" -d @- https://xxxxxxxx/prompt
```
```

---

Title: Go OpenAI

Short Description: A simple Go application that interacts with the OpenAI API

Tags: go, openai, chatgpt

Languages: go
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Go HTTP Server with Fiscal Data API

This is a simple HTTP server written in Go that serves two endpoints: / and /rates. The / endpoint responds with a JSON object containing the status, while the /rates endpoint fetches data from the Fiscal Data Treasury API and returns the response to the client.
This is a simple HTTP server written in Go that serves two endpoints: / and /rates. The / endpoint responds with a JSON object containing the status, while the /rates endpoint fetches data from the Fiscal Data Treasury API and returns the response to the client.

---

Title: Go + REST API

Short Description: A simple Go application that fetches fiscal data from an API

Tags: go, http, fiscal data, api, rest

Languages: go
10 changes: 10 additions & 0 deletions samples/golang/AWS S3/README.md → samples/golang-s3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ and then enter the value when prompted.
## Testing
curl -X POST -H 'Content-Type: application/json' -d '{ "first_name" : "jane", "last_name" : "doe" }' https://xxxxxx/upload
curl https://xxxxxx/download

---

Title: Go S3

Short Description: A simple Go application that uploads and downloads files from AWS S3

Tags: go, s3, aws

Languages: go
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,14 @@ Once the Slackbot is deployed, you can send a POST request to the `/` endpoint w
curl 'https://raphaeltm-bot--8080.prod1.defang.dev/' \
-H 'content-type: application/json' \
--data-raw $'{"message":"This is your bot speaking. We\'ll be landing in 10 minutes. Please fasten your seatbelts."}'
```
```

---

Title: Go Slackbot

Short Description: A simple Slackbot that posts messages to a Slack channel

Tags: go, slack, bot

Languages: go
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions samples/golang/Basic Service/README.md

This file was deleted.

10 changes: 10 additions & 0 deletions samples/other/hasura/README.md → samples/hasura/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ If you want to edit the database, permissions, or any other Hasura settings such
3. Setup a password for hasura by typing `defang config set HASURA_GRAPHQL_ADMIN_SECRET` and adding a password you would like to login with.
2. Type `defang compose up` in the CLI.
3. Your app will be running within a few minutes.

---

Title: GraphQL API with Hasura + Postgres

Short Description: A sample project demonstrating how to deploy Hasura with Defang and connect it to a Postgres database

Tags: hasura, graphql, postgres, database

Languages: sql, graphql
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions samples/other/imgproxy/README.md → samples/imgproxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ If you have environment variables configured for your [own cloud account](https:
```sh
defang compose up
```

---

Title: ImgProxy

Short Description: A fast and secure standalone server for resizing and converting remote images

Tags: imgproxy, images, server

Languages:
File renamed without changes.
34 changes: 34 additions & 0 deletions samples/metabase/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Metabase + Postgres

Metabase is a simple and powerful analytics tool which lets anyone learn and make decisions from their company’s data. This sample demonstrates how to deploy Metabase with Defang. In development, we run a postgres container and in production, we use a managed postgres service. To build the sample, we used Neon, because of their simplicity and generous free tier.


## Prerequisites
1. Download <a href="https://github.com/defang-io/defang">Defang CLI</a>
2. Have a managed database service configured and have the connection details ready.
3. (optional) If you are using <a href="https://docs.defang.io/docs/concepts/defang-byoc">Defang BYOC</a>, make sure you have properly <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html">authenticated your AWS account</a>.

## Local

For development, we use a Postgres container. The Postgres container is defined in the `compose.dev.yml` file. The Metabase container is defined in the `compose.yml` file, with some overrides in the `compose.dev.yml` file so it can correctly connect to the development database container.

To start the development environment, run `docker compose -f ./compose.yml -f ./compose.dev.yml up`. This will start the Postgres container and the Metabase container. Metabase will be available at `http://localhost:3000`.

Since Metabase is a self contained application, there isn't an actual development process, but you can use the development environment to see how Metabase works.

## Deploying

1. Open the terminal and type `defang login`
2. Add your database connection details using `defang config` by typing `defang config set <CONFIG_VAL>` where `<CONFIG_VAL>` is the each of the following `MB_DB_DBNAME`, `MB_DB_HOST`, `MB_DB_PORT`, `MB_DB_USER`, `MB_DB_PASS` (to set the database name, host, port, user, and password respectively). For example `defang config set MB_DB_DBNAME` and pasting your database name.
3. Type `defang compose up` in the CLI.
4. Your app will be running within a few minutes.

---

Title: Metabase + Postgres

Short Description: A simple metabase configuration with a Postgres database

Tags: metabase, postgres, analytics, database

Languages: sql
35 changes: 35 additions & 0 deletions samples/metabase/compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3.9'
services:
metabase:
environment:
- MB_DB_TYPE=postgres
- MB_DB_DBNAME=metabase
- MB_DB_PORT=5432
- MB_DB_USER=metabase
- MB_DB_PASS=metabase
- MB_DB_HOST=postgres
depends_on:
postgres:
condition: service_healthy

postgres:
image: "postgres:latest"
environment:
POSTGRES_DB: metabase
POSTGRES_USER: metabase
POSTGRES_PASSWORD: metabase
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD", "pg_isready", "-U", "metabase"]
interval: 10s
timeout: 10s
retries: 10
deploy:
resources:
reservations:
cpus: "0.5"
memory: 1024M

volumes:
postgres_data:
26 changes: 26 additions & 0 deletions samples/metabase/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3.9'
name: metabase
services:
metabase:
image: "metabase/metabase:latest"
ports:
- mode: ingress
target: 3000
published: 3000
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/api/health" ]
interval: 1m30s
timeout: 30s
retries: 5
environment:
- MB_DB_TYPE=postgres
- MB_DB_DBNAME
- MB_DB_PORT
- MB_DB_USER
- MB_DB_PASS
- MB_DB_HOST
deploy:
resources:
reservations:
cpus: "0.5"
memory: 1024M
File renamed without changes.
File renamed without changes.
Loading
Loading