Skip to content

Commit 87407c8

Browse files
committed
initial
1 parent f795e79 commit 87407c8

File tree

11 files changed

+1186
-0
lines changed

11 files changed

+1186
-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/python:3.12-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/jupyter-postgres/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Jupyter & 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-jupyter-postgres-template%26template_owner%3DDefangSamples)
4+
5+
This sample shows you how to spin up a postgres database and a Jupyter notebook server. This is useful if you want to use Jupyter notebooks to read data from or persist data to a database.
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.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+
13+
## Development
14+
15+
To run the application locally, you can use the following command:
16+
17+
```bash
18+
# This might be `docker compose -f compose.dev.yaml up --build` depending on the project. #REMOVE_ME_AFTER_EDITING
19+
docker compose up --build
20+
```
21+
22+
## Configuration
23+
24+
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration):
25+
26+
> 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.
27+
28+
### `POSTGRES_PASSWORD`
29+
The password to use for the postgres database.
30+
```bash
31+
defang config set POSTGRES_PASSWORD
32+
```
33+
34+
### `JUPYTER_TOKEN`
35+
The token to access your Jupyter notebook server.
36+
```bash
37+
defang config set JUPYTER_TOKEN
38+
```
39+
40+
## Deployment
41+
42+
> [!NOTE]
43+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
44+
45+
### Defang Playground
46+
47+
Deploy your application to the Defang Playground by opening up your terminal and typing:
48+
```bash
49+
defang compose up
50+
```
51+
52+
### BYOC (AWS)
53+
54+
If you want to deploy to your own cloud account, you can use Defang BYOC:
55+
56+
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`.
57+
2. Run in a terminal that has access to your AWS environment variables:
58+
```bash
59+
defang --provider=aws compose up
60+
```
61+
62+
---
63+
64+
Title: Jupyter & Postgres
65+
66+
Short Description: This sample shows you how to spin up a postgres database and a Jupyter notebook server.
67+
68+
Tags: Jupyter, Postgres, Database
69+
70+
Languages: Python, SQL
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
services:
2+
jupyter:
3+
extends:
4+
service: jupyter
5+
file: compose.yaml
6+
environment:
7+
JUPYTER_TOKEN: jupyter
8+
POSTGRES_PASSWORD: password
9+
volumes:
10+
- ./jupyter/notebooks:/home/jovyan/work
11+
12+
db:
13+
image: postgres:14
14+
environment:
15+
POSTGRES_PASSWORD: password
16+
ports:
17+
- "5432:5432"
18+
volumes:
19+
- postgres_data:/var/lib/postgresql/data
20+
21+
volumes:
22+
postgres_data:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
services:
2+
jupyter:
3+
# Uncomment the following line and run `defang cert generate` to generate an ssl certificate for your domain
4+
# domainname: notebooks.mycompany.com
5+
build:
6+
context: ./jupyter
7+
ports:
8+
- mode: ingress
9+
target: 8888
10+
published: 8888
11+
environment:
12+
JUPYTER_TOKEN:
13+
POSTGRES_PASSWORD:
14+
healthcheck:
15+
test: ["CMD", "curl", "-f", "http://localhost:8888/login" ]
16+
depends_on:
17+
- db
18+
19+
db:
20+
image: postgres:14
21+
x-defang-postgres: true
22+
healthcheck:
23+
test: ["CMD-SHELL", "pg_isready -U postgres"]
24+
environment:
25+
POSTGRES_PASSWORD:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM jupyter/datascience-notebook
2+
3+
# 4.002 Error: pg_config executable not found.
4+
# make sure the development packages are installed
5+
6+
USER root
7+
8+
RUN apt-get update && apt-get install -y libpq-dev
9+
10+
USER 1000
11+
12+
COPY requirements.txt /tmp/
13+
RUN pip install --no-cache-dir -r /tmp/requirements.txt

0 commit comments

Comments
 (0)