Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions samples/django-channels-redis-postgres/app/Dockerfile

This file was deleted.

6 changes: 3 additions & 3 deletions samples/django-channels-redis-postgres/compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ services:
extends:
file: compose.yaml
service: app
volumes:
- ./app:/app
# volumes:
# - ./app:/app
healthcheck: {}
environment:
- REDIS_URL=redis://redis-service:6379
Expand All @@ -13,7 +13,7 @@ services:
depends_on:
- redis-service
- postgres-service
command: sh -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
command: ["python manage.py migrate && python manage.py runserver 0.0.0.0:8000"]

redis-service:
extends:
Expand Down
9 changes: 6 additions & 3 deletions samples/django-channels-redis-postgres/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ services:
app:
# uncomment to add your own domain
# domainname: example.com
build:
context: ./app
dockerfile: Dockerfile
# build:
# context: ./app
# dockerfile: Dockerfile
# args:
# - DEBUG=True
image: app:latest
ports:
- target: 8000
published: 8000
Expand Down
2 changes: 2 additions & 0 deletions samples/nodejs-react-postgres-nfc/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

FROM mcr.microsoft.com/devcontainers/typescript-node:22-bookworm
11 changes: 11 additions & 0 deletions samples/nodejs-react-postgres-nfc/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"features": {
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/aws-cli:1": {}
}
}
21 changes: 21 additions & 0 deletions samples/nodejs-react-postgres-nfc/.github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Deploy

on:
push:
branches:
- main

jobs:
deploy:
environment: playground
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Deploy
uses: DefangLabs/[email protected]
66 changes: 66 additions & 0 deletions samples/nodejs-react-postgres-nfc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Node.js & React & PostgreSQL

[![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-nodejs-react-postgres-template%26template_owner%3DDefangSamples)`

This sample project demonstrates how to deploy a full-stack application using React for the frontend, Node.js for the backend, and PostgreSQL for the database.

In this sample, we have set up the essential files you need to deploy in production using [Neon](https://neon.tech/) to host your database. We use a connection string to connect Neon to your code. By replacing the pre-configured connection string at .env and at the compose file to yours, you will be ready to deploy this sample with Neon.

## Prerequisites

1. Download [Defang CLI](https://github.com/DefangLabs/defang)
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)

## Development

To run the application locally, you can use the following command:

```bash
docker compose -f compose.dev.yaml up --build
```
Or run without using Docker by doing the following:

1. run `npm install` to install the nodejs dependencies in both the `client` directory and the `server` directory
2. create or modify the .env file in both the `client` directory and the `server` directory with localhost, or create a .env.local to override the .env file.
3. run `npm start`

## Configuration
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.

### `DATABASE_URL`
A connection to the database, which should be in the format of `postgres://username:password@host:port/dbname`.
```bash
defang config set DATABASE_URL
```

### `REACT_APP_API_URL`
A URL for the React App. For this, you will need to update the `compose.yaml` file to replace `<YOUR_USERNAME>` with your username, which you can get by running `defang whoami`.

## Deployment

> [!NOTE]
> Download [Defang CLI](https://github.com/DefangLabs/defang)

### Defang Playground

Deploy your application to the Defang Playground by opening up your terminal and typing:
```bash
defang compose up
```

### BYOC (AWS)

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):

---

Title: Node.js & React & PostgreSQL

Short Description: A full-stack to-do list application.

Tags: Node.js, React, Full-stack, PostgreSQL, JavaScript, SQL

Languages: nodejs
32 changes: 32 additions & 0 deletions samples/nodejs-react-postgres-nfc/client/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Ignore node_modules
node_modules
node_modules/*
npm-debug.log

# Ignore build outputs
build
dist

# Ignore logs
*.log
logs
*.log.*

# Ignore environment variables
.env.local
.env.development.local
.env.test.local
.env.production.local

# Ignore editor directories and files
.idea
.vscode
*.sublime-project
*.sublime-workspace

# Ignore testing and coverage files
coverage
jest-test-results.json

# Ignore miscellaneous
*.swp
23 changes: 23 additions & 0 deletions samples/nodejs-react-postgres-nfc/client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
30 changes: 30 additions & 0 deletions samples/nodejs-react-postgres-nfc/client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Use the slim version of Node.js on Debian Bookworm as the base image
FROM node:20-bookworm-slim

# Set environment variables to avoid interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive

# Argument for API URL
ARG REACT_APP_API_URL=http://localhost:3010
ENV REACT_APP_API_URL=${REACT_APP_API_URL}

# Set the working directory to /app
WORKDIR /app

# Copy package.json and package-lock.json into the container at /app
COPY package*.json ./

# Install any needed packages specified in package.json
RUN npm install

# Copy the current directory contents into the container at /app
COPY . .

# Build the React application
RUN npm run build

# Expose port 3000
EXPOSE 3000

# Command to serve the built React app
CMD ["npx", "serve", "-s", "build"]
70 changes: 70 additions & 0 deletions samples/nodejs-react-postgres-nfc/client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
Loading
Loading