Skip to content

Commit

Permalink
Merge pull request #2 from pawanpaudel93/feat/deploy-config
Browse files Browse the repository at this point in the history
feat: deploy config
  • Loading branch information
pawanpaudel93 authored May 5, 2024
2 parents 2e8f925 + ef56fa6 commit 457bf72
Show file tree
Hide file tree
Showing 16 changed files with 1,599 additions and 1,054 deletions.
49 changes: 36 additions & 13 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,53 @@
{
// Enable the ESlint flat config support
"eslint.experimental.useFlatConfig": true,

// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,

// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "never"
},

// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
{ "rule": "*-order", "severity": "off" },
{ "rule": "*-dangle", "severity": "off" },
{ "rule": "*-newline", "severity": "off" },
{ "rule": "*quotes", "severity": "off" },
{ "rule": "*semi", "severity": "off" }
{
"rule": "style/*",
"severity": "off"
},
{
"rule": "*-indent",
"severity": "off"
},
{
"rule": "*-spacing",
"severity": "off"
},
{
"rule": "*-spaces",
"severity": "off"
},
{
"rule": "*-order",
"severity": "off"
},
{
"rule": "*-dangle",
"severity": "off"
},
{
"rule": "*-newline",
"severity": "off"
},
{
"rule": "*quotes",
"severity": "off"
},
{
"rule": "*semi",
"severity": "off"
}
],

// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
Expand Down
146 changes: 123 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![JSDocs][jsdocs-src]][jsdocs-href]
[![License][license-src]][license-href]

A package to deploy AO contracts.
A package for deploying AO contracts.

## Installation

Expand Down Expand Up @@ -39,52 +39,97 @@ bun add ao-deploy --dev
### CLI

```sh
Usage: ao-deploy [options] <contractPath>
Usage: ao-deploy [options] <contractOrConfigPath>

A CLI tool to deploy AO contracts
Deploy AO contracts using a CLI.

Arguments:
contractPath Contract main file path to deploy
contractOrConfigPath Path to the main contract file or deployment configuration.

Options:
-V, --version output the version number
-n, --name [name] Name of the process to spawn (default: "default")
-w, --wallet [wallet] Wallet JWK file path
-s, --scheduler [scheduler] Scheduler to use for Process (default: "_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA")
-m, --module [module] The module source to use to spin up Process
-c, --cron [interval] Cron interval to use for Process i.e (1-minute, 5-minutes)
-t, --tags [tags...] Additional tags to use when spawning Process
--retry-count [count] Retry count to spawn Process (default: "10")
--retry-delay [delay] Retry delay in milliseconds (default: "3000")
-h, --help display help for command
-V, --version output the version number
-n, --name [name] Specify the process name. (default: "default")
-w, --wallet [wallet] Path to the wallet JWK file.
-l, --lua-path [luaPath] Specify the Lua modules path seperated by semicolon.
-d, --deploy [deploy] List of deployment configuration names, separated by commas.
-s, --scheduler [scheduler] Scheduler to be used for the process. (default: "_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA")
-m, --module [module] Module source for spawning the process.
-c, --cron [interval] Cron interval for the process (e.g. 1-minute, 5-minutes).
-t, --tags [tags...] Additional tags for spawning the process.
-p, --process-id [processId] Specify process Id of existing process.
--concurrency [limit] Concurrency limit for deploying multiple processes. (default: "5")
--retry-count [count] Number of retries for deploying contract. (default: "10")
--retry-delay [delay] Delay between retries in milliseconds. (default: "3000")
-h, --help display help for command
```

#### CLI Example
#### CLI Examples

```sh
ao-deploy process.lua -n tictactoe -w wallet.json --tags name1:value1 name2:value2
```

OR,
##### Deployment with configuration

Here is an example using a deployment configuration:

```ts
// aod.config.ts
import { defineConfig } from 'ao-deploy'

const wallet = 'wallet.json'
const luaPath = './?.lua;./src/?.lua'

const config = defineConfig({
contract_1: {
luaPath,
name: `contract-1`,
contractPath: 'contract-1.lua',
wallet,
},
contract_2: {
luaPath,
name: `contract-2`,
contractPath: 'contract-2.lua',
wallet,
},
contract_3: {
luaPath,
name: `contract-3`,
contractPath: 'contract-3.lua',
wallet,
}
})

export default config
```

Deploy all specified contracts:

```sh
aod process.lua -n tictactoe -w wallet.json --tags name1:value1 name2:value2
ao-deploy aod.config.ts
```

Deploy specific contracts:

```sh
ao-deploy aod.config.ts --deploy=contract_1,contract_3
```

> [!Note]
A wallet is generated and saved if not passed.

Run this command to get the generated wallet path:
Retrieve the generated wallet path:

```sh
node -e "const path = require('path'); const os = require('os'); console.log(path.resolve(os.homedir(), '.aos.json'));"
```

### Code
### API Usage

To deploy a contract, you need to import and call the `deployContract` function from your script. Here is a basic example:

#### Example
#### Example: deployContract

