Skip to content

Commit efbbe9d

Browse files
committed
add redis-js sample
1 parent 371442d commit efbbe9d

File tree

12 files changed

+1178
-0
lines changed

12 files changed

+1178
-0
lines changed
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: 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: REDISX_URL
24+
env:
25+
ENV1: ${{ secrets.REDISX_URL }}

samples/redis-js/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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` 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+
## Configuration
23+
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration):
24+
25+
> 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.
26+
27+
### `REDISX_URL`
28+
A Redis connection string of the form `rediss://<username>:<password>@<host>:<port>`. Note that `REDISX` is a prefix which should match of the name of the Redis service (in this case, `redisx`).
29+
30+
```bash
31+
defang config set REDISX_URL
32+
```
33+
34+
## Deployment
35+
36+
> [!NOTE]
37+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
38+
39+
### Defang Playground
40+
41+
Deploy your application to the Defang Playground by opening up your terminal and typing:
42+
```bash
43+
defang compose up
44+
```
45+
46+
### BYOC
47+
48+
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).
49+
50+
---
51+
52+
Title: Redis & JavaScript
53+
54+
Short Description: A Redis and JavaScript application, deployed with Defang.
55+
56+
Tags: Redis, JavaScript
57+
58+
Languages: JavaScript

samples/redis-js/app/.dockerignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Default .dockerignore file for Defang
2+
**/__pycache__
3+
**/.direnv
4+
**/.DS_Store
5+
**/.envrc
6+
**/.git
7+
**/.github
8+
**/.idea
9+
**/.next
10+
**/.vscode
11+
**/compose.*.yaml
12+
**/compose.*.yml
13+
**/compose.yaml
14+
**/compose.yml
15+
**/docker-compose.*.yaml
16+
**/docker-compose.*.yml
17+
**/docker-compose.yaml
18+
**/docker-compose.yml
19+
**/node_modules
20+
**/Thumbs.db
21+
Dockerfile
22+
*.Dockerfile
23+
# Ignore our own binary, but only in the root to avoid ignoring subfolders
24+
defang
25+
defang.exe
26+
# Ignore our project-level state
27+
.defang

samples/redis-js/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

samples/redis-js/app/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use Node.js as the base image
2+
FROM node:22-alpine
3+
4+
# Set working directory to /app
5+
WORKDIR /app
6+
7+
# Copy package.json and package-lock.json first for better caching
8+
COPY package*.json ./
9+
10+
# Install dependencies
11+
RUN npm install
12+
13+
# Copy the rest of the project files
14+
COPY . .
15+
16+
# Expose the port your app runs on
17+
EXPOSE 3000
18+
19+
# Start the Node.js app
20+
CMD ["node", "server.js"]

0 commit comments

Comments
 (0)