Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

Commit

Permalink
Add build command
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrkubisa committed Nov 2, 2018
1 parent 760d558 commit fff23c1
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmd/localcb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ func main() {
app := cli.NewApp()
app.Name = "localcb"
app.Usage = "Run AWS CodeBuild pipeline directly on your local machine"
app.Version = "0.3.0"
app.Version = "0.4.0"
app.Commands = []cli.Command{
codebuild.BuildCommand(),
codebuild.RunCommand(),
}

Expand Down
108 changes: 108 additions & 0 deletions provider/codebuild/cmd_build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package codebuild

import (
"fmt"
"os"
"strings"
"text/template"

"github.com/piotrkubisa/localcb/cmd"
"github.com/urfave/cli"
)

var buildFlags = struct {
DockerImage cmd.FlagPair
}{
DockerImage: cmd.NewFlagPair("image", "i"),
}

var buildTemplate = `cd /tmp
git clone https://github.com/aws/aws-codebuild-docker-images.git
cd aws-codebuild-docker-images
cd {{.ImagePath}}
docker build -t {{.DockerImage}} .
`

// BuildCommand registers a cli.Command
func BuildCommand() cli.Command {
return cli.Command{
Name: "build",
Usage: "Prepares shell script to build one of the AWS CodeBuild curated Docker image",
ArgsUsage: "<docker-image>",
Action: buildCommand,
}
}

func buildCommand(c *cli.Context) error {
image := c.Args().Get(0)
if image == "" {
return fmt.Errorf("Provide name of the docker image, i.e. aws/codebuild/golang:1.10 or golang:1.10")
}

var imagePath string
var dockerImage string
shortImage := strings.TrimPrefix(image, "aws/codebuild/")

switch image {
case "android-java-8:24.4.1":
fallthrough
case "android-java-8:26.1.1":
fallthrough
case "docker:17.09.0":
fallthrough
case "dot-net:core-1":
fallthrough
case "dot-net:core-2.1":
fallthrough
case "dot-net:core-2":
fallthrough
case "golang:1.10":
fallthrough
case "java:openjdk-8":
fallthrough
case "java:openjdk-9":
fallthrough
case "nodejs:10.1.0":
fallthrough
case "nodejs:6.3.1":
fallthrough
case "nodejs:8.11.0":
fallthrough
case "php:5.6":
fallthrough
case "php:7.0":
fallthrough
case "python:2.7.12":
fallthrough
case "python:3.3.6":
fallthrough
case "python:3.4.5":
fallthrough
case "python:3.5.2":
fallthrough
case "python:3.6.5":
fallthrough
case "ruby:2.2.5":
fallthrough
case "ruby:2.3.1":
fallthrough
case "ruby:2.5.1":
fallthrough
case "ubuntu-base:14.04":
imagePath = "ubuntu/" + strings.Replace(shortImage, ":", "/", 1)
dockerImage = "aws/codebuild/" + shortImage
default:
return fmt.Errorf("Unknown image name (%s), you might need to build it manually", image)
}

tpl, err := template.New("script").Parse(buildTemplate)
if err != nil {
return err
}

data := struct {
ImagePath string
DockerImage string
}{imagePath, dockerImage}
return tpl.Execute(os.Stdout, data)
}

0 comments on commit fff23c1

Please sign in to comment.