Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use click for CLI #457

Merged
merged 26 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
95faa0f
refactor: use click for CLI
raaymax Jun 6, 2024
2215df8
chore: changes according to code review
raaymax Jun 11, 2024
644f27a
docs: added docs for cloud deploy
raaymax Jun 11, 2024
24bf9f4
docs: added verbose flag to docs
raaymax Jun 11, 2024
bdc205a
fix: linter error
raaymax Jun 11, 2024
167c030
Merge branch 'dev' into using_click_for_cli
raaymax Jun 20, 2024
bebc497
feat: added version option for CLI
raaymax Jun 28, 2024
729564a
feat: added version and help commands short options
raaymax Jun 28, 2024
f0cb5ef
fix: typo in command line help message
raaymax Jul 8, 2024
e4625b5
Merge branch 'dev' into using_click_for_cli
raaymax Jul 16, 2024
6aa358d
Merge branch 'dev' into using_click_for_cli
raaymax Jul 16, 2024
2a76d56
test: add tests for deploy and cli commands
raaymax Jul 16, 2024
b5ef822
fix: python 3.9
raaymax Jul 17, 2024
dc6fc0c
fix: missing templates in tests
raaymax Jul 17, 2024
f2fa9fa
fix: according to CR
raaymax Jul 18, 2024
a1b3262
chore: added missing change
raaymax Jul 18, 2024
2645fd6
fix: linter errors
raaymax Jul 18, 2024
a168622
docs: removed mention about service_entrypoint.py
raaymax Jul 22, 2024
76f68e5
test: cli edit and run commands
raaymax Jul 22, 2024
e26d416
fix: linter
raaymax Jul 22, 2024
f35229c
ci: build first
raaymax Jul 22, 2024
b6401cb
fix: windows paths problem
raaymax Jul 22, 2024
40f3ac0
fix: windows problem
raaymax Jul 23, 2024
1c95d0b
fix: windows issue attempt 2
raaymax Jul 23, 2024
96d5a21
fix: windows issue attempt 3
raaymax Jul 23, 2024
6fff61a
fix: linter
raaymax Jul 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions alfred/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
def ci(front, back, e2e, docs):
no_flags = (not front and not back and not e2e and not docs)

if front or no_flags:
alfred.invoke_command("npm.lint")
alfred.invoke_command("npm.build")
if back or no_flags:
alfred.invoke_command("ci.mypy")
alfred.invoke_command("ci.ruff")
alfred.invoke_command("ci.pytest")
if front or no_flags:
alfred.invoke_command("npm.lint")
alfred.invoke_command("npm.build")
if docs or no_flags:
alfred.invoke_command("npm.docs.test")
if e2e:
Expand Down
167 changes: 167 additions & 0 deletions docs/framework/cloud-deploy.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
---
title: "Cloud Deployment Using CLI"
---

## Table of Contents

2. [Basic Usage](#basic-usage)
3. [Common Options](#common-options)
4. [Commands](#commands)
- [Deploy](#writer-cloud-deploy)
- [Undeploy](#writer-cloud-undeploy)
- [Logs](#writer-cloud-logs)
5. [Environment Variables](#environment-variables)
6. [API Key](#api-key)
7. [Deployment Process](#deployment-process)
8. [Example Workflow](#example-workflow)

## Basic Usage

The `writer cloud` command group includes the following commands:
- `deploy`
- `undeploy`
- `logs`

## Common Options

These options are common across multiple commands:
- `--api-key`: The Writer API key used for authentication. If not provided, you will be prompted to enter it.
- `--verbose, -v`: Enable verbose output.

## Commands

### `writer cloud deploy`

Deploys an app from the specified path to the Writer cloud.

**Usage:**
```
writer cloud deploy [OPTIONS] PATH
```

**Arguments:**
- `PATH`: The path to the folder containing the app to deploy.

**Options:**
- `--api-key`: Writer API key for authentication. If not provided, you will be prompted to enter it.
- `--env, -e`: Environment variables to set in the deployed app. Use the format `VAR=value`. Multiple environment variables can be specified by repeating the `--env` option.
- `--verbose, -v`: Enable verbose output.

**Example:**
```
writer cloud deploy hello --env VAR1=value1 --env VAR2=value2
```

**Description:**
- Deploys the app located in the `PATH` folder.
- Creates a deployment package, ignoring `.git` directories, `Dockerfile`s and all files specified in `.gitignore` file.
- Uploads the package to the deployment server.
- The deployed app will have access to specified environment variables.
- By default, the `WRITER_API_KEY` environment variable will be added to enable AI features.

**Output Example**

```
Creating deployment package from path: /path/to/your/app
[WARNING] Dockerfile found in project root. This will be ignored in the deployment package.
Packing file: pyproject.toml
Packing file: README.md
...
Uploading package to deployment server
Package uploaded. Building...
...
Deployment successful
URL: https://your_app_url
```

### `writer cloud undeploy`

Stops the deployed app and makes it unavailable.

**Usage:**
```
writer cloud undeploy [OPTIONS]
```

**Options:**
- `--api-key`: Writer API key for authentication. If not provided, you will be prompted to enter it.
- `--verbose, -v`: Enable verbose output.

**Example:**
```
writer cloud undeploy
```

**Description:**
- Stops and removes the deployed app from the Writer cloud.

### `writer cloud logs`

Fetches logs from the deployed app.

**Usage:**
```
writer cloud logs [OPTIONS]
```

**Options:**
- `--api-key`: Writer API key for authentication. If not provided, you will be prompted to enter it.
- `--verbose, -v`: Enable verbose output.

**Example:**
```
writer cloud logs
```

**Description:**
- Continuously fetches and displays logs from the deployed app.
- Logs are ordered by date and time.

**Output Example**

```
2024-06-11 09:27:02.190646+00:00 [INFO] Starting container entrypoint...
2024-06-11 09:27:03.798148+00:00 [INFO] BuildService - Downloading build files...
...
```

## Environment Variables

When deploying an app, you can specify environment variables that will be available to the app during runtime. Use the `--env` option to pass these variables.

**Example:**
```
writer cloud deploy hello --env DB_HOST=db.example.com --env DB_PORT=5432
```

In this example, `DB_HOST` and `DB_PORT` will be available to the app as environment variables.

## API Key

The `WRITER_API_KEY` is crucial for deploying and managing apps. It is used for authenticating requests to the Writer cloud. If not provided as an option, the CLI will prompt you to enter it. The `WRITER_API_KEY` will also be added to the deployed app's environment to enable AI features of the Writer framework.

## Deployment Process

1. **Package Creation:** The CLI packages the app, excluding certain files (e.g., Dockerfile, `service_entrypoint.py`).
raaymax marked this conversation as resolved.
Show resolved Hide resolved
2. **Upload Package:** The package is uploaded to the Writer deployment server.
3. **Build and Deploy:** The server builds and deploys the app, making it accessible via a URL.
4. **Environment Variables:** Specified environment variables are set, and `WRITER_API_KEY` is added by default.

## Example Workflow

1. **Deploying an App:**
```
writer cloud deploy /path/to/app --env DB_HOST=db.example.com --env DB_PORT=5432
```

2. **Fetching Logs:**
```
writer cloud logs
```

3. **Undeploying an App:**
```
writer cloud undeploy
```

By following this documentation, you should be able to effectively deploy and manage your Writer apps using the Writer Framework CLI.
1 change: 1 addition & 0 deletions docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
{
"group": "Deployment",
"pages": [
"framework/cloud-deploy",
"framework/deploy-with-docker",
"framework/testing"
]
Expand Down
Loading
Loading