このページでは、バージョン間の変更点と、あるバージョンから別のバージョンへの移行方法について説明します。

Morph 0.2.1 to 0.3.0

Dockerfileのアップデート: フロントエンドのビルド

v0.3.0ではフロントエンドのビルドが追加されました。ローカル環境から morph deploy を実行する場合は、以下のようにDockerfileを更新してください。

FROM node:lts AS morph-frontend-build

WORKDIR /var/task

# Copy source code and dependencies
COPY . .

RUN npm install
RUN npm run build

# Base image for Morph Cloud
FROM public.ecr.aws/i1l4z0u0/morph-data:python3.12

# Set working directory
WORKDIR /var/task

# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt --target "\${MORPH_PACKAGE_ROOT}"

# Copy source code and dependencies
COPY . .

COPY --from=morph-frontend-build /var/task/.morph .morph
COPY --from=morph-frontend-build /var/task/dist dist

# Command to run the Lambda function
CMD python "\${MORPH_APP_FILE_PATH}"

morph_project.ymlのアップデート

v0.3.0では、morph_project.ymlの設定が変更になりました。こちらのリファレンスを参照してください。

version: '1'

# Framework Settings
default_connection: DUCKDB
source_paths:
- src

# Cloud Settings
profile: default # Defined in the Profile Section in `~/.morph/credentials`
project_id: xxxxxx-xxxxx-xxxx-xxxxx

# Build Settings
build:
    # These settings are required when there is no Dockerfile in the project root.
    # They define the environment in which the project will be built
    runtime: python3.9 # python3.9, python3.10, python3.11, python3.12
    framework: morph # morph | streamlit
    package_manager: pip # pip, poetry, uv
    # These settings are required when there is a Dockerfile in the project root.
    # They define how the Docker image will be built
    context: .
    build_args:
        ARG1: value1
        ARG2: value2

# Deployment Settings
deployment:
    provider: aws
    aws:
        region: us-east-1
        memory: 512
        timeout: 30
    gcp:
        region: us-central1
        memory: "1Gi"
        cpu: 1
        concurrency: 80
        timeout: 300

フロントエンドのアップデート

v0.3.0 ではフロントエンドのプロジェクト構成が変更されました。

マイグレーションのために以下の手順でプロジェクトをアップデートしてください。

  1. morph-data~=0.3をインストール後、以下のコマンドを実行してください
    • プロジェクトのルートで実行してください。
    • venv や virtualenv を利用している場合は、仮想環境を有効化した状態で実行してください。
  2. [npm のパッケージを追加でインストールしていた場合のみ] インストールしていたパッケージを手動で再度インストールしてください。
python <<EOF
import morph
import os
import shutil
import subprocess

morph_data_installed_dir = os.path.dirname(morph.__file__)
starter_template_dir = os.path.join(
    morph_data_installed_dir, "include", "starter_template"
)

def migrate_frontend():
    def copy_starter_template_file(path: str):
        src = os.path.join(starter_template_dir, path)
        dst = os.path.join(os.getcwd(), path)

        os.makedirs(os.path.dirname(dst), exist_ok=True)
        shutil.copy(src, dst)

    # Copy files
    copy_starter_template_file("vite.config.ts")
    copy_starter_template_file("tsconfig.json")
    copy_starter_template_file("package.json")
    copy_starter_template_file("components.json")
    copy_starter_template_file("src/pages/_app.tsx")
    copy_starter_template_file("src/pages/404.tsx")
    copy_starter_template_file("src/pages/index.css")
    copy_starter_template_file("src/pages/_lib/utils.ts")
    copy_starter_template_file("src/pages/_components/table-of-contents.tsx")
    copy_starter_template_file("src/pages/_components/header.tsx")

    # Init components
    subprocess.run(
        [
            "npx",
            "shadcn@latest",
            "add",
            "--yes",
            "https://morph-components.vercel.app/r/morph-components.json",
        ],
    )

    subprocess.run(
        [
            "npm",
            "install",
        ],
    )

if __name__ == "__main__":
    migrate_frontend()

EOF

Morph 0.1.9 to 0.2.0

Dockerfileのアップデート: CMDコマンドの変更

Github連携に伴いMorphで構築したアプリの実行コマンドをデプロイ環境にインストールする方法が変更になりました。 具体的にはローカル環境で作成した.morph/core/morphディレクトリにあるapi/app.pyをデプロイ環境にコピーする方式から、パッケージとしてインストールされたファイルを実行する方式に変更になりました。 それに伴い、morph deploy実行時にもv0.2.0以降ではdockerfileでのエントリーポイントが変更になっています。

v0.2.0の変更でmorph newコマンドで生成されるDockerfileのCMDコマンドが変更されましたので、これまでのバージョンをお使いの場合はCMDコマンドを変更してください。

# Base image for Morph Cloud
FROM public.ecr.aws/i1l4z0u0/morph-data:python3.9

# Set working directory
WORKDIR /var/task

# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt --target "${MORPH_PACKAGE_ROOT}"

# Copy source code and dependencies
COPY . .

# Command to run the Lambda function
CMD python "${MORPH_APP_FILE_PATH}"

/staticディレクトリの追加

v0.2.0ではスタティックファイルをホストするための/staticディレクトリが追加されました。/static以下に配置されたファイルは、フロントエンドアプリケーションからアクセスできます。

# `/static`ディレクトリに配置されたファイルを画像として表示する例

![Logo](/static/logo.png)

これまでのバージョンをお使いの場合は/staticディレクトリを作成してください。

Morph 0.1.7 to 0.1.8

Dockerfileのアップデート: <LLM /> <Chat />のストリーミング処理の改善

LLMを用いたストリーミングレスポンスの挙動の改善に伴い、DockerfileのベースイメージとCMDの設定が変更されました。

v0.1.8以降で morph new コマンドで初期生成されるDockerfileは以下の形式で初期化をされます。

# Base image for Morph Cloud
FROM public.ecr.aws/i1l4z0u0/morph-data:python3.9

# Set working directory
WORKDIR /var/task

# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt --target "${MORPH_TASK_ROOT}"

# Copy source code and dependencies
COPY . .

# Command to run the Lambda function
CMD ["python", ".morph/core/morph/api/app.py"]

併せて、初期化時に.dockerignoreファイルを生成し、COPYコマンドでは個別のファイルのコピーではなく、.dockerignoreファイルで除外されたファイルを除外したディレクトリをコピーするように変更しました。

これによりローカルの開発環境でのディレクトリ構成が変更された場合もDockerfileの更新が不要になります。