Hugo + Github Pages + CircleCIを使ってデプロイする時に、
CircleCIの設定にハマったので、メモ。
CircleCIに登録する前に
-
CircleCIがgithubへpushするために、SSH Keyをssh-keygen -t ecdsa -b 384 -m pemで作成しておく
-
githubに生成したSSH公開鍵を設定
-
Hugoのディレクトリに.circleci/config.ymlを作成
- フォルダ構成
.
├── .circleci
│ └── config.yml
├── .git
├── .gitmodules
├── archetypes
├── config.toml
├── content
├── layouts
├── resources
├── static
└── themes
- config.yml
version: 2
jobs:
build:
docker:
- image: cibuilds/hugo:latest
branches:
only:
- master
working_directory: ~/hugo
steps:
- run:
name: Update enviroment
command: apk add --no-cache git
- checkout:
- add_ssh_keys:
fingerprints:
- "xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
- run:
name: Building pages
command: |
git submodule update --init --recursive
HUGO_ENV=production hugo -v
git config --global user.name "xxxx"
git config --global user.email "xxxx"
- run:
name: push to master
command: |
git clone https://github.com/xxxx/xxxx.github.io.git
ls
cp -rp public/* xxxx.github.io/
cd xxxx.github.io
ls
git status
git add .
git commit -m "circle ci update"
git push origin master
fingerprintsは、githubに登録したSSH Keyのfingerprintを設定して、
コミットとプッシュをしておく
CircleCIの設定
-
CircleCIのアカウントを作成し、ダッシュボードからADD PROJECT
-
リポジトリを選択し、Set Up Project
-
PERMISSIONS、SSH Permissionsを選択し、Add SSH Key
-
SSH秘密鍵を設定
これでgithubへpushするたびにCircleCIが走り、デプロイしてくれるはず
いろいろミスってfailedしまくった