Skip to content

Commit e627eff

Browse files
committed
default to playground as environment name
0 parents  commit e627eff

23 files changed

+6193
-0
lines changed

.devcontainer/Dockerfile

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

.devcontainer/devcontainer.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}
10+
}

.github/workflows/deploy.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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]
22+
with:
23+
config-env-vars: POSTGRES_PASSWORD
24+
env:
25+
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Next.js & Postgres
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-nextjs-postgres-template%26template_owner%3DDefangSamples)
4+
5+
This is a sample Next.js application that uses Postgres as a database. It is a simple example that demonstrates how to connect to a Postgres database from a Next.js application: on each request it takes the user's IP address, geo-locates it, and stores the result in the database, then displays the last 20 results on the home page.
6+
7+
## Prerequisites
8+
9+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
10+
2. (Optional) If you are using [Defang BYOC](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) authenticated with your AWS 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 -f compose.dev.yaml up --build
19+
```
20+
21+
## Configuration
22+
23+
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.
24+
25+
### `POSTGRES_PASSWORD`
26+
A password that will be used to connect to the Postgres database.
27+
28+
29+
## Deploying
30+
31+
1. Open the terminal and type `defang login`
32+
2. Use the [`defang config`](https://docs.defang.io/docs/concepts/compose#configuration) command to setup environment variables.
33+
3. Type `defang compose up` in the CLI.
34+
4. Your app will be running within a few minutes.
35+
36+
---
37+
38+
Title: Next.js & Postgres
39+
40+
Short Description: A sample Next.js application that uses Postgres as a database.
41+
42+
Tags: Next.js, Postgres, Database, Node.js
43+
44+
Languages: TypeScript, JavaScript

app/.dockerignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Ignore node_modules and npm debug log
2+
node_modules
3+
npm-debug.log
4+
5+
# Ignore build output
6+
.next
7+
out
8+
9+
# Ignore local environment variables
10+
.env
11+
.env.local
12+
.env.development.local
13+
.env.test.local
14+
.env.production.local
15+
16+
# Ignore logs
17+
logs
18+
*.log
19+
20+
# Ignore OS-specific files
21+
.DS_Store
22+
Thumbs.db
23+
24+
# Ignore editor directories and files
25+
.vscode
26+
.idea
27+
*.suo
28+
*.ntvs*
29+
*.njsproj
30+
*.sln

app/.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["next/core-web-vitals", "next/typescript"]
3+
}

app/.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
.yarn/install-state.gz
8+
9+
# testing
10+
/coverage
11+
12+
# next.js
13+
/.next/
14+
/out/
15+
16+
# production
17+
/build
18+
19+
# misc
20+
.DS_Store
21+
*.pem
22+
23+
# debug
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts

app/Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Stage 1: Build the application
2+
FROM node:20-bookworm-slim AS builder
3+
4+
WORKDIR /app
5+
6+
# Copy package.json and package-lock.json
7+
COPY package*.json ./
8+
9+
# Install dependencies
10+
RUN npm ci
11+
12+
# Copy the rest of the application code
13+
COPY . .
14+
15+
# Build the application
16+
RUN npm run build
17+
18+
FROM node:20-bookworm-slim AS development
19+
20+
WORKDIR /app
21+
22+
# Stage 2: Serve the application
23+
FROM node:20-bookworm-slim
24+
25+
WORKDIR /app
26+
27+
# Install curl
28+
RUN apt-get update -qq \
29+
&& apt-get install -y curl \
30+
&& apt-get clean \
31+
&& rm -rf /var/lib/apt/lists/*
32+
33+
# Copy only the necessary files from the build stage
34+
COPY --from=builder /app/package*.json ./
35+
COPY --from=builder /app/.next ./.next
36+
COPY --from=builder /app/next.config.mjs ./
37+
38+
# Install only production dependencies
39+
RUN npm ci --only=production
40+
41+
# Expose the port the app runs on
42+
EXPOSE 3000
43+
44+
# Use a non-root user for security
45+
RUN addgroup --system appgroup && adduser --system appuser --ingroup appgroup
46+
USER appuser
47+
48+
# Start the application
49+
CMD ["npm", "start"]

app/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
# or
14+
bun dev
15+
```
16+
17+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18+
19+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20+
21+
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
22+
23+
## Learn More
24+
25+
To learn more about Next.js, take a look at the following resources:
26+
27+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29+
30+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
31+
32+
## Deploy on Vercel
33+
34+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35+
36+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.

app/next.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {};
3+
4+
export default nextConfig;

0 commit comments

Comments
 (0)