概要
- CirclCIを導入検証する
- CircleCIはビルド・テスト・デプロイのCI/CDを自動で実行するサービス
- とりあえずmasterブランチにPUSHしたらビルドが走るという挙動を試す
- デプロイは次回
- 無料で結構使えるので前向きに検討
設定
アカウント登録
- Githubアカウントがある事が前提
- "Sign up with github"でアカウント登録
- "Authorize CirclCI"で承認
- "Githubのパスワードを入力
プロジェクト作成
- CirclCIの画面へ遷移
- "Add Project"を選択しプロジェクトを設定する画面へ遷移
- ProjectイコールGithubのリポジトリ
- "Set Up Project"をクリック
- プロジェクト設定画面へ遷移。OSと言語を選択。
- ”Copy to Clipboad"でSample .yml をコピー
- ローカルで/.circleci/config.yml新規ファイル作成しペースト
$ git clone https://github.com/<repo-name>/circleci.git
$ cd circleci
$ mkdir .circleci
$ vim .circleci/config.yml
$ git add .
$ git commit -m 'add .circleci/config.yml'
$ git push origin master
config.yml
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
jobs:
build:
docker:
# specify the version
- image: circleci/golang:1.9
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4
#### TEMPLATE_NOTE: go expects specific checkout path representing url
#### expecting it in the form of
#### /go/src/github.com/circleci/go-tool
#### /go/src/bitbucket.org/circleci/go-tool
working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}}
steps:
- checkout
# specify any bash command here prefixed with `run: `
- run: go get -v -t -d ./...
- run: go test -v ./...
ビルド開始
- "start building"をクリックしビルド開始
- ビルドが成功すると”success"が表示される
- "Jobs"タブを選びビルドの様子をモニタリング
出力サンプル
Spin up Environment
Build-agent version 1.0.9934-d6876d00 (2019-04-01T12:08:20+0000)
Docker Engine Version: 17.05.0-ce
Kernel Version: Linux 681d5dd07475 4.4.0-141-generic #167~14.04.1-Ubuntu SMP Mon Dec 10 13:20:24 UTC 2018 x86_64 Linux
Starting container circleci/golang:1.9
image cache not found on this host, downloading circleci/golang:1.9
1.9: Pulling from circleci/golang
:
:
Digest: sha256:acc81847ea4e5b11a61f62aaab537dc622027e406f2b36da6e36215aa7c89447
Status: Downloaded newer image for circleci/golang:1.9
using image circleci/golang@sha256:acc81847ea4e5b11a61f62aaab537dc622027e406f2b36da6e36215aa7c89447
Using build environment variables
BASH_ENV=/tmp/.bash_env-5ca5e9ead40cb80009de2c6f-0-build
CI=true
CIRCLECI=true
CIRCLE_BRANCH=master
CIRCLE_BUILD_NUM=2
CIRCLE_BUILD_URL=https://circleci.com/gh/<org_name>/circleci/2
CIRCLE_COMPARE_URL=
CIRCLE_JOB=build
CIRCLE_NODE_INDEX=0
CIRCLE_NODE_TOTAL=1
CIRCLE_PREVIOUS_BUILD_NUM=1
CIRCLE_PROJECT_REPONAME=circleci
CIRCLE_PROJECT_USERNAME=<org_name>
CIRCLE_REPOSITORY_URL=git@github.com:<org_name>/circleci.git
CIRCLE_SHA1=200f1a89b0398b0aab9c9031fc73f61f18be00af
CIRCLE_SHELL_ENV=/tmp/.bash_env-5ca5e9ead40cb80009de2c6f-0-build
CIRCLE_STAGE=build
CIRCLE_USERNAME=<org_name>
CIRCLE_WORKFLOW_ID=eabfbd03-aae7-4da9-b80d-fce9e8b78aab
CIRCLE_WORKFLOW_JOB_ID=232e1300-5f4b-4744-82fe-6bd74eefa92e
CIRCLE_WORKFLOW_UPSTREAM_JOB_IDS=
CIRCLE_WORKFLOW_WORKSPACE_ID=eabfbd03-aae7-4da9-b80d-fce9e8b78aab
CIRCLE_WORKING_DIRECTORY=/go/src/github.com/<org_name>/circleci
Using environment variables from project settings and/or contexts
CIRCLE_JOB=**REDACTED**
Checkout code
#!/bin/sh
set -e
\# Workaround old docker images with incorrect $HOME
\# check https://github.com/docker/docker/issues/2968 for details
if [ "\${HOME}" = "/" ]
then
export HOME=$(getent passwd $(id -un) | cut -d: -f6)
fi
mkdir -p ~/.ssh
echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQExxxxxxxxxxxxxxx43JXiUFFAaQ==
bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxxxxxxxxxxxxxxxVBoGqzHM9yXw==
' >> ~/.ssh/known_hosts
(umask 077; touch ~/.ssh/id_rsa)
chmod 0600 ~/.ssh/id_rsa
(cat <<EOF > ~/.ssh/id_rsa
$CHECKOUT_KEY
EOF
)
#### use git+ssh instead of https
git config --global url."ssh://git@github.com".insteadOf "https://github.com" || true
git config --global gc.auto 0 || true
if [ -e /go/src/github.com/<org_name>/circleci/.git ]
then
cd /go/src/github.com/<org_name>/circleci
git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true
else
mkdir -p /go/src/github.com/<org_name>/circleci
cd /go/src/github.com/<org_name>/circleci
git clone "$CIRCLE_REPOSITORY_URL" .
fi
if [ -n "$CIRCLE_TAG" ]
then
git fetch --force origin "refs/tags/${CIRCLE_TAG}"
else
git fetch --force origin "master:remotes/origin/master"
fi
if [ -n "$CIRCLE_TAG" ]
then
git reset --hard "$CIRCLE_SHA1"
git checkout -q "$CIRCLE_TAG"
elif [ -n "$CIRCLE_BRANCH" ]
then
git reset --hard "$CIRCLE_SHA1"
git checkout -q -B "$CIRCLE_BRANCH"
fi
git reset --hard "$CIRCLE_SHA1"
Cloning into '.'...
Warning: Permanently added the RSA host key for IP address '192.30.xxx.xxx' to the list of known hosts.
remote: Enumerating objects: 16, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 16 (delta 4), reused 7 (delta 2), pack-reused 0
Receiving objects: 100% (16/16), done.
Resolving deltas: 100% (4/4), done.
HEAD is now at 200f1a8 add .circleci/config.yml
HEAD is now at 200f1a8 add .circleci/config.yml
- go get -v -t -d ./...
#!/bin/bash -eo pipefail
go get -v -t -d ./...
- go test -v ./...
#!/bin/bash -eo pipefail
go test -v ./...
=== RUN TestHelloWorld
--- PASS: TestHelloWorld (0.00s)
PASS
ok github.com/masamitsu-ezaki/circleci 0.001s
所感
- 問題なくビルドできた
- UIも見やすい。AWSやJenkinsに比べてもかなり扱いやすく見やすい
- yamlファイルをリポジトリに入れて設定するのはCodeBuildなども同じ。簡単にできそう。
- Githubとの親和性はこちらのほうが高い。Privateリポジトリが無料になったので使わない手はないかな。
- Slack通知が簡単
- デプロイの方も検証してみる