Commit 58c1c6be authored by Lee Brown's avatar Lee Brown

updated devops which removed use of placeholders in taskdef

parent 46745517
......@@ -5,7 +5,8 @@ services:
variables:
DOCKER_TLS_CERTDIR: ""
GIT_DEPTH: "1"
GIT_DEPTH: "10"
stages:
- setup:dev
- build:dev
......@@ -90,6 +91,8 @@ webapp:build:prod:
- master
- prod
- prod-web-app
dependencies:
- 'infra:setup:prod'
variables:
TARGET_ENV: 'prod'
TARGET_TYPE: 'service'
......@@ -124,6 +127,8 @@ webapi:build:prod:
- master
- prod
- prod-web-api
dependencies:
- 'infra:setup:prod'
variables:
TARGET_ENV: 'prod'
TARGET_TYPE: 'service'
......@@ -158,6 +163,8 @@ ddlogscollector:build:prod:
- master
- prod
- prod-ddlogs
dependencies:
- 'infra:setup:prod'
variables:
TARGET_ENV: 'prod'
TARGET_TYPE: 'function'
......
......@@ -358,6 +358,21 @@ Access/Secret Keys are required
--no-push disable pushing release image to remote repository
```
* `build image` - Executes a build for a single image
```bash
$ cicd -env [dev|stage|prod] build image -name NNNNN [command options]
```
Options:
```bash
--name value, -n value target image, required
--release-tag value, --tag value optional tag to override default CI_COMMIT_SHORT_SHA
--dry-run print out the build details
--no-cache skip caching for the docker build
--no-push disable pushing release image to remote repository
```
* `deploy infrastructure` - Executes a deploy to setup the infrastructure for the deployment environment.
```bash
......
......@@ -538,7 +538,7 @@ func getDatadogApiKey(cfg *devdeploy.Config) (string, error) {
// 3. Check AWS Secrets Manager for Datadog entry.
if apiKey == "" {
secretId := "DATADOG"
secretId := "datadog"
var err error
apiKey, err = devdeploy.GetAwsSecretValue(cfg.AwsCredentials, secretId)
if err != nil {
......
......@@ -15,7 +15,7 @@ import (
type Function = string
var (
Function_Ddlogscollector = "ddlogscollector"
Function_Ddlogscollector Function = "ddlogscollector"
)
// List of function names used by main.go for help.
......
package config
import (
"encoding/json"
"fmt"
"log"
"path/filepath"
"github.com/pkg/errors"
"gitlab.com/geeks-accelerator/oss/devops/pkg/devdeploy"
)
// Image define the name of an image.
type Image = string
var (
ImageYourBaseImage Image = "your-base-image"
)
// List of images names used by main.go for help and append the functions to config.
var ImageNames = []Image{
ImageYourBaseImage,
}
// NewImage returns the *devdeploy.ProjectImage.
func NewImage(imageName string, cfg *devdeploy.Config) (*devdeploy.ProjectImage, error) {
ctx := &devdeploy.ProjectImage{
Name: fmt.Sprintf("%s-%s-%s", cfg.Env, cfg.ProjectName, imageName),
CodeDir: filepath.Join(cfg.ProjectRoot, "build/docker", imageName),
DockerBuildDir: cfg.ProjectRoot,
DockerBuildContext: ".",
// Set the release tag for the image to use include env + function name + commit hash/tag.
ReleaseTag: devdeploy.GitLabCiReleaseTag(cfg.Env, imageName),
}
switch imageName {
case ImageYourBaseImage:
// No specific settings.
default:
return nil, errors.Wrapf(devdeploy.ErrInvalidFunction,
"No context defined for image '%s'",
imageName)
}
// Set the docker file if no custom one has been defined for the service.
if ctx.Dockerfile == "" {
ctx.Dockerfile = filepath.Join(ctx.CodeDir, "Dockerfile")
}
return ctx, nil
}
// BuildImageForTargetEnv executes the build commands for a target image.
func BuildImageForTargetEnv(log *log.Logger, awsCredentials devdeploy.AwsCredentials, targetEnv Env, imageName, releaseTag string, dryRun, noCache, noPush bool) error {
cfg, err := NewConfig(log, targetEnv, awsCredentials)
if err != nil {
return err
}
targetImage, err := NewImage(imageName, cfg)
if err != nil {
return err
}
// Override the release tag if set.
if releaseTag != "" {
targetImage.ReleaseTag = releaseTag
}
// Append build args to be used for all functions.
if targetImage.DockerBuildArgs == nil {
targetImage.DockerBuildArgs = make(map[string]string)
}
// funcPath is used to copy the service specific code in the Dockerfile.
codePath, err := filepath.Rel(cfg.ProjectRoot, targetImage.CodeDir)
if err != nil {
return err
}
targetImage.DockerBuildArgs["code_path"] = codePath
if dryRun {
cfgJSON, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
log.Fatalf("BuildFunctionForTargetEnv : Marshalling config to JSON : %+v", err)
}
log.Printf("BuildFunctionForTargetEnv : config : %v\n", string(cfgJSON))
detailsJSON, err := json.MarshalIndent(targetImage, "", " ")
if err != nil {
log.Fatalf("BuildFunctionForTargetEnv : Marshalling details to JSON : %+v", err)
}
log.Printf("BuildFunctionForTargetEnv : details : %v\n", string(detailsJSON))
return nil
}
return devdeploy.BuildImageForTargetEnv(log, cfg, targetImage, noCache, noPush)
}
This diff is collapsed.
......@@ -149,6 +149,44 @@ func main() {
return config.BuildFunctionForTargetEnv(log, awsCredentials, targetEnv, funcName, releaseTag, dryRun, noCache, noPush)
},
},
{
Name: "image",
Usage: "build an image",
Flags: []cli.Flag{
cli.StringFlag{
Name: "name, n",
Usage: fmt.Sprintf("target image, one of [%s]",
strings.Join(config.ImageNames, ", ")),
Required: true,
},
cli.StringFlag{
Name: "release-tag, tag",
Usage: "optional tag to override default CI_COMMIT_SHORT_SHA",
},
cli.BoolFlag{
Name: "dry-run",
Usage: "print out the build details",
},
cli.BoolFlag{
Name: "no-cache",
Usage: "skip caching for the docker build",
},
cli.BoolFlag{
Name: "no-push",
Usage: "disable pushing release image to remote repository",
},
},
Action: func(c *cli.Context) error {
targetEnv := c.GlobalString("env")
funcName := c.String("name")
releaseTag := c.String("release-tag")
dryRun := c.Bool("dry-run")
noCache := c.Bool("no-cache")
noPush := c.Bool("no-push")
return config.BuildImageForTargetEnv(log, awsCredentials, targetEnv, funcName, releaseTag, dryRun, noCache, noPush)
},
},
},
},
......
......@@ -41,7 +41,7 @@ require (
github.com/tinylib/msgp v1.1.0 // indirect
github.com/urfave/cli v1.21.0
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
gitlab.com/geeks-accelerator/oss/devops v1.0.18
gitlab.com/geeks-accelerator/oss/devops v1.0.19
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7
golang.org/x/tools v0.0.0-20190807223507-b346f7fd45de // indirect
......
......@@ -215,8 +215,8 @@ github.com/urfave/cli v1.21.0/go.mod h1:lxDj6qX9Q6lWQxIrbrT0nwecwUtRnhVZAJjJZrVU
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 h1:zzrxE1FKn5ryBNl9eKOeqQ58Y/Qpo3Q9QNxKHX5uzzQ=
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2/go.mod h1:hzfGeIUDq/j97IG+FhNqkowIyEcD88LrW6fyU3K3WqY=
gitlab.com/geeks-accelerator/oss/devops v1.0.18 h1:Vkk7WrTIvGd+Nnb6ru3o4r1yw4h7lJBdcnGLG71d390=
gitlab.com/geeks-accelerator/oss/devops v1.0.18/go.mod h1:xr+rhNSDXrEh0A6bkBPnfMiRIou3OiPZK0oD5h9GAAM=
gitlab.com/geeks-accelerator/oss/devops v1.0.19 h1:x/PknYjZFZNfrm9TW4wWXlI73Jd56HYrQt3a1IUbpK8=
gitlab.com/geeks-accelerator/oss/devops v1.0.19/go.mod h1:xr+rhNSDXrEh0A6bkBPnfMiRIou3OiPZK0oD5h9GAAM=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment