# Deploy on Phala

Your proxy runs our published image inside an Intel TDX enclave on Phala Cloud. The enclave proves to our router exactly what code is running. It keeps your keys sealed away from everyone, including Phala and us.

## The compose file

The installer puts this file in `~/.local/share/sn46/compose.yml`. You can also save it yourself as `compose.yml`:

```yaml
services:
  sn46-proxy:
    image: ghcr.io/subnet46/sn46-proxy@sha256:daf8bbf6b7d705f21f3603214d5e184b1235913231838d1ea54cc0d808a8c6ac
    restart: always
    ports:
      - '8443:8443'
    volumes:
      - /var/run/dstack.sock:/var/run/dstack.sock
    environment:
      - SN46_HOTKEY
      - SN46_KEYS_DEEPINFRA
      - SN46_KEYS_CHEAPERINFERENCE
      - SN46_KEYS_SURPLUS
      - SN46_KEYS_OPENSCALE
      - SN46_KEYS_ENGY
      - SN46_KEYS_REDPILL
```

It pins the current release image by digest:

```text
ghcr.io/subnet46/sn46-proxy@sha256:daf8bbf6b7d705f21f3603214d5e184b1235913231838d1ea54cc0d808a8c6ac
```

Every published digest is listed on [GitHub](https://github.com/orgs/Subnet46/packages/container/package/sn46-proxy). Use the published digest exactly: our control plane only accepts enclaves running a released image.

## Your env file

Write a private env file with your hotkey's ss58 address and your provider keys. Leave out the providers you don't use. For several keys from one provider, separate them with commas.

```sh
cat > proxy.env <<'ENV'
SN46_HOTKEY=<your hotkey ss58 address>
SN46_KEYS_DEEPINFRA=<key 1>,<key 2>
SN46_KEYS_SURPLUS=<your key>
ENV
chmod 600 proxy.env
```

These are the only variables the enclave accepts. Phala encrypts them to your enclave on deploy, so they never travel in the clear and are never sent anywhere else. The full list of providers and their variables is on the [providers page](https://docs.instantnetwork.ai/miners/providers).

## Deploy

```sh
npx phala@1.2.8 auth login
npx phala@1.2.8 deploy -n sn46-proxy -t tdx.small -c compose.yml -e proxy.env --wait
```

The proxy listens on port 8443 with its own TLS. Its public address is the CVM's `-8443s` passthrough address:

```text
https://<app-id>-8443s.<gateway domain>
```

`npx phala@1.2.8 cvms get` shows it. Note your **CVM id** and this **proxy address**: you need the address to [register](https://docs.instantnetwork.ai/miners/register), and the CVM id for [auto-update](https://docs.instantnetwork.ai/miners/auto-update).

## Keep a template for auto-update

Auto-update fills in each new release's digest. Keep a copy of your compose file with the digest replaced by a placeholder:

```sh
sed 's/@sha256:[0-9a-f]*/@{{image_digest}}/' compose.yml > compose.template.yml
```

## Check the image yourself

The proxy image is built reproducibly from [the source](https://github.com/Subnet46/v2-sn46-miner-proxy): `images/build.sh release <out dir>` builds it, and `images/check-release.sh` compares two builds of one commit. Anyone can check that a digest comes from that source.

Next: [register your proxy](https://docs.instantnetwork.ai/miners/register).
