Metadata-Version: 2.5
Name: osc-outscale
Version: 0.1.0
Summary: Local-first CLI to generate and optionally apply Outscale setups (Terraform VMs + OKS)
Project-URL: Homepage, https://github.com/simondelamarre/osc
Project-URL: Repository, https://github.com/simondelamarre/osc
Project-URL: Issues, https://github.com/simondelamarre/osc/issues
Author-email: Simon <simondrow@users.noreply.github.com>
License-Expression: MIT
Keywords: cli,infrastructure,oks,outscale,terraform
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: System :: Systems Administration
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: jinja2>=3.1
Requires-Dist: pyyaml>=6.0
Requires-Dist: rich>=13.0
Requires-Dist: typer>=0.12
Provides-Extra: dev
Requires-Dist: build>=1.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: twine>=5.0; extra == 'dev'
Description-Content-Type: text/markdown

# osc

Local-first CLI to **generate** Outscale setups in the current repository, then optionally **apply** them with credentials.

```text
cd mon-projet/
osc init -n mon-app
osc add stack single-vm --name app --git-repo git@github.com:org/monorepo.git
# or: osc add stack multi-vm …
# or: osc add stack oks …
osc validate
# later:
osc apply --target terraform   # or oks
osc deploy                     # git clone/pull + build/start
osc redeploy                   # pull + rebuild + restart
```

This is **not** a rewrite of `oks-cli`. It writes configs under `./outscale/` from a declarative `project.yaml`. Patterns are simplified from [formation-outscale](../formation-outscale) (Terraform VMs) and [formation-oks](../formation-oks) (managed OKS).

## Install

### Prerequisites

