静的ファイルのホスティングをPage CreatorからApp Engineに移行
Google AppsのGoogle Page Creatorを HTMLやイメージなどの静的ファイルをホスティングするのに使ってたけど、Google Page Creatorが6月で終了する ことになってしまったので、これらのファイルをGoogle App Engineに ホスティングすることにした。その時の手順などをメモっておく。
参考
アカウントの作成
- Googleのアカウントで Google App Engine にログイン
- 携帯のメールアドレスを入力(GAEのコードを受け取るため)
- Create Application ボタンを押し、携帯で受信した Google App Engine Code を入力
- 任意の Application ID と Title を設定
Google App Engine Launcher でアプリケーションを設定する (Mac OSX)
- Google App Engine SDKをダウンロード
- Google App Engine Launcher をアプリケーションにコピー(インストール)
- Google App Engine Launcher を起動
- ’+’ をクリックしてアプリケーションを作成
- Application name を入力して、ディレクトリを指定
- Create をクリック
静的ファイル用にディレクトリを作成
-
アプリケーション用のディレクトリの下に、ディレクトリを作成する (上の手順で作ったアプリケーション用のディレクトリには *.yaml や main.py ができている)
yourappdirectory/ +- assets/ | +- archives/ | +- css/ | +- html/ | +- img/ | +- js/ | +- xml/ | +- app.yaml +- index.yaml +- main.py -
app.yaml を編集する。 (上の例では yourappdirectory/app.yaml)
application: yourappname version: 1 runtime: python api_version: 1 handlers: - url: /(.*\.zip) static_files: assets/archive/\1 upload: assets/archive/(.*\.zip) - url: /(.*\.css) static_files: assets/css/\1 upload: assets/css/(.*\.css) - url: /(.*\.html) static_files: assets/html/\1 upload: assets/html/(.*\.html) - url: /(.*\.(gif|png|jpg)) static_files: assets/img/\1 upload: assets/img/(.*\.(gif|png|jpg)) - url: /(.*\.js) static_files: assets/js/\1 upload: assets/js/(.*\.js) - url: /(.*\.xml) static_files: assets/xml/\1 upload: assets/xml/(.*\.xml) - url: / static_files: assets/html/index.html upload: assets/html/index.html - url: /index.html static_files: assets/html/index.html upload: assets/html/index.html - url: .* script: main.py
この設定では、静的ファイルはすべてルートディレクトリでアクセスできるようにしている。これは Google Page Creator でそうだったから、今までの URL をそのまま使えるようにするため。
テスト
- Google App Engine Launcher で Run ボタンを押す
- http://localhost:8080/ にアクセス
デプロイ
Google App Engine Launcher はワンクリックでデプロイできる。ツールバーの Deploy ボタンを押すだけ。
Google Apps で独自ドメインにひもづける
- Google App Engine のダッシュボードにログイン
- サイドバーの Administration 以下にある ‘Versions’ に移動
- ‘Domain Setup’ の ‘Add Domain’ ボタンを押す
- 自分のドメイン名(Google Appsの)を入力し ‘Add Dmain’ を押す
- Google Apps のコントロールパネルで ‘Activate This Service’
- App Engine にサブドメインを設定
- 自分のドメインの DNS で上のサブドメインに対し、CNAME に ‘ghs.google.com.’ と設定