Skip to content

Commit 1c4704a

Browse files
committed
Merge branch 'main' into eric/remove-gateway-anchor
2 parents 1785025 + 2295623 commit 1c4704a

File tree

20 files changed

+1337
-52
lines changed

20 files changed

+1337
-52
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Defang Software Labs
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM mcr.microsoft.com/devcontainers/typescript-node:22-bookworm
2+
3+
# Install hasura cli
4+
RUN curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | bash
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile",
4+
"context": ".."
5+
},
6+
"features": {
7+
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
8+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
9+
"ghcr.io/devcontainers/features/aws-cli:1": {}
10+
}
11+
}

samples/hasura/README.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,51 @@ This sample project demonstrates how to deploy Hasura with Defang and connect it
77
## Prerequisites
88

99
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
10-
2. Have a managed database service configured and have the connection string ready.
11-
3. (Optional) If you are using [Defang BYOC](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) authenticated with your AWS account
12-
4. (Optional - for local development) [Docker CLI](https://docs.docker.com/engine/install/)
13-
5. (Optional) [Install the Hasura CLI](https://hasura.io/docs/latest/hasura-cli/install-hasura-cli/) to create migrations and update metadata for your Hasura GraphQL api.
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+
4. (Optional) [Install the Hasura CLI](https://hasura.io/docs/latest/hasura-cli/install-hasura-cli/) to create migrations and update metadata for your Hasura GraphQL api.
1413

1514
## Development
1615

17-
For development, we use a Postgres container. The Postgres container is defined in the `compose.dev.yaml` file. The Hasura container is defined in the `compose.yaml` file, with some overrides in the `compose.dev.yaml` file so it can correctly connect to the development database container.
18-
19-
To start the development environment, run `docker compose -f ./compose.yaml -f ./compose.dev.yaml up`. This will start the Postgres container and the Hasura container. The Hasura console will be available at `http://localhost:8080` with the password `password`.
16+
To start the development environment, run `docker -f ./compose.dev.yaml up`. This will start the Postgres container and the Hasura container. The Hasura console will be available at `http://localhost:8080` with the password `password`.
2017
**Note:** _If you want to make changes to your database, permissions, etc. you should use the Hasura console and the Hasura CLI to make those changes. See the next section for more information._
2118

2219
### Editing the database/permissions etc.
2320

2421
If you want to edit the database, permissions, or any other Hasura settings such that you can deploy them to production, you should [install the Hasura CLI](https://hasura.io/docs/latest/hasura-cli/install-hasura-cli/). Then, after starting the development environment, you can run `hasura console` _inside the `./hasura` directory_. This will open the Hasura console in your browser. Any changes you make in the console will be saved to the `migrations` and `metadata` directories. When you run `defang compose up` these changes will be applied to the production environment.
2522

26-
## Deploying
23+
**NOTE**: If you are using the [Dev Container](https://containers.dev/) defined in [.devcontainer/devcontainer.json](.devcontainer/devcontainer.json), the Hasura CLI will already be installed.
24+
25+
## Configuration
26+
27+
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/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.
28+
29+
### `HASURA_GRAPHQL_ADMIN_SECRET`
30+
This password will be used to allow you to access the hasura console.
31+
32+
33+
### `POSTGRES_PASSWORD`
34+
This password will be used to initialize the PostgreSQL database and to connect to it. You could use a command like `openssl rand -base64 16` to generate a random password.
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 `defang up`.
45+
46+
**Keep in mind that the playground does not support [managed Postgres](https://docs.defang.io/docs/concepts/managed-storage/managed-postgres).**
47+
48+
### BYOC (AWS)
49+
50+
If you want to deploy to your own cloud account, you can use Defang BYOC:
51+
52+
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`.
53+
2. Run `defang --provider=aws up` in a terminal that has access to your AWS environment variables.
2754

28-
1. Open the terminal and type `defang login`
29-
2. Add your connection string as a defang config value by typing `defang config set HASURA_GRAPHQL_DATABASE_URL` and pasting your connection string (which should be in the format `postgres://username:password@host:port/dbname`)
30-
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.
31-
4. Type `defang compose up` in the CLI.
32-
5. Your app will be running within a few minutes.
3355

3456
---
3557

samples/hasura/compose.dev.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
services:
2-
postgres:
3-
image: postgres:16
4-
environment:
5-
- POSTGRES_USER=postgres
6-
- POSTGRES_PASSWORD=postgres
7-
- POSTGRES_DB=postgres
8-
volumes:
9-
- postgres_data:/var/lib/postgresql/data
102
hasura:
11-
depends_on:
12-
- postgres
13-
restart: on-failure
3+
extends:
4+
file: compose.yaml
5+
service: hasura
146
environment:
15-
- HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres
7+
- HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:password@database:5432/postgres
168
- HASURA_GRAPHQL_ADMIN_SECRET=password
179
volumes:
1810
- ./hasura:/hasura
11+
database:
12+
extends:
13+
file: compose.yaml
14+
service: database
15+
environment:
16+
- POSTGRES_PASSWORD=password
17+
volumes:
18+
- database_data:/var/lib/postgresql/data
1919

2020
volumes:
21-
postgres_data:
21+
database_data:

samples/hasura/compose.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,23 @@ services:
1111
published: 8080
1212
mode: ingress
1313
environment:
14-
- HASURA_GRAPHQL_DATABASE_URL
1514
- HASURA_GRAPHQL_ADMIN_SECRET
15+
- HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD}@database:5432/postgres
1616
- HASURA_GRAPHQL_ENABLE_CONSOLE=true
1717
- HASURA_GRAPHQL_UNAUTHORIZED_ROLE=public
1818
- HASURA_GRAPHQL_EXPERIMENTAL_FEATURES=naming_convention
1919
- HASURA_GRAPHQL_DEFAULT_NAMING_CONVENTION=graphql-default
2020
- HASURA_GRAPHQL_MIGRATIONS_DIR=/hasura/migrations
2121
- HASURA_GRAPHQL_METADATA_DIR=/hasura/metadata
22-
#deploy:
23-
# resources:
24-
# reservations:
25-
# memory: 256M
22+
- POSTGRES_PASSWORD
23+
24+
database:
25+
image: postgres:16
26+
x-defang-postgres: true
27+
ports:
28+
- target: 5432
29+
mode: host
30+
environment:
31+
- POSTGRES_USER=postgres
32+
- POSTGRES_DB=postgres
33+
- POSTGRES_PASSWORD
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM mcr.microsoft.com/devcontainers/typescript-node:22-bookworm
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile",
4+
"context": ".."
5+
},
6+
"features": {
7+
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
8+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
9+
"ghcr.io/devcontainers/features/aws-cli:1": {}
10+
}
11+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
environment: playground
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
id-token: write
15+
16+
steps:
17+
- name: Checkout Repo
18+
uses: actions/checkout@v4
19+
20+
- name: Deploy
21+
uses: DefangLabs/[email protected]

samples/redis-js/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Redis & JavaScript
2+
[![1-click-deploy](https://raw.githubusercontent.com/DefangLabs/defang-assets/main/Logos/Buttons/SVG/deploy-with-defang.svg)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-redis-js-template%26template_owner%3DDefangSamples)
3+
4+
This is a Redis and JavaScript application, deployed with Defang.
5+
6+
Note that Defang supports the use of managed Redis in production deployments. You can enable this feature by adding the `x-defang-redis: true` tag to your Redis service in the `compose.yaml` file.
7+
8+
## Prerequisites
9+
10+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
11+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
12+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
13+
14+
## Development
15+
16+
To run the application locally, you can use the following command:
17+
18+
```bash
19+
docker compose up --build
20+
```
21+
22+
## Deployment
23+
24+
> [!NOTE]
25+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
26+
27+
### Defang Playground
28+
29+
Deploy your application to the Defang Playground by opening up your terminal and typing:
30+
```bash
31+
defang compose up
32+
```
33+
34+
### BYOC
35+
36+
If you want to deploy to your own cloud account, you can [use Defang BYOC](https://docs.defang.io/docs/tutorials/deploy-to-your-cloud).
37+
38+
---
39+
40+
Title: Redis & JavaScript
41+
42+
Short Description: A Redis and JavaScript application, deployed with Defang.
43+
44+
Tags: Redis, JavaScript
45+
46+
Languages: JavaScript

0 commit comments

Comments
 (0)