- Python **3.11+**
- For apply Terraform: [`terraform`](https://developer.hashicorp.com/terraform/install) >= 1.5
- For apply OKS: [`oks-cli`](https://docs.eu-west-2.oks.outscale.com/) (see formation-oks `make install`)

### Option A — pipx (recommended on a machine)

```bash
# from a clone
git clone https://github.com/<org>/osc.git
cd osc
pipx install .

osc version
```

Upgrade later:

```bash
cd osc && git pull && pipx install . --force
```

### Option B — editable install (dev)

```bash
git clone https://github.com/<org>/osc.git
cd osc
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

osc version
pytest
```

### Option C — from a GitHub release / tag (once published)

```bash
pipx install git+https://github.com/<org>/osc.git@v0.1.0
```

Or with pip:

```bash
pip install "osc @ git+https://github.com/<org>/osc.git@v0.1.0"
```

### Use in another repo

Install `osc` once on the machine (pipx), then run it **from the consumer project**:

```bash
cd ~/Documents/Github/mon-app
osc init -n mon-app
```

The CLI always writes under `./outscale/` relative to the current working directory.

## Publish

V1 is not on PyPI yet. Suggested release flow:

1. Bump `version` in [`pyproject.toml`](pyproject.toml)
2. Tag and push:

```bash
git tag v0.1.0
git push origin main --tags
```

3. Build and (optionally) upload to PyPI:

```bash
pip install build twine
python -m build
# twine upload dist/*
```

4. Users install with:

```bash
pipx install osc
# or until PyPI:
pipx install git+https://github.com/<org>/osc.git@v0.1.0
```

Homebrew tap is out of scope for V1.

## Layout written into your project

```text
mon-projet/
└── outscale/
    ├── project.yaml       # source of truth
    ├── terraform/         # generated HCL (modules + root)
    ├── oks/               # cluster/nodepool YAML + apply.sh
    ├── kubeconfigs/       # filled on OKS apply
    └── .state/            # local only
```

## Commands

| Command | Cloud? | Description |
|---------|--------|-------------|
| `osc init` | No | Create `outscale/project.yaml` |
| `osc add net` | No | Add VPC/Net component |
| `osc add vm --name … [--install mongodb\|nodejs\|nginx\|docker]` | No | Add VM (+ auto `net` if missing) |
| `osc add oks --name …` | No | Add managed OKS cluster + nodepool |
| `osc add stack single-vm\|multi-vm\|oks` | No | Full stack: api+web+worker+mongo+redis+weaviate |
| `osc generate` | No | Regenerate terraform/ and oks/ |
| `osc validate` | No | Schema + layout checks |
| `osc status` | Optional | Local summary (+ oks-cli list if available) |
| `osc plan --target terraform` | Yes | `terraform plan` |
| `osc apply --target terraform\|oks\|all` | Yes | Deploy infra |
| `osc deploy` / `osc redeploy` | On VM/cluster | Git pull + build/restart app layer |

## Credentials (apply only)

### Terraform

Edit `outscale/terraform/terraform.tfvars` (copied from the example on first generate):

```hcl
outscale_access_key_id = "..."
outscale_secret_key_id = "..."
image_id               = "ami-..."   # Ubuntu OMI for your region
```

Requires `terraform` on `PATH` and the [outscale/outscale](https://registry.terraform.io/providers/outscale/outscale/latest/docs) provider.

### OKS

```bash
export OKS_PROFILE=your-profile
# optional:
export OKS_ADMIN_CIDR=x.x.x.x/32
osc apply --target oks
```

Requires `oks-cli` (see formation-oks `make install`).

## Full stack topologies (api + web + worker + mongo + redis + weaviate)

Yes, **all on one VM is possible** (Docker Compose). Prefer **multi-vm** for anything beyond a lab, and **OKS** for managed Kubernetes.

```bash
osc add stack single-vm --name app --git-repo git@github.com:org/monorepo.git
osc add stack multi-vm  --name app --git-repo git@github.com:org/monorepo.git
osc add stack oks       --name app --git-repo git@github.com:org/monorepo.git
```

| Topology | Infra | App services | DB exposure |
|----------|-------|--------------|-------------|
| `single-vm` | 1 public VM | Compose on the same host | Bound on localhost/docker network (still one blast radius) |
| `multi-vm` | app public + mongo/redis/weaviate **private** | Compose app on app VM | SGs: DB ports only from VPC CIDR |
| `oks` | OKS cluster + nodepool | k8s Deployments/Services | Cluster-internal Services |

See generated fixtures under [`examples/`](examples/).

### How git deploy works

1. `project.yaml` stores `stack.git.repo` / `ref` and monorepo paths (`apps/api`, `apps/web`, `apps/worker` — each needs a `Dockerfile`).
2. `osc generate` writes `outscale/app/<stack>/deploy.sh` (+ compose or k8s manifests).
3. After infra (`osc apply`), on the target:
   - `osc deploy` → `git clone/pull` into `/opt/osc/<stack>` (or `OSC_APP_DIR`) then `docker compose up` / `kubectl apply`
   - `osc redeploy` → same script path (pull + rebuild + restart)

No registry flow is fully automated yet for OKS: set image names in `outscale/oks/apps/*.yaml` (placeholders `ghcr.io/example/...`) or build/push in CI then redeploy.

### Images / versions

Data-plane images default to:

- `mongo:7`
- `redis:7-alpine`
- `semitechnologies/weaviate:1.27.0`

Override under `components[].images` in `project.yaml`, then `osc generate`. App images come from your monorepo Dockerfiles (single/multi-vm) or a container registry (OKS).

## Example `project.yaml`

```yaml
name: my-app
region: eu-west-2
environment: dev
vpc_cidr: 10.0.0.0/16
availability_zone: eu-west-2a
image_id: ""
components:
  - type: net
  - type: vm
    name: api
    size: tinav6.c4r6p2
    packages: [nodejs]
    subnet: public
    volume_size: 20
    public_ip: true
  - type: vm
    name: mongo
    size: tinav6.c4r6p2
    packages: [mongodb]
    subnet: private
    volume_size: 40
    public_ip: false
  - type: oks
    name: main
    version: "1.30"
    oks_project: my-app
    control_plane: cp.mono.master
    nodepools:
      - name: default
        type: tinav6.c4r6p2
        count: 3
```

## Design rules

1. **Always write into the cwd** — run `osc` from the consumer repo.
2. **Generate without credentials** — `init` / `add` / `generate` / `validate` are offline.
3. **Apply is explicit** — never deploy unless you run `osc apply`.
4. **Idempotent generate** — `project.yaml` is the source of truth; derived files are regenerated.

## V1 scope

Included: `net`, generic `vm` (+ cloud-init for nodejs/mongodb/nginx/docker), OKS cluster + one nodepool, validate/plan/apply.

Not included yet: Packer OMI baking, load balancer stack, Redis/Weaviate presets, Homebrew tap, interactive menus.

## Development

```bash
pip install -e ".[dev]"
pytest
```
