AWS Amplify Console は、Web アプリケーションや静的サイトをホスティングできる Web サービスです。 リポジトリの変更をトリガーにして、React や Vue.js などの SPA や、HUGO や Gatsby などの静的サイトジェネレータのビルド・デプロイ・ホスティングができます。
この記事では、次の内容について説明します。
- HUGO で作った静的サイトを AWS Amplify Console を使って、ビルド・デプロイする方法
- ログの確認
- HUGO のバージョン固定
- Pull Request 単位でのプレビュー URL 生成
環境
- Git
- Hugo v0.58.2
AWS Amplify Console でサイトを構築する
HUGO でサイトを作る
ビルドするサイトを作成します。サイト作成の詳細は HUGO で静的サイトを構築する を参照のこと。
hugo new site amplify-console-sample cd amplify-console-sample
テーマは、
git submodule
で追加します。 CodePipeline では submodule は利用できないとありますが、2019年12月21日現在、submodule でのテーマ追加でもビルドできました。Pipeline Error: My GitHub source stage contains Git submodules, but CodePipeline doesn’t initialize them Problem: CodePipeline does not support git submodules. CodePipeline relies on the archive link API from GitHub, which does not support submodules. Possible fixes: Consider cloning the GitHub repository directly as part of a separate script. For example, you could include a clone action in a Jenkins script.
git init
git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
echo 'theme = "ananke"' >> config.toml
記事を作成します。「contents」の下にファイルが作成されます。
hugo new posts/my-first-post.md
contents/posts/my-first-post.md
を開き、draft
フラグをfalse
にします。--- title: "My First Post" date: 2019-03-26T08:47:11+01:00 draft: false
GitHub でリポジトリを作成し、GitHub にプッシュします。
git remote add origin git@github.com:OWNER/REPOSITORY_NAME.git git add . git commit -m "first commit" git push -u origin master
AWS Amplify Console の設定
AWS Amplify Console にアクセスします。
URL にアクセスすると、サイトが生成されていることを確認できます。
https://BRANCH_NAME.RANDOM-LETTER.amplifyapp.com/
ログの確認
HUGO のバージョンを固定する
AWS Amplify Console でビルドする HUGO のバージョンを固定します。
次回以降のビルドから、指定したバージョンの HUGO でビルドできます。
PR 単位で Preview ページを作る
設定
Pull Request 単位で確認用の URL を作成します。
[Install GitHub app]をクリックし、接続している GitHub アカウントに AWS Amplify アプリケーションをインストールします。
AWS Amplify Console の画面に戻ります。Pull Request を出す対象のブランチを選び、[Manage]をクリックします。