# runlinux

> JDK 21과 Android SDK가 있는 클라우드 Linux 빌더에서 Gradle 작업 같은 셸 스크립트를 실행하고, 지정한 파일을 가져옵니다.

Source: https://air.build/ko/docs/cli/runlinux/

`runlinux`는 팀의 환경에서 Linux 빌더로 Bash 스크립트 하나를 실행합니다. `airbuild.yaml`이 필요 없습니다. [runmacos](https://air.build/ko/docs/cli/runmacos/)의 Linux판으로, 옵션은 같고 슬롯은 따로 있습니다.

빌더에는 JDK 21, Android SDK, 미리 채워진 `~/.gradle`이 있어서 `./gradlew lint`나 `./gradlew dependencies` 같은 Gradle 작업과, 샌드박스에 없는 다른 Linux 도구에 알맞습니다. **Node와 Bun은 없습니다.** 스크립트에서 설치하거나, Node, npm, pnpm이 있는 `runmacos`를 쓰세요. 여기에는 `airbuild-xcode`가 없습니다.

**클라우드 팀 전용**입니다. Mac 팀에서는 `runlinux is only available in cloud Teams; local Teams provide runtest.`와 함께 멈춥니다.

Android 앱을 빌드하거나 테스트하려면 `runbuild --platform android_beta`와 `runtest --platform android_beta`를 쓰세요. `runlinux`는 그 밖의 모든 작업용입니다.

## 개요

```bash
runlinux [<project-id>] [--source <directory>] [--output <relative-path>]... --command '<shell script>' [--environment ID] [--no-cache]
runlinux --follow [--run ID]    # reattach; starts nothing
runlinux --cancel [--run ID]
runlinux --list-environments
runlinux --help
```

## 옵션

| 옵션 | 값 | 기본값 | 하는 일 |
| --- | --- | --- | --- |
| `--command` | 셸 스크립트 | 필수 | 업로드된 루트에서 `-e -o pipefail`로 실행할 Bash 스크립트. |
| `<project-id>` | UUID | 없음 | 이 프로젝트를 업로드하고 그 루트에서 실행합니다. |
| `--source` | 디렉터리 | 없음 | 대신 이 디렉터리를 업로드합니다. 현재 디렉터리 기준입니다. 둘 다 있으면 `--source`가 업로드됩니다. |
| `--output` | 상대 경로 | 없음 | 가져올 파일이나 디렉터리. 더 있으면 반복합니다. |
| `--environment` | `--list-environments`의 ID | 첫 번째 Linux 환경 | 다른 Linux 환경에서 실행합니다. 다른 플랫폼용 환경은 거부됩니다. |
| `--no-cache` | — | 캐시 사용 | 이번 실행에서 `airbuild-cache restore`와 `save`를 끕니다. |
| `--follow` | — | — | 진행 중인 실행에 다시 연결합니다. 끝난 실행이면 그렇다고 알리고 저장된 출력을 다시 보여 줍니다. |
| `--run` | 실행 ID | 실행 중인 실행, 없으면 가장 최근 것 | `--follow`나 `--cancel`과 함께 씁니다. |
| `--cancel` | — | — | 실행에 중지를 요청하고 확인을 최대 30초 기다립니다. |
| `--list-environments` | — | — | 빌더 환경을 나열합니다. |

프로젝트 ID나 `--source`가 없으면 스크립트는 빈 디렉터리에서 실행되고 소스는 업로드되지 않습니다.

## 캐시

미리 채워진 `~/.gradle` 말고는 아무것도 저절로 캐시되지 않습니다. 실행 사이에 파일(`node_modules`, 패키지 저장소, Gradle 빌드 캐시)을 보관하려면 스크립트에서 [airbuild-cache](https://air.build/ko/docs/cli/airbuild-cache/)로 복원하세요.

```bash
airbuild-cache restore --key node --path node_modules
```

스크립트가 복원한 것은 끝날 때마다 매번 다시 저장되며, 결과가 돌아온 뒤 업로드됩니다. Linux와 macOS 빌더는 같은 키 아래에서도 항목을 따로 유지합니다.

## 출력물과 결과

`--output` 경로는 [runmacos](https://air.build/ko/docs/cli/runmacos/)와 같은 규칙을 따릅니다. 구체적인 상대 경로여야 하며 `..`, 와일드카드, 심볼릭 링크, 겹치는 경로는 안 됩니다. 스크립트가 실패해도 존재하는 출력물은 그 종료 코드와 함께 가져옵니다. 실행은 같은 방식으로 끝납니다.

```text
✓ Command finished.
  Build: <build-id>
  Artifact: <path to the collected outputs>
```

## 종료 코드

| 코드 | 의미 |
| --- | --- |
| `0` | 스크립트가 통과했고 모든 출력물이 쓰였습니다. |
| `1` | 실행을 시작할 수 없었거나 잃어버렸습니다. |
| `2` | 잘못된 옵션이거나 `--command`가 빠져서 아무것도 실행되지 않았습니다. |
| `65` | 선언한 출력물이 없거나 내보낼 수 없습니다. |
| `130` | 취소되었거나 Ctrl-C로 연결을 끊었습니다. |
| 기타 | 스크립트 자체의 종료 코드. |

## 오류

| 메시지 | 해야 할 일 |
| --- | --- |
| `--command requires a nonempty shell script and is only available with runmacos and runlinux.` | 스크립트를 넘기세요. |
| `--platform takes a platform (…) and is only available with runbuild and runtest.` | `--platform`을 빼세요. |
| `runlinux does not accept build or signing options.` | `--sign` / `--unsigned`를 빼세요. |
| `Declared output was not produced: <path>` | 스크립트가 그 파일을 쓰게 하거나 `--output`을 빼세요. |
| `N runlinux executions are running; choose one with --run.` | 나열된 실행 ID 중 하나를 넘기세요. |
| `This Team's Environment is already running N runlinux executions, the limit.` | 하나가 끝나기를 기다리거나 하나를 follow하세요. |

`node`나 `bun`을 설치하지 않고 호출하는 스크립트는 `command not found`(종료 코드 127)로 실패합니다.

## 예시

```bash
# List the app's dependencies and bring the list back
runlinux 3f6c1a2e-8b4d-4f0a-9c1e-2d7b5a6e9f10 \
  --command './gradlew dependencies > dependencies.txt' --output dependencies.txt
```

```bash
# Keep a downloaded tools directory between runs
runlinux 3f6c1a2e-8b4d-4f0a-9c1e-2d7b5a6e9f10 --command '
  airbuild-cache restore --key tools --path .tools
  ./scripts/fetch-tools.sh .tools'
```

```bash
# What the builder has
runlinux --command 'java -version; ls "$ANDROID_HOME"'
```
