-
Notifications
You must be signed in to change notification settings - Fork 1
docs: add Quick start and Local development workflow guides #39
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
base: master
Are you sure you want to change the base?
Changes from all commits
7b0335c
604c49e
b95ecfa
faad0bb
110935b
2cb810d
a8185aa
fe282f1
8b1829e
6cfff9c
c7e0f0c
019b218
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| # Quick start | ||
|
|
||
| Learn how to build, run, and inspect [Actors](https://docs.apify.com/actors) on your own machine with the local Actor runtime. | ||
|
|
||
| The local Actor runtime is a single Docker container that emulates the parts of the Apify platform the Actor development loop needs. You use the same Apify CLI commands as against the platform, but builds and runs happen on your computer and no platform compute is used. | ||
|
|
||
| ## Before you start | ||
|
|
||
| - [Install Docker](https://docs.docker.com/get-docker/). Use Docker Desktop on macOS or Windows, or Docker Engine on Linux. Docker must be running. | ||
| - [Install Apify CLI](https://docs.apify.com/cli/docs/installation). | ||
| - Log in with `apify login`. You do not need a real Apify account: the runtime accepts any non-empty token and maps it to a local user. With a real token, the runtime adopts your username, id, and proxy password the first time it sees it. | ||
|
|
||
| ## 1. Start the runtime | ||
|
|
||
| Choose one of the following methods. | ||
|
|
||
| ### Start with Apify CLI | ||
|
|
||
| In your Actor directory, run: | ||
|
|
||
| ``` | ||
| apify local start | ||
| ``` | ||
|
|
||
| The command checks that Docker works, downloads the runtime image, and starts it. Runtime data is stored in the `data` directory of your Actor, so each Actor has its own local platform state. | ||
|
|
||
| To stop the runtime later, run `apify local stop`. | ||
|
|
||
| ### Start with Docker | ||
|
|
||
| Build the image from this repository and run it: | ||
|
|
||
| ``` | ||
| docker build -t actor-runtime . | ||
| docker run --rm --name actor-runtime \ | ||
| -p 3333:3333 -p 3000:3000 \ | ||
| -v /var/run/docker.sock:/var/run/docker.sock \ | ||
| -v "$(pwd)/data:/data" \ | ||
| actor-runtime | ||
| ``` | ||
|
|
||
| ### Check that it is running | ||
|
|
||
| To verify that the runtime is up, run: | ||
|
|
||
| ``` | ||
| apify local status | ||
| ``` | ||
|
|
||
| The command reports the runtime API URL, `http://localhost:3333`, and the data directory, and exits non-zero when the runtime is down. | ||
|
|
||
| **Proposed command** | ||
|
|
||
| `apify local status` does not exist yet. Until it ships, run this instead: | ||
|
|
||
| ``` | ||
| APIFY_CLIENT_BASE_URL=http://localhost:3333 apify api v2/users/me | ||
| ``` | ||
|
|
||
| It prints your user as JSON when the runtime is up, and a connection error when it is not. | ||
|
|
||
| ## 2. Connect Apify CLI | ||
|
|
||
| To send every Apify CLI command to the local runtime instead of the Apify platform, run: | ||
|
|
||
| ``` | ||
| apify local connect | ||
| ``` | ||
|
|
||
| Your login is not affected. To switch back to the Apify platform, run: | ||
|
|
||
| ``` | ||
| apify local disconnect | ||
| ``` | ||
|
|
||
| **Proposed commands** | ||
|
|
||
| `apify local connect` and `apify local disconnect` do not exist yet. Until they ship, Apify CLI reads the target URLs from two environment variables. Set them in the terminal you develop in: | ||
|
|
||
| ``` | ||
| export APIFY_CLIENT_BASE_URL=http://localhost:3333 | ||
| export APIFY_CONSOLE_URL=http://localhost:3000 | ||
| ``` | ||
|
|
||
| Unset both variables to switch back to the Apify platform. | ||
|
|
||
| ## 3. Push and run your Actor | ||
|
|
||
| 1. Navigate to your Actor directory: | ||
|
|
||
| ``` | ||
| cd your-actor-name | ||
| ``` | ||
|
|
||
| 2. Push the Actor to the runtime: | ||
|
|
||
| ``` | ||
| apify push | ||
| ``` | ||
|
|
||
| The CLI uploads the source code, creates the Actor in the runtime, and shows the build log. The first build downloads the base image and installs dependencies, so it takes about a minute. Later builds reuse Docker's layer cache and take seconds. | ||
|
|
||
| 3. Run the Actor: | ||
|
|
||
| ``` | ||
| apify call | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That statistic can be misleading, and if we can easily replace |
||
| ``` | ||
|
|
||
| The run uses the input from your local `storage/key_value_stores/default/INPUT.json`. To pass a different input, add `--input '{"key": "value"}'` or `--input-file input.json`. The CLI streams the run log and prints the run's default storage ids when it finishes. Add `--json` to get them as JSON. | ||
|
|
||
| **No Actor yet?** | ||
|
|
||
| Create one with [`apify create`](https://docs.apify.com/cli/docs/quick-start), or use `sample_actor_ts` in this repository, which takes `--input '{"maxPages": 3}'`. | ||
|
|
||
| ## 4. View the results | ||
|
|
||
| To list the runs of your Actor, run: | ||
|
|
||
| ``` | ||
| apify runs ls | ||
| ``` | ||
|
|
||
| To read what a run produced, use the ids `apify call` printed: | ||
|
|
||
| | Command | Shows | | ||
| | -------------------------------------------------------- | -------------------------------------- | | ||
| | `apify datasets info <datasetId>` | Dataset metadata, including item count | | ||
| | `apify api v2/datasets/<datasetId>/items` | Dataset items | | ||
| | `apify api v2/key-value-stores/<storeId>/records/OUTPUT` | One key-value store record | | ||
| | `apify api v2/actor-runs/<runId>/log` | The run log | | ||
|
|
||
| `apify api` sends any request to the runtime API, so every Actor, build, run, log, and storage is available this way. The raw files are in the `data` directory. Read them freely, but change state through the API. | ||
|
|
||
| ## 5. Edit your Actor's code | ||
|
|
||
| Edit the code of your Actor and see the results without rebuilding it. | ||
|
|
||
| 1. Change the source in your Actor directory, for example `src/main.ts`. | ||
|
|
||
| 2. Compile the code, if your language needs it: | ||
|
|
||
| ``` | ||
| npm run build | ||
| ``` | ||
|
|
||
| 3. Run the Actor again: | ||
|
|
||
| ``` | ||
| apify call | ||
| ``` | ||
|
|
||
| The run starts from your edited source. There is no `apify push` and no build in between, so the loop takes seconds instead of the minute a build costs. | ||
|
|
||
| Edits apply to the next run you start, not to a run already in progress. Changes to dependencies, such as `package.json` or `requirements.txt`, still need `apify push`, because dependencies are installed during the build. | ||
|
|
||
| ## 6. Stop and reset the runtime | ||
|
|
||
| - To stop, run `apify local stop` or `docker stop actor-runtime`. | ||
| - To keep your data, start the runtime again with the same `data` directory. | ||
| - To reset, stop the runtime and delete the `data` directory. Built Actor images stay in Docker and are reused when you push the same source again. | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is, in essence, very global. It makes sense for parallel agents, for example, to run separate instances of the local runtime. We should describe how to do that.
I imagine setting
APIFY_CLIENT_BASE_URLandAPIFY_CONSOLE_URLin a per-worktree.envfile or viamisewould work just fine...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea that it would work out of the box in Actor project. Anyway, your point is good. Maybe it can be both the
.env, and also maybe some parameters likeapify local connect --client-base-url=<...> ...