| description | Get started quickly with Next.js and Python templates on Phala Cloud. |
|---|---|
| title | NextJS & Python |
There are a couple templates that we offer to allow you to get started without any heavy lifting. The steps to get started are simple and easy to test in a few minutes.
#### Before You StartMake sure you have Docker Desktop or OrbStack started before you begin.
Also, make sure you have gone through the Sign-up for Cloud Account section before continuing.
This is a template for developing a Next.js-based app with boilerplate code targeting deployment on Phala Cloud and DStack. It includes the SDK by default to make integration with TEE features easier. This repo also includes a default Dockerfile and docker-compose.yml for deployment.
First, you need to clone this repo:
git clone --depth 1 https://github.com/Phala-Network/phala-cloud-nextjs-starter.gitNext, let's initialize the development environment:
yarn
cp env.local.example .env.localWe also need to download the dstack simulator:
# Mac
wget https://github.com/Leechael/tappd-simulator/releases/download/v0.1.4/tappd-simulator-0.1.4-aarch64-apple-darwin.tgz
tar -xvf tappd-simulator-0.1.4-aarch64-apple-darwin.tgz
cd tappd-simulator-0.1.4-aarch64-apple-darwin
./tappd-simulator -l unix:/tmp/tappd.sock
# Linux
wget https://github.com/Leechael/tappd-simulator/releases/download/v0.1.4/tappd-simulator-0.1.4-x86_64-linux-musl.tgz
tar -xvf tappd-simulator-0.1.4-x86_64-linux-musl.tgz
cd tappd-simulator-0.1.4-x86_64-linux-musl
./tappd-simulator -l unix:/tmp/tappd.sockOnce the simulator is running, you need to open another terminal to start your Next.js development server:
yarn devBy default, the Next.js development server will listen on port 3000. Open http://127.0.0.1:3000/ in your browser and check.
This repo also includes code snippets for the following common use cases:
/api/tdx_quote: Thereportdataistestand generates the quote for attestation report viagetQuoteAPI./api/tdx_quote_raw: ThereportdataisHello DStack!and generates the quote for attestation report. The difference from/api/dx_quoteis that you can see the raw textHello DStack!in Attestation Explorer./api/eth_account/address: Using thegetKeyAPI to generate a deterministic wallet for Ethereum, a.k.a. a wallet held by the TEE instance./api/solana_account/address: Using thegetKeyAPI to generate a deterministic wallet for Solana, a.k.a. a wallet held by the TEE instance.
You need to build the image and push it to DockerHub for deployment. The following instructions are for publishing to a public registry via DockerHub:
For this to be logged into Docker to push to registry. Run docker login to login in the CLI.docker build . -t <docker-username>/my-app:latest
docker push <docker-username>/my-app:latestNow we have an official docker image for our nextjs app. Let's deploy to Phala Cloud now.
You can copy and paste the docker-compose.yml file from this repo to see the example up and running.
Go to your Phala Cloud dashboard and click Deploy. You will have an option for deploying via docker compose file. Click on this option to deploy.
You will come to a CVM configuration page. Click on Advanced and replace the default docker compose contents with the following (Make sure to replace the <docker-username>with your own:
services:
app:
image: <docker-username>/my-app:latest
container_name: app
ports:
- "3000:3000"
volumes:
- /var/run/dstack.sock:/var/run/dstack.sock
For those using the CLI, you can deploy from the terminal with:
Make sure to change the `image` field to match your published docker image (ex: `0xii/my-app:latest`)npx phala deploy -c docker-compose.yml -n my-appYour application should be deployed now to your Phala Cloud dashboard. Go to the Network tab to be able to open your application.
This is a template for developing a FastAPI-based app with boilerplate code targeting deployment on Phala Cloud and Dstack. It includes the SDK by default to make integration with TEE features easier. This repo also includes a default Dockerfile and docker-compose.yml for deployment.
In this tutorial, we'll start with venv and pip. First, you need to clone this repo:
git clone --depth 1 https://github.com/Phala-Network/phala-cloud-python-starter.gitNext, let's initialize the development environment with venv & pip:
python -m venv venv
source venv/bin/activate
python -m pip install -r requirements.txt
cp env.example .envWe also need to download the dstack simulator:
# Mac
wget https://github.com/Leechael/tappd-simulator/releases/download/v0.1.4/tappd-simulator-0.1.4-aarch64-apple-darwin.tgz
tar -xvf tappd-simulator-0.1.4-aarch64-apple-darwin.tgz
cd tappd-simulator-0.1.4-aarch64-apple-darwin
./tappd-simulator -l unix:/tmp/tappd.sock
# Linux
wget https://github.com/Leechael/tappd-simulator/releases/download/v0.1.4/tappd-simulator-0.1.4-x86_64-linux-musl.tgz
tar -xvf tappd-simulator-0.1.4-x86_64-linux-musl.tgz
cd tappd-simulator-0.1.4-x86_64-linux-musl
./tappd-simulator -l unix:/tmp/tappd.sockOnce the simulator is running, you need to open another terminal to start your FastAPI development server:
# Activate the Python venv
source venv/bin/activate
# Start the FastAPI dev server
python -m fastapi devBy default, the FastAPI development server will listen on port 8000. Open http://127.0.0.1:8000/tdx_quote in your browser to get the quote with reportdata test.
docker build . -t <docker-username>/my-app:latest
docker push <docker-username>/my-app:latestNow we have an official docker image for our Python app. Let's deploy to Phala Cloud now.
You can copy and paste the docker-compose.yml file from this repo to see the example up and running.
Go to your Phala Cloud dashboard and click Deploy. You will have an option for deploying via docker compose file. Click on this option to deploy.
You will come to a CVM configuration page. Click on Advanced and replace the default docker compose contents with the following (Make sure to replace the <docker-username>with your own:
services:
app:
image: <docker-username>/my-app:latest
container_name: app
ports:
- "8000:8000"
volumes:
- /var/run/dstack.sock:/var/run/dstack.sock
Now you can interact with your application by going to the Network tab and making calls like the following.
And output of GET /eth_account
{
"address":"0xf75647Ec8372BF710D95ad634EDb1ED198CeAE6C"
}Output of GET /sol_account
{
"address":"5JPbG1BP7pZQWsoqQsyCLSvs56SpC2ZAgSHLouVX5Vdn"
}The last 2 tutorials were key to understanding the basics of deploying a Docker app on a TEE Server. Now you are ready to start building on dstack! For more info on the design of dstack, check out the Design Documents.







