# deployer

- Install dependencies
  ```bash
  yarn
  ```

- Replace variables in the following files
  - [records/application-deployment-request.yml](records/application-deployment-request.yml)
    - `<CURRENT_DATE_TIME>`: Replace with current time which can be generated by command `date -u`
      ```yml
      # Example
      record:
        ...
        meta:
          note: Added by Snowball @ Friday 23 February 2024 06:35:50 AM UTC
          ...
      ```

- Update record version in [records/application-record.yml](records/application-record.yml)
  ```yml
  record:
    type: ApplicationRecord
    version: <NEW_VERSION>
    ...
  ```

- Update commit hash in the following places:
  - [records/application-record.yml](records/application-record.yml)
    ```yml
    record:
      ...
      repository_ref: <COMMIT_HASH>
      ...
    ```
  - [records/application-deployment-request.yml](records/application-deployment-request.yml)
    ```yml
    record:
      ...
      meta:
        ...
        repository_ref: <COMMIT_HASH>
    ```
  - [deploy-frontend.sh](deploy-frontend.sh)
    ```bash
    ...
    RCD_APP_VERSION="0.1.0"
    REPO_REF="<COMMIT_HASH>"
    ...
    ```

- Run script to deploy app
  ```
  ./deploy-frontend.sh
  ```

- Commit the updated [ApplicationRecord](records/application-record.yml) and [ApplicationDeploymentRequest](records/application-deployment-request.yml) files to the repository

## Notes

- Any config env can be updated in [records/application-deployment-request.yml](records/application-deployment-request.yml)
  ```yml
  record:
    ...
    config:
      env:
        LACONIC_HOSTED_CONFIG_app_server_url: https://snowballtools-base-api-001.apps.snowballtools.com
        ...
  ```
  - On changing `LACONIC_HOSTED_CONFIG_app_github_clientid`, the GitHub client ID and secret need to be changed in backend config too

## Troubleshoot

- If deployment fails due to low bond balance
  - Check balances
    ```bash
    # Account balance
    yarn laconic cns account get

    # Bond balance
    yarn laconic cns bond get --id 8fcf44b2f326b4b63ac57547777f1c78b7d494e5966e508f09001af53cb440ac
    ```
  - Command to refill bond
    ```bash
    yarn laconic cns bond refill --id 8fcf44b2f326b4b63ac57547777f1c78b7d494e5966e508f09001af53cb440ac --type aphoton --quantity 10000000
    ```