2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AWS Amplify標準ではないバージョンのhugoでビルドする。

Last updated at Posted at 2019-12-14

Are you ready?

hugoのテーマを変更した後、localhostでは機嫌よく動いていたhugoがAWS Amplifyでビルドすると失敗した。

####↓動かしたビルド。

amplify.yml
version: 0.1
frontend:
  phases:
    build:
      commands:
        - echo $(hugo version)
        - hugo
  artifacts:
    baseDirectory: docs
    files:
      - '**/*'
  cache:
    paths: []

####↓結果

                                 # Starting phase: build
2019-12-12T07:47:12.672Z [INFO]: # Executing command: echo Hugo Static Site Generator v0.55.6-A5D4C82D linux/amd64 BuildDate: 2019-05-18T07:56:30Z
2019-12-12T07:47:12.699Z [INFO]: Hugo Static Site Generator v0.55.6-A5D4C82D linux/amd64 BuildDate: 2019-05-18T07:56:30Z
2019-12-12T07:47:12.701Z [INFO]: # Executing command: hugo
2019-12-12T07:47:12.814Z [INFO]: ERROR 2019/12/12 07:47:12 HUGO-THEME-DREAM theme does not support Hugo version 0.55.6. Minimum version required is 0.57.2
                                 Building sites …
2019-12-12T07:47:13.006Z [INFO]: Total in 192 ms
2019-12-12T07:47:13.007Z [WARNING]: Error: Error building site: logged 1 error(s)
2019-12-12T07:47:13.009Z [ERROR]: !!! Build failed
2019-12-12T07:47:13.009Z [ERROR]: !!! Non-Zero Exit Code detected
2019-12-12T07:47:13.009Z [INFO]: # Starting environment caching...
2019-12-12T07:47:13.010Z [INFO]: # Environment caching completed
Terminating logging...

どうもAmplifyで動いているhugoのパッケージが古く、
変更したテーマが新しいバージョンのhugoじゃないと動かないようだ。

AmplifyはAWSマネージドのサービスだし、標準パッケージが古いんじゃどうしようもない… なんてことはない。

さぁ、実験をはじめようか。

Amplifyのコンソールより、【アプリの設定】→【ビルドの設定】→【Build image settings
】の【Edit】を選択すると以下画面が出てくる。

image.png

【Add Package version override】より、Amplifyが用意しているパッケージのlatestバージョンを選ぶことが出来る。

image.png

これで、一番新しいバージョンのhugoでビルド出来るようになる。

                                 # Starting phase: build
2019-12-12T09:14:58.530Z [INFO]: # Executing command: echo Hugo Static Site Generator v0.61.0-9B445B9D linux/amd64 BuildDate: 2019-12-11T08:27:34Z
2019-12-12T09:14:58.578Z [INFO]: Hugo Static Site Generator v0.61.0-9B445B9D linux/amd64 BuildDate: 2019-12-11T08:27:34Z
                                 # Executing command: hugo
2019-12-12T09:14:58.615Z [INFO]: Building sites …
ifact is: 239MB
019-12-12T09:13:42.527Z [INFO]: Git SSH Key acquired
2019-12-12T09:13:42.633Z [INFO]: # Cloning repository: git@github.com:xxxx/xxxx.git
2019-12-12T09:13:42.782Z [INFO]: Agent pid 68
2019-12-12T09:13:42.788Z [INFO]: Identity added: /root/.ssh/git_rsa (/root/.ssh/git_rsa)
2019-12-12T09:13:43.078Z [INFO]: Cloning into 'hugo7'...
2019-12-12T09:13:43.893Z [INFO]: Warning: Permanently added the RSA host key for IP address '13.114.40.48' to the list of known hosts.
2019-12-12T09:14:11.066Z [INFO]: # Checking for Git submodules at: /codebuild/output/src681934525/src/hugo7/.gitmodules
2019-12-12T09:14:11.184Z [INFO]: # Updating Git submodules...
2019-12-12T09:14:15.275Z [INFO]: # Retrieving cache...
2019-12-12T09:14:15.417Z [INFO]: # Extracting cache...
2019-12-12T09:14:15.428Z [INFO]: # Extraction completed
2019-12-12T09:14:15.428Z [INFO]: # Retrieving environment cache...
2019-12-12T09:14:15.473Z [INFO]: # Retrieved environment cache
2019-12-12T09:14:29.543Z [INFO]: # Ensuring Hugo is version: 'latest'
2019-12-12T09:14:29.545Z [INFO]: # Patching Hugo package from 0.55.6 to 0.61.0...
2019-12-12T09:14:34.110Z [INFO]: # Done patching Hugo
                                 # Starting phase: build
