# Update deployments after code changes

Instructions to reset / update the deployments

## Login

* Log in as `dev` user on the deployments VM

* All the deployments are placed in the `/srv` directory:

  ```bash
  cd /srv
  ```

## stage0 laconicd

* Deployment dir: `/srv/laconicd/stage0-deployment`

* If code has changed, fetch and build with updated source code:

  ```bash
  # laconicd source
  cd ~/cerc/laconicd

  # Pull latest changes, or checkout to the required branch
  git pull

  # Confirm the latest commit hash
  git log

  # Rebuild the containers
  cd /srv/laconicd

  laconic-so --stack ~/cerc/fixturenet-laconicd-stack/stack-orchestrator/stacks/fixturenet-laconicd build-containers --force-rebuild
  ```

* Optionally, reset the data directory (this will remove all stage0 data!):

  ```bash
  # Stop the deployment
  laconic-so deployment --dir stage0-deployment stop --delete-volumes

  # Remove and recreate the required data dir
  sudo rm -rf stage0-deployment/data/laconicd-data
  mkdir stage0-deployment/data/laconicd-data
  ```

* Start the deployment:

  ```bash
  laconic-so deployment --dir stage0-deployment start

  # Follow logs for laconicd container, check that new blocks are getting created
  laconic-so deployment --dir stage0-deployment logs laconicd -f
  ```

* If the stage0 laconicd chain has been reset, reset the faucet deployment too with new faucet key:

  ```bash
  cd /srv/faucet

  export FAUCET_ACCOUNT_PK=$(laconic-so deployment --dir /srv/laconicd/stage0-deployment exec laconicd "echo y | laconicd keys export alice --keyring-backend test --unarmored-hex --unsafe")

  cat <<EOF > laconic-faucet-deployment/config.env
  CERC_FAUCET_KEY=$FAUCET_ACCOUNT_PK
  EOF

  # Stop the deployment
  laconic-so deployment --dir laconic-faucet-deployment stop --delete-volumes

  # Remove and recreate the required data dir
  sudo rm -rf laconic-faucet-deployment/data/faucet-data
  mkdir laconic-faucet-deployment/data/faucet-data

  # Start the deployment
  laconic-so deployment --dir laconic-faucet-deployment start
  ```

## testnet-onboarding-app

* Deployment dir: `/srv/app/onboarding-app-deployment`

* If code has changed, fetch and build with updated source code:

  ```bash
  # testnet-onboarding-app source
  cd ~/cerc/testnet-onboarding-app

  # Pull latest changes, or checkout to the required branch
  git pull

  # Confirm the latest commit hash
  git log

  # Rebuild the containers
  cd /srv/app

  laconic-so --stack ~/cerc/testnet-onboarding-app-stack/stack-orchestrator/stacks/onboarding-app build-containers --force-rebuild
  ```

