Skip to content

Commit

Permalink
feat: add new "deploy" command to execute user/template defined logic…
Browse files Browse the repository at this point in the history
… to deploy smart contracts to an Algorand network (#295)

---------
Co-authored-by: Altynbek Orumbayev <altynbek.orumbayev@makerx.com.au>
Co-authored-by: Adam Chidlow <achidlow@users.noreply.github.com>
Co-authored-by: Daniel McGregor <daniel.mcgregor@makerx.com.au>
  • Loading branch information
aorumbayev authored and achidlow committed Jul 13, 2023
1 parent 6c2d5e2 commit 6673f80
Show file tree
Hide file tree
Showing 108 changed files with 1,559 additions and 296 deletions.
73 changes: 62 additions & 11 deletions docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,51 @@
- [Options](#options-1)
- [--force](#--force)
- [all](#all)
- [Options](#options-2)
- [--interactive, --non-interactive, --ci](#--interactive---non-interactive---ci)
- [env](#env)
- [Options](#options-3)
- [--interactive, --non-interactive, --ci](#--interactive---non-interactive---ci-1)
- [npm](#npm)
- [poetry](#poetry)
- [completions](#completions)
- [install](#install)
- [Options](#options-2)
- [Options](#options-4)
- [--shell ](#--shell-)
- [uninstall](#uninstall)
- [Options](#options-3)
- [Options](#options-5)
- [--shell ](#--shell--1)
- [config](#config)
- [version-prompt](#version-prompt)
- [Arguments](#arguments)
- [ENABLE](#enable)
- [deploy](#deploy)
- [Options](#options-6)
- [-C, --command ](#-c---command-)
- [--interactive, --non-interactive, --ci](#--interactive---non-interactive---ci-2)
- [-P, --path ](#-p---path-)
- [Arguments](#arguments-1)
- [ENVIRONMENT_NAME](#environment_name)
- [doctor](#doctor)
- [Options](#options-4)
- [Options](#options-7)
- [-c, --copy-to-clipboard](#-c---copy-to-clipboard)
- [explore](#explore)
- [Arguments](#arguments-1)
- [Arguments](#arguments-2)
- [NETWORK](#network)
- [generate](#generate)
- [client](#client)
- [Options](#options-5)
- [Options](#options-8)
- [-o, --output ](#-o---output-)
- [-l, --language ](#-l---language-)
- [Arguments](#arguments-2)
- [Arguments](#arguments-3)
- [APP_SPEC_PATH_OR_DIR](#app_spec_path_or_dir)
- [goal](#goal)
- [Options](#options-6)
- [Options](#options-9)
- [--console](#--console)
- [Arguments](#arguments-3)
- [Arguments](#arguments-4)
- [GOAL_ARGS](#goal_args)
- [init](#init)
- [Options](#options-7)
- [Options](#options-10)
- [-n, --name ](#-n---name-)
- [-t, --template ](#-t---template-)
- [--template-url ](#--template-url-)
Expand All @@ -59,11 +70,11 @@
- [console](#console)
- [explore](#explore-1)
- [logs](#logs)
- [Options](#options-8)
- [Options](#options-11)
- [--follow, -f](#--follow--f)
- [--tail ](#--tail-)
- [reset](#reset)
- [Options](#options-9)
- [Options](#options-12)
- [--update, --no-update](#--update---no-update)
- [start](#start)
- [status](#status)
Expand Down Expand Up @@ -120,6 +131,12 @@ Runs all bootstrap sub-commands in the current directory and immediate sub direc
algokit bootstrap all [OPTIONS]
```

### Options


### --interactive, --non-interactive, --ci
Enable/disable interactive prompts. If the CI environment variable is set, defaults to non-interactive

### env

Copies .env.template file to .env in the current working directory and prompts for any unspecified values.
Expand All @@ -128,6 +145,12 @@ Copies .env.template file to .env in the current working directory and prompts f
algokit bootstrap env [OPTIONS]
```

### Options


### --interactive, --non-interactive, --ci
Enable/disable interactive prompts. If the CI environment variable is set, defaults to non-interactive

### npm

Runs npm install in the current working directory to install Node.js dependencies.
Expand Down Expand Up @@ -221,6 +244,34 @@ algokit config version-prompt [OPTIONS] [[enable|disable]]
### ENABLE
Optional argument

## deploy

Deploy smart contracts from AlgoKit compliant repository.

```shell
algokit deploy [OPTIONS] [ENVIRONMENT_NAME]
```

### Options


### -C, --command <command>
Custom deploy command. If not provided, will load the deploy command from .algokit.toml file.


### --interactive, --non-interactive, --ci
Enable/disable interactive prompts. If the CI environment variable is set, defaults to non-interactive


### -P, --path <path>
Specify the project directory. If not provided, current working directory will be used.

### Arguments


### ENVIRONMENT_NAME
Optional argument

## doctor

Diagnose potential environment issues that may affect AlgoKit
Expand Down
127 changes: 127 additions & 0 deletions docs/features/deploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# AlgoKit Deploy Feature Documentation

Deploy your smart contracts effortlessly to various networks with the AlgoKit Deploy feature. This feature is essential for automation in CI/CD pipelines and for seamless deployment to various Algorand network environments.

## Usage

```sh
$ algokit deploy [OPTIONS] [ENVIRONMENT_NAME]
```

This command deploys smart contracts from an AlgoKit compliant repository to the specified network.

### Options

- `--command, -C TEXT`: Specifies a custom deploy command. If this option is not provided, the deploy command will be loaded from the `.algokit.toml` file.
- `--interactive / --non-interactive, --ci`: Enables or disables the interactive prompt for mnemonics. When the CI environment variable is set, it defaults to non-interactive.
- `--path, -P DIRECTORY`: Specifies the project directory. If not provided, the current working directory will be used.
- `-h, --help`: Show this message and exit.

## Environment files

AlgoKit `deploy` employs both a general and network-specific environment file strategy. This allows you to set environment variables that are applicable across all networks and others that are specific to a given network.

The general environment file (`.env`) should be placed at the root of your project. This file will be used to load environment variables that are common across deployments to all networks.

For each network you're deploying to, you can optionally have a corresponding `.env.[network_name]` file. This file should contain environment variables specific to that network. Network-specific environment variables take precedence over general environment variables.

The directory layout would look like this:

```md
.
├── ... (your project files and directories)
├── .algokit.toml # Configuration file for AlgoKit
├── .env # (OPTIONAL) General environment variables common across all deployments
└── .env.[{mainnet|testnet|localnet|betanet|custom}] # (OPTIONAL) Environment variables specific to deployments to a network
```

> ⚠️ Please note that creating `.env` and `.env.[network_name]` files is only necessary if you're deploying to a custom network or if you want to override the default network configurations provided by AlgoKit. AlgoKit comes with predefined configurations for popular networks like `TestNet`, `MainNet`, `BetaNet`, or AlgoKit's `LocalNet`.
The logic for loading environment variables is as follows:

- If a `.env` file exists, the environment variables contained in it are loaded first.
- If a `.env.[network_name]` file exists, the environment variables in it are loaded, overriding any previously loaded values from the `.env` file for the same variables.

## AlgoKit Configuration File

AlgoKit uses a configuration file called `.algokit.toml` in the root of your project. The configuration file can be created using the `algokit init` command. This file will define the deployment commands for the various network environments that you want to target.

Here's an example of what the `.algokit.toml` file might look like. When deploying it will prompt for the `DEPLOYER_MNEMONIC` secret unless it is already defined as an environment variable or is deploying to localnet.

```toml
[algokit]
min_version = "v{lastest_version}"

[deploy]
command = "poetry run python -m smart_contracts deploy"
environment_secrets = [
"DEPLOYER_MNEMONIC",
]

[deploy.localnet]
environment_secrets = []
```

The `command` key under each `[deploy.{network_name}]` section should contain a string that represents the deployment command for that particular network. If a `command` key is not provided in a network-specific section, the command from the general `[deploy]` section will be used.

The `environment_secrets` key should contain a list of names of environment variables that should be treated as secrets. This can be defined in the general `[deploy]` section, as well as in the network-specific sections. The environment-specific secrets will be added to the general secrets during deployment.

The `[algokit]` section with the `min_version` key allows you to specify the minimum version of AlgoKit that the project requires.

This way, you can define common deployment logic and environment secrets in the `[deploy]` section, and provide overrides or additions for specific environments in the `[deploy.{environment_name}]` sections.

## Deploying to a Specific Network

The command requires a `ENVIRONMENT` argument, which specifies the network environment to which the smart contracts will be deployed. Please note, the `environment` argument is case-sensitive.

Example:

```sh
$ algokit deploy testnet
```

This command deploys the smart contracts to the testnet.

## Custom Project Directory

By default, the deploy command looks for the `.algokit.toml` file in the current working directory. You can specify a custom project directory using the `--project-dir` option.

Example:

```sh
$ algokit deploy testnet --project-dir="path/to/project"
```

## Custom Deploy Command

You can provide a custom deploy command using the `--custom-deploy-command` option. If this option is not provided, the deploy command will be loaded from the `.algokit.toml` file.

Example:

```sh
$ algokit deploy testnet --custom-deploy-command="your-custom-command"
```

## CI Mode

By using the `--ci` or `--non-interactive` flag, you can skip the interactive prompt for mnemonics.

This is useful in CI/CD environments where user interaction is not possible. When using this flag, you need to make sure that the mnemonics are set as environment variables.

Example:

```sh
$ algokit deploy testnet --ci
```

## Example of a Full Deployment

```sh
$ algokit deploy testnet --custom-deploy-command="your-custom-command"
```

This example shows how to deploy smart contracts to the testnet using a custom deploy command. This also assumes that .algokit.toml file is present in the current working directory, and .env.testnet file is present in the current working directory and contains the required environment variables for deploying to TestNet environment.

## Further Reading

For in-depth details, visit the [deploy](../cli/index.md#deploy) section in the AlgoKit CLI reference documentation.
Loading

2 comments on commit 6673f80

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/algokit
   __init__.py15753%6–13, 17–24, 32–34
   __main__.py220%1–3
src/algokit/cli
   completions.py105298%80, 95
   deploy.py55493%34–36, 78
   doctor.py48394%142–144
   generate.py30197%49
   goal.py30197%42
   init.py1901692%264–265, 315, 318–320, 331, 375, 401, 441, 450–452, 455–460, 473
   localnet.py91397%157, 178–179
src/algokit/core
   bootstrap.py1612485%103–104, 126, 149, 214, 217, 223–237, 246–251
   conf.py54885%10, 24, 28, 36, 38, 71–73
   deploy.py591083%60–63, 72–73, 77, 82, 89–91
   doctor.py65789%67–69, 92–94, 134
   log_handlers.py68790%50–51, 63, 112–116, 125
   proc.py45198%98
   sandbox.py1501590%100–107, 118, 226, 242, 257–259, 275
   typed_client_generation.py80594%55–57, 70, 75
   version_prompt.py73889%27–28, 40, 59–62, 80, 109
TOTAL148512492% 

Tests Skipped Failures Errors Time
232 0 💤 0 ❌ 0 🔥 18.022s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/algokit
   __init__.py15753%6–13, 17–24, 32–34
   __main__.py220%1–3
src/algokit/cli
   completions.py105298%80, 95
   deploy.py55493%34–36, 78
   doctor.py48394%142–144
   generate.py30197%49
   goal.py30197%42
   init.py1901692%264–265, 315, 318–320, 331, 375, 401, 441, 450–452, 455–460, 473
   localnet.py91397%157, 178–179
src/algokit/core
   bootstrap.py1612485%103–104, 126, 149, 214, 217, 223–237, 246–251
   conf.py54885%10, 24, 28, 36, 38, 71–73
   deploy.py591083%60–63, 72–73, 77, 82, 89–91
   doctor.py65789%67–69, 92–94, 134
   log_handlers.py68790%50–51, 63, 112–116, 125
   proc.py45198%98
   sandbox.py1501590%100–107, 118, 226, 242, 257–259, 275
   typed_client_generation.py80594%55–57, 70, 75
   version_prompt.py73889%27–28, 40, 59–62, 80, 109
TOTAL148512492% 

Tests Skipped Failures Errors Time
232 0 💤 0 ❌ 0 🔥 14.699s ⏱️

Please sign in to comment.