-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FROM mcr.microsoft.com/devcontainers/python:3.12-bookworm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Jupyter & Postgres | ||
|
||
[![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) | ||
|
||
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. | ||
|
||
## 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 | ||
# This might be `docker compose -f compose.dev.yaml up --build` depending on the project. #REMOVE_ME_AFTER_EDITING | ||
docker compose up --build | ||
``` | ||
|
||
## 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. | ||
### `POSTGRES_PASSWORD` | ||
The password to use for the postgres database. | ||
```bash | ||
defang config set POSTGRES_PASSWORD | ||
``` | ||
|
||
### `JUPYTER_TOKEN` | ||
The token to access your Jupyter notebook server. | ||
```bash | ||
defang config set JUPYTER_TOKEN | ||
``` | ||
|
||
## 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: | ||
|
||
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`. | ||
2. Run in a terminal that has access to your AWS environment variables: | ||
```bash | ||
defang --provider=aws compose up | ||
``` | ||
|
||
--- | ||
|
||
Title: Jupyter & Postgres | ||
|
||
Short Description: This sample shows you how to spin up a postgres database and a Jupyter notebook server. | ||
|
||
Tags: Jupyter, Postgres, Database | ||
|
||
Languages: Python, SQL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
services: | ||
jupyter: | ||
extends: | ||
service: jupyter | ||
file: compose.yaml | ||
environment: | ||
JUPYTER_TOKEN: jupyter | ||
POSTGRES_PASSWORD: password | ||
volumes: | ||
- ./jupyter/notebooks:/home/jovyan/work | ||
|
||
db: | ||
image: postgres:14 | ||
environment: | ||
POSTGRES_PASSWORD: password | ||
ports: | ||
- "5432:5432" | ||
volumes: | ||
- postgres_data:/var/lib/postgresql/data | ||
|
||
volumes: | ||
postgres_data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
services: | ||
jupyter: | ||
# Uncomment the following line and run `defang cert generate` to generate an ssl certificate for your domain | ||
# domainname: notebooks.mycompany.com | ||
build: | ||
context: ./jupyter | ||
ports: | ||
- mode: ingress | ||
target: 8888 | ||
published: 8888 | ||
environment: | ||
JUPYTER_TOKEN: | ||
POSTGRES_PASSWORD: | ||
healthcheck: | ||
test: ["CMD", "curl", "-f", "http://localhost:8888/login" ] | ||
depends_on: | ||
- db | ||
|
||
db: | ||
image: postgres:14 | ||
x-defang-postgres: true | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready -U postgres"] | ||
environment: | ||
POSTGRES_PASSWORD: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM jupyter/datascience-notebook | ||
|
||
# 4.002 Error: pg_config executable not found. | ||
# make sure the development packages are installed | ||
|
||
USER root | ||
|
||
RUN apt-get update && apt-get install -y libpq-dev | ||
|
||
USER 1000 | ||
|
||
COPY requirements.txt /tmp/ | ||
RUN pip install --no-cache-dir -r /tmp/requirements.txt |
Oops, something went wrong.