* Update the configuration, if required in `onboarding-app-deployment/config.env`:

  ```bash
  WALLET_CONNECT_ID=63...

  CERC_REGISTRY_GQL_ENDPOINT="https://laconicd.laconic.com/api"
  CERC_LACONICD_RPC_ENDPOINT="https://laconicd.laconic.com"

  CERC_FAUCET_ENDPOINT="https://faucet.laconic.com"

  CERC_WALLET_META_URL="https://loro-signup.laconic.com"

  CERC_STAKING_AMOUNT=1000000000000000
  ````

* Restart the deployment:

  ```bash
  laconic-so deployment --dir onboarding-app-deployment stop

  laconic-so deployment --dir onboarding-app-deployment start

  # Follow logs for testnet-onboarding-app container, wait for the build to finish
  laconic-so deployment --dir onboarding-app-deployment logs testnet-onboarding-app -f
  ```

* The updated onboarding app can now be viewed at <https://loro-signup.laconic.com>

## laconic-wallet-web

* Deployment dir: `/srv/wallet/laconic-wallet-web-deployment`

* If code has changed, fetch and build with updated source code:

  ```bash
  # testnet-onboarding-app source
  cd ~/cerc/laconic-wallet-web

  # Pull latest changes, or checkout to the required branch
  git pull

  # Confirm the latest commit hash
  git log

  # Rebuild the containers
  cd /srv/wallet

  laconic-so --stack ~/cerc/laconic-wallet-web/stack/stack-orchestrator/stack/laconic-wallet-web build-containers --force-rebuild
  ```

* Update the configuration, if required in `laconic-wallet-web-deployment/config.env`:

  ```bash
  WALLET_CONNECT_ID=63...
  ```

* Restart the deployment:

  ```bash
  laconic-so deployment --dir laconic-wallet-web-deployment stop

  laconic-so deployment --dir laconic-wallet-web-deployment start

  # Follow logs for laconic-wallet-web container, wait for the build to finish
  laconic-so deployment --dir laconic-wallet-web-deployment logs laconic-wallet-web -f
  ```

* The web wallet can now be viewed at <https://wallet.laconic.com>

## stage1 laconicd

* Deployment dir: `/srv/laconicd/stage1-deployment`

* If code has changed, fetch and build with updated source code:

  ```bash
  # laconicd source
  cd ~/cerc/laconicd

  # Pull latest changes, or checkout to the required branch
  git pull

  # Confirm the latest commit hash
  git log

  # Rebuild the containers
  cd /srv/laconicd

  laconic-so --stack ~/cerc/fixturenet-laconicd-stack/stack-orchestrator/stacks/fixturenet-laconicd build-containers --force-rebuild
  ```

* Optionally, reset the data directory:

  ```bash
  # Stop the deployment
  laconic-so deployment --dir stage1-deployment stop --delete-volumes

  # Remove and recreate the required data dirs
  sudo rm -rf stage1-deployment/data/laconicd-data stage1-deployment/data/genesis-config

  mkdir stage1-deployment/data/laconicd-data
  mkdir stage1-deployment/data/genesis-config
  ```

* Update the configuration, if required in `stage1-deployment/config.env`:

  ```bash
  AUTHORITY_AUCTION_ENABLED=true
  AUTHORITY_AUCTION_COMMITS_DURATION=3600
  AUTHORITY_AUCTION_REVEALS_DURATION=3600
  AUTHORITY_GRACE_PERIOD=7200
  ```

* Follow [stage0-to-stage1.md](./stage0-to-stage1.md) to generate the genesis file for stage1 and start the deployment

## laconic-console

* Deployment dir: `/srv/console/laconic-console-deployment`

* If code has changed, fetch and build with updated source code:

  ```bash
  # testnet-onboarding-app source
  cd ~/cerc/laconic-console

  # Pull latest changes, or checkout to the required branch
  git pull

  # Confirm the latest commit hash
  git log

  # Rebuild the containers
  cd /srv/console

  laconic-so --stack ~/cerc/testnet-laconicd-stack/stack-orchestrator/stacks/laconic-console build-containers --force-rebuild
  ```

* Update the configuration, if required in `laconic-console-deployment/config.env`:

  ```bash
  # Laconicd (hosted) GQL endpoint
  LACONIC_HOSTED_ENDPOINT=https://laconicd.laconic.com
  ```

* Restart the deployment:

  ```bash
  laconic-so deployment --dir laconic-console-deployment stop

  laconic-so deployment --dir laconic-console-deployment start

  # Follow logs for console container
  laconic-so deployment --dir laconic-console-deployment logs console -f
  ```

* The laconic console can now be viewed at <https://loro-console.laconic.com>

---

## stage2 laconicd

* Deployment dir: `/srv/laconicd/stage2-deployment`

* If code has changed, fetch and build with updated source code:

  ```bash
  # laconicd source
  cd ~/cerc/laconicd

  # Pull latest changes, or checkout to the required branch
  git pull

  # Confirm the latest commit hash
  git log

  # Rebuild the containers
  cd /srv/laconicd

  laconic-so --stack ~/cerc/fixturenet-laconicd-stack/stack-orchestrator/stacks/fixturenet-laconicd build-containers --force-rebuild
  ```

* Optionally, reset the data directory:

  ```bash
  # Stop the deployment
  laconic-so deployment --dir stage2-deployment stop --delete-volumes

  # Remove and recreate the required data dirs
  sudo rm -rf stage2-deployment/data/laconicd-data stage2-deployment/data/genesis-config

  mkdir stage2-deployment/data/laconicd-data
  mkdir stage2-deployment/data/genesis-config
  ```

* Follow [stage1-to-stage2.md](./stage1-to-stage2.md) to reinitialize stage2 and start the deployment

## laconic-console-testnet2

* Deployment dir: `/srv/console/laconic-console-testnet2-deployment`

* Steps to update the deployment similar as in [laconic-console](#laconic-console)

## Laconic Shopify

* Deployment dir: `/srv/shopify/laconic-shopify-deployment`

* If code has changed, fetch and build with updated source code:

  ```bash
  laconic-so --stack ~/cerc/testnet-laconicd-stack/stack-orchestrator/stacks/laconic-shopify setup-repositories --git-ssh --pull

  # rebuild containers
  laconic-so --stack ~/cerc/testnet-laconicd-stack/stack-orchestrator/stacks/laconic-shopify build-containers --force-rebuild
  ```

* Update the configuration if required in `laconic-shopify-deployment/config.env`

* Restart the deployment:

  ```bash
  cd /srv/shopify

  laconic-so deployment --dir laconic-shopify-deployment stop

  laconic-so deployment --dir laconic-shopify-deployment start
  ```

## webapp-deployer

### Backend

* Deployment dir: `/srv/service-provider/webapp-deployer`

* If code has changed, fetch and build with updated source code:

  ```bash
  laconic-so --stack webapp-deployer-backend setup-repositories --git-ssh --pull

  laconic-so --stack webapp-deployer-backend build-containers --force-rebuild
  ```

* Update the configuration, if required in :
  * `/srv/service-provider/webapp-deployer/data/config/laconic.yml`
  * `/srv/service-provider/webapp-deployer/config.env`

* Restart the deployment:

  ```bash
  laconic-so deployment --dir webapp-deployer stop

  laconic-so deployment --dir webapp-deployer start
  ```

* Load context for k8s

  ```bash
  kubie ctx vs-narwhal
  ```

* Copy the GPG key file to the webapp-deployer container

  ```bash
  # Get the webapp-deployer pod id
  laconic-so deployment --dir webapp-deployer ps

  # Expected output
  # Running containers:
  # id: default/laconic-096fed46af974a47-deployment-644db859c7-snbq6, name: laconic-096fed46af974a47-deployment-644db859c7-snbq6, ports: 10.42.2.11:9555->9555

  # Set pod id
  export POD_ID=
  # Example:
  # export POD_ID=laconic-096fed46af974a47-deployment-644db859c7-snbq6

  # Copy GPG key files to the pod
  kubectl cp webapp-deployer/webapp-deployer-api.apps.vaasl.io.pgp.key $POD_ID:/app
  kubectl cp webapp-deployer/webapp-deployer-api.apps.vaasl.io.pgp.pub $POD_ID:/app
  ```

### Frontend

* Deployment dir: `/srv/service-provider/webapp-ui`

* If code has changed, fetch and build with updated source code:

  ```bash
  cd ~/cerc/webapp-deployment-status-ui

  # Pull latest changes, or checkout to the required branch
  git pull

  # Confirm the latest commit hash
  git log

  laconic-so build-webapp --source-repo ~/cerc/webapp-deployment-status-ui
  ```

* Modify `/srv/service-provider/webapp-ui/config.env` like [this Pull Request](https://git.vdb.to/cerc-io/webapp-deployment-status-ui/pulls/6) but with your host details.

* Restart the deployment:

  ```bash
  laconic-so deployment --dir webapp-ui stop

  laconic-so deployment --dir webapp-ui start
  ```

## Deploy Backend

* Deployment dir: `/srv/deploy-backend/laconic-backend-deployment`

* If code has changed, fetch and build with updated source code:

  ```bash
  laconic-so --stack ~/cerc/snowballtools-base-api-stack/stack-orchestrator/stacks/snowballtools-base-backend setup-repositories --git-ssh --pull

  # rebuild containers
  laconic-so --stack ~/cerc/snowballtools-base-api-stack/stack-orchestrator/stacks/snowballtools-base-backend build-containers --force-rebuild
  ```

* Push updated images to the container registry:

  ```bash
  cd /srv/deploy-backend

  # login to container registry
  CONTAINER_REGISTRY_URL=container-registry.apps.vaasl.io
  # For credentials: "cat /srv/service-provider/webapp-deployer/config.env | grep IMAGE_REGISTRY"
  CONTAINER_REGISTRY_USERNAME=
  CONTAINER_REGISTRY_PASSWORD=

  docker login $CONTAINER_REGISTRY_URL --username $CONTAINER_REGISTRY_USERNAME --password $CONTAINER_REGISTRY_PASSWORD

  # Push backend images
  laconic-so deployment --dir laconic-backend-deployment push-images
  ```

* Update the configuration if required in `laconic-backend-deployment/configmaps/config/prod.toml`

* Restart the deployment:

  ```bash
  laconic-so deployment --dir laconic-backend-deployment stop

  laconic-so deployment --dir laconic-backend-deployment start
  ```

## Deply Frontend

* Follow steps similar to [deployments-from-scratch.md](./deployments-from-scratch.md#deploy-frontend) to deploy the snowball frontend
  * Use auhority `laconic-deploy` and the script `deploy-frontend.sh` instead

## Fixturenet Eth

* Deployment dir: `/srv/fixturenet-eth/fixturenet-eth-deployment`

* If code has changed, fetch and build with updated source code:

  ```bash
  laconic-so --stack ~/cerc/fixturenet-eth-stacks/stack-orchestrator/stacks/fixturenet-eth setup-repositories --git-ssh --pull

  # Rebuild the containers
  laconic-so --stack ~/cerc/fixturenet-eth-stacks/stack-orchestrator/stacks/fixturenet-eth build-containers --force-rebuild
  ```

* Update the configuration if required in `fixturenet-eth-deployment/config.env`:

  ```bash
  CERC_ALLOW_UNPROTECTED_TXS=true
  ```

* Restart the deployment:

  ```bash
  cd /srv/fixturenet-eth

  laconic-so deployment --dir fixturenet-eth-deployment stop

  laconic-so deployment --dir fixturenet-eth-deployment start
  ```

## Nitro Bridge

* Deployment dir: `/srv/bridge/bridge-deployment`

* Rebuild containers:

  ```bash
  # Rebuild the containers
  laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/bridge build-containers --force-rebuild
  ```

* Update the configuration if required in `bridge-deployment/config.env`

* Restart the bridge deployment:

  ```bash
  cd /srv/bridge

  laconic-so deployment --dir bridge-deployment stop

  laconic-so deployment --dir bridge-deployment start
  ```
