|
| 1 | +# Jupyter & Postgres |
| 2 | + |
| 3 | +[](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 |
0 commit comments