Builder Management (Experimental)

This feature is an experimental feature. Currently it is only accessible for approved users. Contact admin to request for permission.

Overview

Builder currently leverages AWS CodeBuild .

Steps to use it:

  1. Write a build spec file named buildspec.yaml, and put it in your source directory.

  2. Save your source in one of the ways listed below:

    • Push to github.com repository.
    • Push to a AWS CodeCommit repository.
    • Create a zip file, and put it into a version-enabled AWS S3 bucket.
  3. Create a build project.

  4. Start to build manually or automatically.

Write a buildspec.yaml

A build spec is a collection of build commands and related settings in YAML format that Builder uses to run a build. By default, the build spec file must be named as buildspec.yml and placed in the root of your source directory.

Syntax

The build spec has the following syntax:

version: 0.2

env:
  variables:
    key: "value"
    key: "value"
  parameter-store:
    key: "value"
    key: "value"

phases:
  install:
    commands:
      - command
      - command
  pre_build:
    commands:
      - command
      - command
  build:
    commands:
      - command
      - command
  post_build:
    commands:
      - command
      - command

artifacts:
  files:
    - location
    - location
  discard-paths: yes
  base-directory: location

cache:
  paths:
    - path
    - path

For details, please refer to AWS CodeBuild Manual.

Examples

Build Docker Images

To build Docker images, Docker daemon needs to be installed and started in the build environment. Otherwise, all associated builds that attempt to interact with the Docker daemon will fail. One way to do this is to initialize the Docker daemon in the install phase of your build spec by running the following build commands. (Do not run the following build commands if you chose a build environment image provided by AWS CodeBuild with Docker support.)

- nohup dockerd --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2375 --storage-driver=overlay&
- timeout -t 15 sh -c "until docker info; do echo .; sleep 1; done"

Directory structure::

(root directory)
|-- buildspec.yml
|-- hello_world.go
`-- Dockerfile

buildspec.yml:

version: 0.2

phases:
  pre_build:
    commands:
      - echo Logging in to Docker Hub...
      # Type the command to log in to your Docker Hub account here.

  install:
    commands:
      # install and start Docker daemon if needed
      - timeout 15 sh -c "until docker info; do echo .; sleep 1; done"

  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image...
      - docker build -t hello_world:v1 .

  post_build:
    commands:
      - echo Build completed on `date`
      - echo Pushing the Docker image...
      - docker push hello_world:v1

Dockerfile:

FROM golang:1.9 as builder
WORKDIR /
COPY hello_world.go .
RUN GOOS=linux go build hello_world.go

FROM ubuntu:16.04
WORKDIR /root/
COPY --from=builder /hello_world .
CMD ["./hello_world"]

hello_world.go:

package main

import "fmt"

func main() {
    fmt.Println("hello world")
}

Building Non-Docker Images

Directory structure:

(root directory)
|-- buildspec.yml
`-- hello_world.go

buildspec.yml:

version: 0.2

phases:
  build:
    commands:
      - echo Build started on `date`
      - GOOS=linux go build hello_world.go

  post_build:
    commands:
      - echo Build completed on `date`

artifacts:
  files:
    - 'hello_world'

hello_world.go:

package main

import "fmt"

func main() {
    fmt.Println("hello world")
}

Create Project

Click Builder -> Projects -> Create on the Builder project list page. Three parts are required to create a builder project:

  • Project’s basic information
  • The source code of the project
  • The build environment of the project

Basic Information

  • Type: The type of project includes Application and Solution
  • Model: Show when type is Solution
  • Project Name: The name of the project
  • Description: The description of the project
_images/builder_create_1.png

Source Code

  • Source Provider:
    • Amazon S3
    • GitHub

If source provider is Amazon S3, then a project image should upload to S3

  • Check periodically for changes.

If source provider is GitHub, there are two params Repository and Branch

  • Repository: The URL of the source code
  • Branch: The branch of the source code
_images/builder_create_2.png _images/builder_create_22.png

Build Environment

  • Image: The image of the project
  • Artifacts: The Artifacts of the project
  • Commands: The Commands of the project
  • Compute Type:
    • 3GB memory 2 vCPU
    • 7GB memory 4 vCPU
    • 15GB memory 8 vCPU
  • Timeout
_images/builder_create_3.png

Manage Project

Click Builder -> Projects on the left navigation.

_images/builder.png

Start/Edit/Delete

  • Click start (the first button) on the Action column, and you can start this project. The status will change to Running.
  • Click edit (the second button) on the Action column, and the page will link to the edit page. For guidance to the following steps, refer back to Create Project.
  • Click delete (the third button) on the Action column, and you can delete this project.

View Project Detail

  • Click Name column to check the detail information about this project.
_images/builder_detail.png _images/builder_detail_2.png

View Project Log

  • Click Log column to check the log information about this project.
_images/builder_log.png