# Iterate then deploy
URL: https://docs.datarobot.com/en/docs/api/dev-learning/workload-api/tutorials/tutorial-iterate.html

> Development-to-production workflow where you iterate on a workload with a draft artifact, then register it and create a governed deployment.

# Iterate then deploy

This tutorial demonstrates the development-to-production workflow where you iterate on a workload with a draft artifact, then register it and create a governed deployment.

## Workflow overview

| Phase | Action | Result |
| --- | --- | --- |
| Development | POST /console/workloads/ | Creates workload and draft artifacts. |
| Iteration | PATCH /registry/artifacts/{artifactId} | Updates the container spec, restarts, tests. |
| Lock | PATCH /registry/artifacts/{artifactId} | Sets status: registered to make immutable. |
| Production | POST /console/deployments/ | Creates a governed deployment. |

## Step 1: Create a development workload

Create a workload with an inline artifact. The artifact is created with `status=draft` by default, allowing iteration.

## Step 2: Iterate on the artifact

During development, update the artifact and restart the workload to test changes.

### 2a. Update artifact (partial update with PATCH)

Use `PATCH` to update specific metadata fields (for example, name or description) while keeping others unchanged.

### 2b. Replace entire artifact (full update with PUT)

Use `PUT` to replace the full artifact definition, including the container spec. For changes to the container specification (image, entrypoint, probes, and so on), `PUT` is required; `PATCH` does not support full artifact updates.

### 2c. Restart workload to apply changes

```
# Stop the workload
curl -X POST "${DATAROBOT_ENDPOINT}/console/workloads/${WORKLOAD_ID}/stop" \
  -H "Authorization: Bearer ${DATAROBOT_API_TOKEN}"

# Wait a few seconds, then start
curl -X POST "${DATAROBOT_ENDPOINT}/console/workloads/${WORKLOAD_ID}/start" \
  -H "Authorization: Bearer ${DATAROBOT_API_TOKEN}"
```

## Step 3: Lock artifact for production

When ready for production, change the artifact status from draft to registered:

```
curl -X PATCH "${DATAROBOT_ENDPOINT}/registry/artifacts/${ARTIFACT_ID}" \
  -H "Authorization: Bearer ${DATAROBOT_API_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{"status": "registered"}'
```

> [!NOTE] Immutability
> Once registered, the artifact's container specification is locked and cannot be modified.

## Step 4: Create production deployment

Create a governed deployment using the `WORKLOAD_ID` from Step 1.

## Key concepts

| Concept | Description |
| --- | --- |
| Draft artifact | Mutable; can be updated during development. |
| Registered artifact | Immutable, locked for production use. |
| Workload | Runtime instance of containers for development or testing. |
| Deployment | Production-grade workload with governance and audit trails. |

---
