メモ的な何か

2019-03-06 19:00 - Linux

Hugo + Github Pages + CircleCI

Hugo + Github Pages + CircleCIを使ってデプロイする時に、
CircleCIの設定にハマったので、メモ。

CircleCIに登録する前に

  1. CircleCIがgithubへpushするために、SSH Keyをssh-keygen -t ecdsa -b 384 -m pemで作成しておく

  2. githubに生成したSSH公開鍵を設定

  3. 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の設定

  1. CircleCIのアカウントを作成し、ダッシュボードからADD PROJECT

  2. リポジトリを選択し、Set Up Project

  3. PERMISSIONS、SSH Permissionsを選択し、Add SSH Key

  4. SSH秘密鍵を設定

これでgithubへpushするたびにCircleCIが走り、デプロイしてくれるはず
いろいろミスってfailedしまくった