2019-12-12T09:14:58.530Z [INFO]: # Executing command: echo Hugo Static Site Generator v0.61.0-9B445B9D linux/amd64 BuildDate: 2019-12-11T08:27:34Z
2019-12-12T09:14:58.578Z [INFO]: Hugo Static Site Generator v0.61.0-9B445B9D linux/amd64 BuildDate: 2019-12-11T08:27:34Z
                                 # Executing command: hugo

勝利の法則は決まった!

とはいえ、使えるバージョンが標準とlatestだけというのは、いささか不安が残る。
もしかしたらlatestバージョンに対応してないけど、Amplify標準では古すぎる…なんてこともあるかもしれない。

そういう時はビルドをギュインギュインのズドドドドにしてみよう!
####↓ギュインギュインのズドドドド

amplify.yml
version: 0.2
frontend:
  phases:
    build:
      commands:
        - wget https://github.com/gohugoio/hugo/releases/download/v0.57.2/hugo_0.57.2_Linux-64bit.tar.gz
        - tar -xf hugo_0.57.2_Linux-64bit.tar.gz hugo
        - mv hugo /usr/bin/hugo
        - rm -rf hugo_0.57.2_Linux-64bit.tar.gz
        - echo $(hugo version)
        - hugo
  artifacts:
    baseDirectory: docs
    files:
      - '**/*'
  cache:
    paths: []

参考元:Specifying Hugo Version on AWS Amplify

変更したテーマが対応しているhugo v0.57.2をwgetでコンテナにダウンロードし、
hugoというフォルダに解凍して、usr/binに移動(インストール)。
不要なファイルは削除してキレイキレイ。

                                 # Starting phase: build
                                 # Executing command: wget https://github.com/gohugoio/hugo/releases/download/v0.57.2/hugo_0.57.2_Linux-64bit.tar.gz
2019-12-13T01:30:03.833Z [WARNING]: --2019-12-13 01:30:03--  https://github.com/gohugoio/hugo/releases/download/v0.57.2/hugo_0.57.2_Linux-64bit.tar.gz
2019-12-13T01:30:03.838Z [WARNING]: Resolving github.com (github.com)...

~省略~

2019-12-13T01:30:06.652Z [INFO]: # Executing command: tar -xf hugo_0.57.2_Linux-64bit.tar.gz hugo
2019-12-13T01:30:06.944Z [INFO]: # Executing command: mv hugo /usr/bin/hugo
2019-12-13T01:30:06.974Z [INFO]: # Executing command: rm -rf hugo_0.57.2_Linux-64bit.tar.gz
2019-12-13T01:30:06.997Z [INFO]: # Executing command: echo Hugo Static Site Generator v0.57.2-A849CB2D linux/amd64 BuildDate: 2019-08-17T17:54:13Z
2019-12-13T01:30:07.017Z [INFO]: Hugo Static Site Generator v0.57.2-A849CB2D linux/amd64 BuildDate: 2019-08-17T17:54:13Z
2019-12-13T01:30:07.018Z [INFO]: # Executing command: hugo

#####ヒャッホホホヒャッホイ!
無事にv0.57.2でビルド出来た。
こちらを応用してAmplify標準以外のパッケージをインストールできるので、
思っている以上に柔軟なマネージドサービスだね。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?