Go moduleを使ったCircleCIのconfig.yml


環境

  • AWS Cloud9 (シンガポールリージョンのEC2上で動作)
  • Amazon Linux2
  • zsh

Go 1.11より go mod が使えるようになる

go modとは

.circleci/config.yml


version: 2
jobs:
  build:
    working_directory: /go/src/github.com/teixy/

    docker:
      - image: circleci/golang:1.11.5
        environment:
          GO111MODULE: "on"

    steps:
      - checkout

      - restore_cache:
          name: Restore go modules cache
          keys:
              - v1-mod-{{ .Branch }}-{{ checksum "go/go.mod" }}

      - run:
          name: Vendoring
          command: go mod download

      - save_cache:
          name: Save go modules cache
          key: v1-mod-{{ .Branch }}-{{ checksum "go/go.mod" }}
          paths:
              - ~/go/pkg/mod/cache

      - run:
          name: Build go binary
          command: |
              go build -v -o go/main go/main.go

workflows:
    version: 2
    build:
      jobs:
        - build