Phala Network Docs
  • Home
    • 👾Phala Network Docs
  • Overview
    • ⚖️Phala Network
      • 💎Phala Cloud
      • 🥷Dstack
      • 🔐GPU TEE
    • 💎PHA Token
      • 🪙Introduction
      • 👐Delegation
        • Delegate to StakePool
        • What is Vault
        • What is Share
        • WrappedBalances & W-PHA
        • Examples of Delegation
        • Use Phala App to Delegate
        • Estimate Your Reward
      • 🗳️Governance
        • Governance Mechanism
        • Join the Council
        • Voting for Councillors
        • Apply for Project Funding
        • Phala Treasury
        • Phala Governance
        • Setting Up an Account Identity
  • Phala Cloud
    • 🚀Getting Started
      • Create Your Phala Cloud Account
      • Your First CVM Deployment
      • Explore Templates
        • Launch an Eliza Agent
        • Start from Template
    • 🪨TEEs, Attestation & Zero Trust Security
      • Attestation
      • Security Architecture
    • 🥷Phala Cloud User Guides
      • Deploy and Manage CVMs
        • Deploy CVM with Docker Compose
        • Set Secure Environment Variables
        • Deploy Private Docker Image to CVM
        • Debugging and Analyzing Logs
          • Check Logs
          • Private Log Viewer
          • Debug Your Application
        • Application Scaling & Resource Management
        • Upgrade Application
        • Deployment Cheat Sheet
      • Building with TEE
        • Access Your Applications
        • Expose Service Port
        • Setting Up Custom Domain
        • Secure Access Database
        • Create Crypto Wallet
        • Generate Remote Attestation
      • Advanced Deployment Options
        • Deploy CVM with Phala Cloud CLI
        • Deploy CVM with Phala Cloud API
        • Setup a CI/CD Pipeline
    • 🚢Be Production Ready
      • CI/CD Automation
        • Setup a CI/CD Pipeline
      • Production Checklist
      • Troubleshooting Guide
      • Glossary
    • 🔒Use Cases
      • TEE with AI
      • TEE with FHE and MPC
      • TEE with ZK and ZKrollup
    • 📋References
      • Phala Cloud CLI Reference
        • phala
          • auth
          • cvms
          • docker
          • simulator
      • Phala Cloud API & SDKs
        • API Endpoints & Examples
        • SDKs and Integrations
      • Phala Cloud Pricing
    • ❓FAQs
  • Dstack
    • Overview
    • Getting Started
    • Hardware Requirements
    • Design Documents
      • Decentralized Root-of-Trust
      • Key Management Service
      • Zero Trust HTTPs (TLS)
    • Acknowledgement
  • LLM in GPU TEE
    • 👩‍💻Host LLM in GPU TEE
    • 🔐GPU TEE Inference API
    • 🏎️GPU TEE Benchmark
  • Tech Specs
    • ⛓️Blockchain
      • Blockchain Entities
      • Cluster of Workers
      • Secret Key Hierarchy
  • References
    • 🔐Setting Up a Wallet on Phala
      • Acquiring PHA
    • 🌉SubBridge
      • Cross-chain Transfer
      • Supported Assets
      • Asset Integration Guide
      • Technical Details
    • 👷Community Builders
    • 🤹Hackathon Guides
      • ETHGlobal Singapore
      • ETHGlobal San Francisco
      • ETHGlobal Bangkok
    • 🤯Advanced Topics
      • Cross Chain Solutions
      • System Contract and Drivers
      • Run Local Testnet
      • SideVM
    • 🆘Support
      • Available Phala Chains
      • Resource Limits
      • Transaction Costs
      • Compatibility Matrix
      • Block Explorers
      • Faucet
    • ⁉️FAQ
  • Compute Providers
    • 🙃Basic Info
      • Introduction
      • Gemini Tokenomics (Worker Rewards)
      • Budget balancer
      • Staking Mechanism
      • Requirements in Phala
      • Confidence Level & SGX Function
      • Rent Hardware
      • Error Summary
    • 🦿Run Workers on Phala
      • Solo Worker Deployment
      • PRBv3 Deployment
      • Using PRBv3 UI
      • PRB Worker Deployment
      • Switch Workers from Solo to PRB Mode
      • Headers-cache deployment
      • Archive node deployment
    • 🛡️Gatekeeper
      • Collator
      • Gatekeeper
  • Web Directory
    • Discord
    • GitHub
    • Twitter
    • YouTube
    • Forum
    • Medium
    • Telegram
