> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ale.run/llms.txt
> Use this file to discover all available pages before exploring further.

# クイックスタート

> エールをローカル環境にインストールし、ローカル K8s クラスターにアプリをデプロイできます。

<Info>
  エールを使用するには、Node.js 20以上が必要です。
</Info>

<video autoPlay muted loop playsInline className="w-full aspect-video" src="https://storage.googleapis.com/files.cloudtype.io/ale-docs/getting-started/images/quickstart(jp).mp4" />

***

## クラスターのセットアップ

<AccordionGroup>
  <Accordion title="Docker Desktop">
    [Docker Desktop](https://www.docker.com/products/docker-desktop/) のウェブサイトにアクセスし、OSとアーキテクチャに合ったインストールファイルをダウンロードしてください。インストール完了後、ターミナルで以下のコマンドを入力してDockerが正常にインストールされたことを確認します。

    ```bash theme={null}
    docker version
    ```

    **Kubernetes クラスターのセットアップ**

    **1.** Docker Desktopの設定画面に移動し、左のメニューから**Kubernetes**を選択します。次に、**Enable Kubernetes**を有効化し、下部の`Apply & restart`をクリックしてください。

    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/getting-started/images/02_01.png" />
    </Frame>

    **2.** kubectlコマンドがDocker Desktopを通じて生成されたKubernetesクラスターに適用されるよう、以下のコマンドを実行してください。

    ```bash theme={null}
    kubectl config use-context docker-desktop
    ```

    ```plain theme={null}
    Switched to context "docker-desktop".
    ```

    **3.** ターミナルで以下のコマンドを実行し、クラスターが正常に動作しているか確認できます。**STATUS**が**Ready**でない場合や、以下の内容が表示されない場合、Kubernetesクラスターが正常に利用できない状態ですので、コンテキストやDocker Desktopの状態を確認する必要があります。

    ```bash theme={null}
    kubectl get node
    ```

    ```plain theme={null}
    NAME             STATUS   ROLES           AGE   VERSION
    docker-desktop   Ready    control-plane   37m   v1.30.2
    ```
  </Accordion>

  <Accordion title="OrbStack">
    [HomeBrew](https://brew.sh/)がインストールされているmacOSで、以下のコマンドを実行してください。

    ```bash theme={null}
    brew install orbstack
    ```

    **Kubernetes クラスターのセットアップ**

    **1.** OrbStackの設定画面に移動し、**Kubernetes**タブを選択します。
    次に、**Enable Kubernetes cluster**および**Expose services to local network devices**にチェックを入れ、下部の`Apply`をクリックしてください。

    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/getting-started/images/02_20.png" />
    </Frame>

    **2.** kubectlコマンドがOrbStackを通じて生成されたKubernetesクラスターに適用されるよう、以下のコマンドを実行してください。

    ```bash theme={null}
    kubectl config use-context orbstack
    ```

    ```plain theme={null}
    Switched to context "orbstack".
    ```

    **3.** ターミナルで以下のコマンドを実行し、クラスターが正常に動作しているか確認できます。**STATUS**が**Ready**でない場合や、以下の内容が表示されない場合、Kubernetesクラスターが正常に利用できない状態ですので、コンテキストやOrbStackの状態を確認する必要があります。

    ```bash theme={null}
    kubectl get node
    ```

    ```plain theme={null}
    NAME       STATUS   ROLES                  AGE     VERSION
    orbstack   Ready    control-plane,master   7m14s   v1.29.3+orb1
    ```
  </Accordion>

  <Accordion title="kind">
    <Info>
      kindを利用するには、v1.16以上のgoがインストールされている必要があります。
      [このページ](https://go.dev/dl/)からOSごとのインストーラをダウンロードし、インストール後、以下のコマンドを入力してシェルにgoのパスを登録してください。

      <CodeGroup>
        ```bash zsh theme={null}
        echo 'export PATH=$PATH:$HOME/go/bin' >> ~/.zshrc && source ~/.zshrc
        ```

        ```bash bash theme={null}
        echo 'export PATH=$PATH:$HOME/go/bin' >> ~/.bashrc && source ~/.bashrc
        ```
      </CodeGroup>
    </Info>

    ターミナルで以下のコマンドを実行してください。

    ```bash theme={null}
    go install sigs.k8s.io/kind@v0.25.0
    ```

    **Kubernetes クラスターのセットアップ**

    **1.** ターミナルで以下のコマンドを入力します。

    ```bash theme={null}
    cat <<EOF | kind create cluster --name kind --config=-
    kind: Cluster
    apiVersion: kind.x-k8s.io/v1alpha4
    nodes:
      - role: control-plane
      - role: worker
      - role: worker
    EOF
    ```

    **2.** kubectlコマンドがkindで作成されたK8sクラスターに適用されるように、以下のコマンドを実行してください。

    ```bash theme={null}
    kubectl config use-context kind
    ```

    ```plain theme={null}
    Switched to context "kind".
    ```

    **3.** ターミナルで以下のコマンドを実行し、クラスターが正常に動作しているか確認できます。**STATUS**が**Ready**でない場合や、以下の内容が表示されない場合、Kubernetesクラスターが正常に利用できない状態ですので、コンテキストや稼働中のコンテナの状態を確認する必要があります。

    ```bash theme={null}
    kubectl get node
    ```

    ```plain theme={null}
    NAME                 STATUS   ROLES           AGE   VERSION
    kind-control-plane   Ready    control-plane   19m   v1.31.2
    kind-worker          Ready    <none>          19m   v1.31.2
    kind-worker2         Ready    <none>          19m   v1.31.2
    ```
  </Accordion>
</AccordionGroup>

## エールのインストールと実行

<Steps>
  <Step title="以下のコマンドを入力してale-runパッケージをインストールします。">
    ```bash theme={null}
    mkdir ale-run
    cd ale-run
    ```

    ```bash theme={null}
    npm i @ale-run/runtime@latest
    ```
  </Step>

  <Step title="以下のコマンドを入力してNginx Ingress Controllerをインストールしてください。">
    ```bash theme={null}
    kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.11.2/deploy/static/provider/cloud/deploy.yaml
    ```

    ```bash theme={null}
    kubectl delete -A ValidatingWebhookConfiguration ingress-nginx-admission
    ```

    ```bash theme={null}
    kubectl patch ingressclass nginx --type='merge' -p '{"metadata": {"annotations": {"ingressclass.kubernetes.io/is-default-class": "true"}}}'
    ```
  </Step>

  <Step title="以下のコマンドを入力してMetrics Serverをインストールしてください。">
    ```bash theme={null}
    kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
    ```
  </Step>

  <Step title="以下のコマンドを入力してエールを開発モードで実行します。">
    ```bash theme={null}
    npx aled dev
    ```
  </Step>

  <Step title="エールを使用してアプリケーションをデプロイするクラスターを選択します。クラスターの一覧は`~/.kube/config`に登録されたコンテキストを通じて表示されます。">
    ```bash theme={null}
    ? Select the k8s cluster to use. › Select the k8s cluster to use.
        No Cluster
        orbstack
    ❯   docker-desktop
    ```

    <Info>
      以下のようにログが表示されたら、実行が完了したことになります。
    </Info>

    ```bash theme={null}
    ...
    [INFO] [plugin:cloudtype-apps] plugin @cloudtype/apps is installed {}
    [INFO] [plugin:cloudtype-apps] plugin @cloudtype/apps is activate {}
    [INFO] [pde:init] plugin "@cloudtype/apps" loaded! 
    [INFO] [k8s] KubernetesClusterType initialized with agent {"connection":{"context":"docker-desktop","namespace":"ale-pde"},"stat":{"db":{"url":"mongodb://127.0.0.1:64000/","dbName":"ale-pde"}}}
    [INFO] [k8s] ConfigContext initialized with {"connection":{"context":"docker-desktop","namespace":"ale-pde"},"stat":{"db":{"url":"mongodb://127.0.0.1:64000/","dbName":"ale-pde"}}}
    [INFO] [k8s] connect k8s to "docker-desktop" 
    [INFO] [k8s] [agent] cluster agent initialized 
    [WARN] [k8s] ConfigMap.get ale-pde agent-config 
    [INFO] [pde:agent] Ale Agent is initialized with config  
    [INFO] [pde:init] Ale Agent httpsd is listening at 127.0.0.1:9801 
    [INFO] [k8s] config loaded from cluster from "ale-pde/agent-config" 
    [INFO] [stat] stat controller init {"collector":{"prefix":"ale"},"db":{"url":"mongodb://127.0.0.1:64000/","dbName":"ale-pde"},"connection":{"context":"docker-desktop","namespace":"ale-pde"}}
    [INFO] [stat] connect k8s to "docker-desktop" 
    [INFO] [stat] stat watcher started 
    ```

    <Warning>
      実行中にデータベース競合が発生した場合、以下のコマンドで既存のエールデータを削除し、再実行してください。

      ```bash theme={null}
      rm -r ~/.ale-dev  
      ```
    </Warning>
  </Step>
</Steps>

<Note>
  ローカル環境とGitHubを連携し、GitHubリポジトリのソースコードをデプロイできます。
</Note>

<AccordionGroup>
  <Accordion title="ローカル環境とGitHubを連携する">
    **1. GitHub Appsの作成**

    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/authentication/images/01_01.png" />
    </Frame>

    > GitHubにログイン後、**Settings > Developer Settings > GitHub Apps**ページで [New GitHub App](https://github.com/settings/apps/new) をクリックして、GitHub App作成を開始します。

    **1-1. 基本情報の入力**

    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/authentication/images/01_17.png" />
    </Frame>

    > GitHub Appを作成するための情報を以下のように入力してください。

    * **GitHub App name** : GitHub Appの名前
    * **Homepage URL**
      * GitHub OAuthを適用するURL
      * ローカルアクセスアドレス `http://localhost:9001`
    * **Callback URL（`Add Callback URL`で追加）**
      * `http://localhost:9009/oauth/github/callback`
      * `http://localhost:9009/oauth/github/connect/callback`

    <Info>
      この画面で入力した**GitHub App name**はエールのGitHub OAuth登録時に使用されます。
    </Info>

    <Warning>
      ローカル環境のため、httpsではなく`http`で入力する必要があります。また、`localhost:9009`はエールのAPIエンドポイントアドレスです。
    </Warning>

    **1-2. Webhookの無効化**

    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/authentication/images/01_03.png" />
    </Frame>

    > WebhookセクションのActiveチェックを解除して無効化してください。

    **1-3. 権限の付与とAPP作成**

    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/authentication/images/01_04.png" />
    </Frame>

    > Permissionセクションで以下の権限を付与し、`Create GitHub App`をクリックしてAPPを作成してください。

    <AccordionGroup>
      <Accordion title="Repository permissions (9)">
        * **Read and Write**
          * Actions
          * Administration
          * Commit statuses
          * Contents
          * Deployments
          * Issues
          * Pull requests
          * Workflows
        * **Read-only**
          * Metadata
      </Accordion>

      <Accordion title="Organization permissions (2)">
        * **Read and Write**
          * Administration
        * **Read-only**
          * Members
      </Accordion>

      <Accordion title="Account permissions (1)">
        * **Read-only**
          * Email addresses
      </Accordion>
    </AccordionGroup>

    **2. GitHub App情報の取得**

    > エールのGitHub OAuthを追加するために、GitHub App Name以外に以下の**4つのIDとKeyの値**が必要です。

    * **App ID**
    * **Client ID**
    * **Client Secret**
    * **Private Key**

    **2-1. App IDとClient IDの取得**

    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/authentication/images/01_05.png" />
    </Frame>

    > 権限付与後にAppが作成されると、**App IDとClient ID**を確認できます。

    **2-2. Client Secretの取得**

    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/authentication/images/01_06.png" />
    </Frame>

    > 同じ画面で`Generate a new client secret`をクリックして、**Client Secret**を生成し、確認してください。

    **2-3. Private Keyの取得**

    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/authentication/images/01_08.png" />
    </Frame>

    > 画面下部の`Generate a private key`をクリックするとpemファイルがダウンロードされます。

    **3. エール運用システムへの登録**

    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/authentication/images/01_10.png" />
    </Frame>

    > ブラウザのアドレスバーに`http://localhost:9001`を入力して運用システムにアクセスし、**設定 > 認証手段 > GitHub**ドロップダウンをクリックして、前の手順で取得した値を各フィールドに入力し、`適用する`をクリックしてください。

    * **APP\_NAME** : GitHub Appの名前
    * **APP\_ID** : App ID
    * **CLIENT\_ID** : Client ID
    * **CLIENT\_SECRET** : Client secret
    * **APP\_PRIVATE\_KEY**: Private key pemファイルの値
  </Accordion>
</AccordionGroup>

## ダッシュボードにアクセス

<Frame>
  <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/getting-started/images/ja/02_02.png" />
</Frame>

> ブラウザのアドレスバーに`http://localhost:9001`を入力すると、エールダッシュボードにアクセスできます。初回アクセス時は、デフォルトで作成される`@dev`スペースに接続されます。

<AccordionGroup>
  <Accordion title="運用システムにアクセス">
    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/setup/ec2/images/04_24.png" />
    </Frame>

    > 左上のスペース名をクリックして運用システムを選択すると、アクセスできます。
  </Accordion>
</AccordionGroup>

## デプロイ

<Frame>
  <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/getting-started/images/ja/02_22.png" />
</Frame>

> ダッシュボードの<Icon icon="circle-plus" iconType="solid" size={15} color="2396F1" />または`⌘ + K`で生成されるデプロイモーダルからHTTPBinを選択します。

<Frame>
  <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/getting-started/images/ja/02_04.png" />
</Frame>

> 設定を変更せずに、画面下部の`デプロイ`をクリックします。

<Frame>
  <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/getting-started/images/ja/02_05.png" />
</Frame>

> サービスの起動が完了すると、画面に表示される状態が`稼働中`に変更されます。`アクセス`をクリックすると、起動したサービスに接続できます。

<Tip>
  ローカル環境とGitHubを連携してGitHubリポジトリをデプロイしたり、SSH認証を使用してプライベートリポジトリをデプロイすることができます。一般的なデプロイについてのガイドは[エールでデプロイページ](/ja/developers/deploy)をご参照ください。
</Tip>

<CardGroup cols={3}>
  <Card title="ローカル環境とGitHubの連携" icon="github" href="/ja/getting-started/quickstart#github" horizontal />

  <Card title="プライベートリポジトリのデプロイ" icon="git-alt" href="/ja/developers/private-repo" horizontal />

  <Card title="エールでサービスをデプロイ" icon="rocket" href="/ja/developers/deploy" horizontal />
</CardGroup>