```ts
import { deployContract } from 'ao-deploy'
Expand All @@ -108,15 +153,14 @@ async function main() {
console.log(`\nDeployed Process: ${processUrl} \nDeployment Message: ${messageUrl}`)
}
catch (error: any) {
console.log('\nDeployment failed!\n')
console.log(error?.message ?? 'Failed to deploy contract!')
console.log(`Deployment failed!: ${error?.message ?? 'Failed to deploy contract!'}\n`)
}
}

main()
```

#### Parameters
##### Parameters

The `deployContract` function accepts the following parameters within the DeployArgs object:

Expand All @@ -128,6 +172,62 @@ The `deployContract` function accepts the following parameters within the Deploy
- `cron` (optional): The cron interval for the process, e.g., "1-minute", "5-minutes". Use format `interval-(second, seconds, minute, minutes, hour, hours, day, days, month, months, year, years, block, blocks, Second, Seconds, Minute, Minutes, Hour, Hours, Day, Days, Month, Months, Year, Years, Block, Blocks)`
- `wallet` (optional): The wallet path or JWK itself (Autogenerated if not passed).
- `retry` (optional): Retry options with `count` and `delay` properties. By default, it will retry up to `10` times with a `3000` milliseconds delay between attempts.
- `luaPath` (optional): The path to the Lua modules seperated by semicolon.
- `processId` (optional): The process id of existing process.

#### Example: deployContracts

To deploy contracts, you need to import and call the `deployContracts` function from your script. Here is a basic example:

```ts
import { deployContracts } from 'ao-deploy'

async function main() {
try {
const results = await deployContracts(
[
{
name: 'demo1',
wallet: 'wallet.json',
contractPath: 'process1.lua',
tags: [{ name: 'Custom', value: 'Tag' }],
retry: {
count: 10,
delay: 3000,
},
},
{
name: 'demo2',
wallet: 'wallet.json',
contractPath: 'process2.lua',
tags: [{ name: 'Custom', value: 'Tag' }],
retry: {
count: 10,
delay: 3000,
},
}
],
2
)
results.forEach((result, idx) => {
if (result.status === 'fulfilled') {
const { processId, messageId } = result.value
const processUrl = `https://ao_marton.g8way.io/#/process/${processId}`
const messageUrl = `${processUrl}/${messageId}`
console.log(`\nDeployed Process: ${processUrl} \nDeployment Message: ${messageUrl}`)
}
else {
console.log(`Failed to deploy contract!: ${result.reason}\n`)
}
})
}
catch (error: any) {
console.log(`Deployment failed!: ${error?.message ?? 'Failed to deploy contract!'}\n`)
}
}

main()
```

## Author

Expand Down
2 changes: 2 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default defineBuildConfig([{
clean: true,
rollup: {
emitCJS: true,
inlineDependencies: true,
},
failOnWarn: false,
}, {
Expand All @@ -18,6 +19,7 @@ export default defineBuildConfig([{
clean: true,
rollup: {
emitCJS: false,
inlineDependencies: true,
},
failOnWarn: false,
}])
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export default antfu(
rules: {
// overrides
'no-console': 'off',
'brace-style': ['error', 'stroustrup', { allowSingleLine: true }],
'indent': ['error', 2],
'curly': ['error', 'all'],
},
},
)
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"version": "0.1.4",
"packageManager": "[email protected]",
"description": "A package to deploy contract to AO",
"description": "A package for deploying AO contracts",
"author": "Pawan Paudel <[email protected]>",
"license": "MIT",
"funding": "https://github.com/sponsors/pawanpaudel93",
Expand Down Expand Up @@ -52,30 +52,30 @@
"prepare": "simple-git-hooks"
},
"dependencies": {
"@permaweb/aoconnect": "^0.0.51",
"@permaweb/aoconnect": "^0.0.53",
"ardb": "^1.1.10",
"arweave": "^1.15.0",
"arweave": "^1.15.1",
"chalk": "^5.3.0",
"commander": "^12.0.0",
"ora": "^8.0.1",
"jiti": "^1.21.0",
"pretty-file-tree": "^1.0.1"
},
"devDependencies": {
"@antfu/eslint-config": "^2.14.0",
"@antfu/eslint-config": "^2.16.1",
"@antfu/ni": "^0.21.12",
"@antfu/utils": "^0.7.7",
"@types/node": "^20.12.7",
"bumpp": "^9.4.0",
"@types/node": "^20.12.8",
"bumpp": "^9.4.1",
"eslint": "^8.57.0",
"esno": "^4.7.0",
"lint-staged": "^15.2.2",
"pnpm": "^8.15.7",
"pnpm": "^8.15.8",
"rimraf": "^5.0.5",
"simple-git-hooks": "^2.11.1",
"typescript": "^5.4.5",
"unbuild": "^2.0.0",
"vite": "^5.2.9",
"vitest": "^1.5.0"
"vite": "^5.2.11",
"vitest": "^1.6.0"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
Expand Down
Loading

0 comments on commit 457bf72

Please sign in to comment.