Powered by GitBook
LogoLogo

Participate

  • Compute Providers
  • Node
  • Community
  • About Us

Resources

  • Technical Whitepaper
  • Token Economics
  • Docs
  • GitHub

More

  • Testnet
  • Explorer
  • Careers
  • Responsible Disclosure

COPYRIGHT © 2024 PHALA.LTD ALL RIGHTS RESERVED. May Phala be with you!

On this page

Was this helpful?

Edit on GitHub
  1. Phala Cloud
  2. Getting Started
  3. Explore Templates

Start from Template

PreviousLaunch an Eliza AgentNextTEEs, Attestation & Zero Trust Security

Last updated 1 month ago

Was this helpful?

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 Start

Make sure you have or started before you begin. Also, make sure you have gone through the section before continuing.

Phala Cloud Next.js Starter

This is a template for developing a -based app with boilerplate code targeting deployment on and . 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.

Requirements

  • >= v18.18

  • Docker or Orbstack

Development

First, you need to clone this repo:

git clone --depth 1 https://github.com/Phala-Network/phala-cloud-nextjs-starter.git

Next, let's initialize the development environment:

yarn
cp env.local.example .env.local

We 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.sock

Once the simulator is running, you need to open another terminal to start your Next.js development server:

yarn dev

By 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: The reportdata is test and generates the quote for attestation report via tdxQuote API.

  • /api/eth_account/address: Using the deriveKey API to generate a deterministic wallet for Ethereum, a.k.a. a wallet held by the TEE instance.

  • /api/solana_account/address: Using the deriveKey API to generate a deterministic wallet for Solana, a.k.a. a wallet held by the TEE instance.

  • /api/info: Returns the TCB Info of the hosted CVM.

Build and Publish to Docker Registry

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.

Build and Publish with Docker CLI

docker build . -t <docker-username>/my-app:latest
docker push <docker-username>/my-app:latest

Build and Publish with Phala Cloud CLI

npx phala docker build -i my-app -t latest -f ./Dockerfile
npx phala docker push -i <docker-username>/my-app:latest

Now we have an official docker image for our nextjs app. Let's deploy to Phala Cloud now.

Deploy to Phala Cloud

You can copy and paste the docker-compose.yml file from this repo to see the example up and running.

Deploy in Phala UI

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/tappd.sock:/var/run/tappd.sock

Deploy via Phala Cloud CLI

For those using the CLI, you can deploy from the terminal with:

Make sure to change the imagefield to match your published docker image (ex: hashwarlock/my-app:latest)

npx phala cvms create -c docker-compose.yml -n my-app

Interact with Your Next.js App in Phala Cloud

Your application should be deployed now to your Phala Cloud dashboard. Go to the Network tab to be able to open your application.

Phala Cloud Python Starter

Development

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.git

Next, 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 .env

We 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.sock

Once 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 dev

Build and Publish with Docker CLI

docker build . -t <docker-username>/my-app:latest
docker push <docker-username>/my-app:latest

Build and Publish with Phala Cloud CLI

npx phala docker build -i my-app -t latest -f ./Dockerfile
npx phala docker push -i <docker-username>/my-app:latest

Now we have an official docker image for our nextjs app. Let's deploy to Phala Cloud now.

Deploy to Phala Cloud

You can copy and paste the docker-compose.yml file from this repo to see the example up and running.

Deploy in Phala UI

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/tappd.sock:/var/run/tappd.sock

Now you can interact with your application by going to the Network tab and making calls like the following.

Conclusion

/api/tdx_quote_raw: The reportdata is Hello DStack! and generates the quote for attestation report. The difference from /api/dx_quote is that you can see the raw text Hello DStack! in .

This is a template for developing a -based app with boilerplate code targeting deployment on and . 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.

By default, the FastAPI development server will listen on port 8000. Open in your browser to get the quote with reportdata test.

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 .

🚀
Docker Desktop
OrbStack
Sign-up for Cloud Account
Next.js
Phala Cloud
DStack
Node
yarn
Attestation Explorer
FastAPI
Phala Cloud
DStack
http://127.0.0.1:8000/tdx_quote
Design Documents
/tdx_quote
/derive_key
/eth_account
/sol_account