Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
.hugo_build.lock
/build-result.json
/deploy-result.json
.idea/
13 changes: 7 additions & 6 deletions cmd/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package main

import (
"fmt"
"github.com/g2a-com/cicd/internal/component"
"github.com/g2a-com/cicd/internal/component/executor"
"os"
"path/filepath"

. "github.com/g2a-com/cicd/internal/blueprint"
"github.com/g2a-com/cicd/internal/flags"
"github.com/g2a-com/cicd/internal/object"
"github.com/g2a-com/cicd/internal/schema"
"github.com/g2a-com/cicd/internal/script"
"github.com/g2a-com/cicd/internal/utils"
Expand Down Expand Up @@ -63,7 +64,7 @@ func main() {
assert(err == nil, err)

// Helper for getting executors
getExecutor := func(kind object.Kind, name string) object.Executor {
getExecutor := func(kind component.Kind, name string) executor.Executor {
e, ok := blueprint.GetExecutor(kind, name)
assert(ok, fmt.Errorf("%s %q does not exist", kind, name))
return e
Expand All @@ -73,13 +74,13 @@ func main() {
for _, service := range blueprint.ListServices() {
l := l.WithTags(service.Name())

if len(service.Entries(object.BuildEntryType)) == 0 {
if len(service.Entries(component.BuildEntryType)) == 0 {
l.WithLevel(log.VerboseLevel).Print("No artifacts to build")
continue
}

// Generate tags
for _, entry := range service.Entries(object.TagEntryType) {
for _, entry := range service.Entries(component.TagEntryType) {
s := script.New(getExecutor(entry.ExecutorKind(), entry.ExecutorName()))
s.Logger = l

Expand All @@ -101,7 +102,7 @@ func main() {
}

// Build artifacts
for _, entry := range service.Entries(object.BuildEntryType) {
for _, entry := range service.Entries(component.BuildEntryType) {
s := script.New(getExecutor(entry.ExecutorKind(), entry.ExecutorName()))
s.Logger = l

Expand All @@ -124,7 +125,7 @@ func main() {
for _, service := range blueprint.ListServices() {
l := l.WithTags("push", service.Name())

for _, entry := range service.Entries(object.PushEntryType) {
for _, entry := range service.Entries(component.PushEntryType) {
s := script.New(getExecutor(entry.ExecutorKind(), entry.ExecutorName()))
s.Logger = l

Expand Down
10 changes: 6 additions & 4 deletions cmd/build/options.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package main

import "github.com/g2a-com/cicd/internal/object"
import (
"github.com/g2a-com/cicd/internal/component"
)

type options struct {
object.GenericObject
component.Backbone

Push bool `flag:"push" alias:"p" help:"Push artifacts to remote registry"`
Services []string `flag:"services" alias:"s" help:"List of services to build (skip to build all services)"`
Expand All @@ -12,8 +14,8 @@ type options struct {
ResultFile string `flag:"result-file" help:"Where to write result file"`
}

func (o options) Kind() object.Kind {
return object.OptionsKind
func (o options) Kind() component.Kind {
return component.OptionsKind
}

func (o options) PlaceholderValues() map[string]interface{} {
Expand Down
12 changes: 6 additions & 6 deletions cmd/build/result.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/g2a-com/cicd/internal/object"
"github.com/g2a-com/cicd/internal/component"
)

type ResultEntry struct {
Expand All @@ -16,7 +16,7 @@ type Result struct {
PushedArtifacts []ResultEntry `json:"pushedArtifacts"`
}

func (r *Result) getTags(service object.Object) (tags []string) {
func (r *Result) getTags(service component.Component) (tags []string) {
for _, r := range r.Tags {
if r.Service == service.Name() {
tags = append(tags, r.Result)
Expand All @@ -25,13 +25,13 @@ func (r *Result) getTags(service object.Object) (tags []string) {
return tags
}

func (r *Result) addTags(service object.Object, entry object.Entry, tags []string) {
func (r *Result) addTags(service component.Component, entry component.Entry, tags []string) {
for _, tag := range tags {
r.Tags = append(r.Tags, ResultEntry{service.Name(), entry.Index(), tag})
}
}

func (r *Result) getArtifacts(service object.Object, entry object.Entry) (artifacts []string) {
func (r *Result) getArtifacts(service component.Component, entry component.Entry) (artifacts []string) {
for _, r := range r.Artifacts {
if r.Service == service.Name() && r.Entry == entry.Index() {
artifacts = append(artifacts, r.Result)
Expand All @@ -40,13 +40,13 @@ func (r *Result) getArtifacts(service object.Object, entry object.Entry) (artifa
return artifacts
}

func (r *Result) addArtifacts(service object.Object, entry object.Entry, artifacts []string) {
func (r *Result) addArtifacts(service component.Component, entry component.Entry, artifacts []string) {
for _, artifact := range artifacts {
r.Artifacts = append(r.Artifacts, ResultEntry{service.Name(), entry.Index(), artifact})
}
}

func (r *Result) addPushedArtifacts(service object.Object, entry object.Entry, artifacts []string) {
func (r *Result) addPushedArtifacts(service component.Component, entry component.Entry, artifacts []string) {
for _, artifact := range artifacts {
r.PushedArtifacts = append(r.PushedArtifacts, ResultEntry{service.Name(), entry.Index(), artifact})
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package main

import (
"fmt"
"github.com/g2a-com/cicd/internal/component"
"os"
"path/filepath"
"strings"

. "github.com/g2a-com/cicd/internal/blueprint"
"github.com/g2a-com/cicd/internal/flags"
"github.com/g2a-com/cicd/internal/object"
"github.com/g2a-com/cicd/internal/schema"
"github.com/g2a-com/cicd/internal/script"
"github.com/g2a-com/cicd/internal/utils"
Expand Down Expand Up @@ -73,14 +73,14 @@ func main() {
for _, service := range blueprint.ListServices() {
l := l.WithTags(service.Name())

if len(service.Entries(object.DeployEntryType)) == 0 {
if len(service.Entries(component.DeployEntryType)) == 0 {
l.WithLevel(log.VerboseLevel).Print("No releases to deploy")
continue
}

l.Printf(`Deploying service %q...`, service.Name())

for _, entry := range service.Entries(object.DeployEntryType) {
for _, entry := range service.Entries(component.DeployEntryType) {
e, ok := blueprint.GetExecutor(entry.ExecutorKind(), entry.ExecutorName())
assert(ok, fmt.Errorf("%s %q does not exist", strings.ToLower(string(entry.ExecutorKind())), entry.ExecutorName()))

Expand Down
10 changes: 6 additions & 4 deletions cmd/deploy/options.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package main

import "github.com/g2a-com/cicd/internal/object"
import (
"github.com/g2a-com/cicd/internal/component"
)

type options struct {
object.GenericObject
component.Backbone

Environment string `flag:"environment" alias:"e" help:"Name of an environment to deploy to" required:"true"`
Tag string `flag:"tag" alias:"t" help:"Tag (version) of service to deploy"`
Expand All @@ -16,8 +18,8 @@ type options struct {
ResultFile string `flag:"result-file" help:"Where to write result file"`
}

func (o options) Kind() object.Kind {
return object.OptionsKind
func (o options) Kind() component.Kind {
return component.OptionsKind
}

func (o options) PlaceholderValues() map[string]interface{} {
Expand Down
4 changes: 2 additions & 2 deletions cmd/deploy/result.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/g2a-com/cicd/internal/object"
"github.com/g2a-com/cicd/internal/component"
)

type ResultEntry struct {
Expand All @@ -14,7 +14,7 @@ type Result struct {
Releases []ResultEntry `json:"releases"`
}

func (r *Result) addReleases(service object.Object, entry object.Entry, releases []string) {
func (r *Result) addReleases(service component.Component, entry component.Entry, releases []string) {
for _, release := range releases {
r.Releases = append(r.Releases, ResultEntry{service.Name(), entry.Index(), release})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/environment.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: g2a-cli/v2.0
kind: Environment
kind: environment
name: local
deployServices:
- generic-api
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/executors.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
apiVersion: g2a-cli/v2.0
kind: Builder
kind: builder
name: custom-docker
schema:
type: object
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/project.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: g2a-cli/v2.0
kind: Project
kind: project
name: example-project
files:
- "*.yaml"
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/service.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
apiVersion: g2a-cli/v2.0
kind: Service
kind: service
name: generic-api
tags:
# Usually it's better to use tag policies like "gitSha" or "gitTag", but we
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/g2a-com/cicd
module github.com/g2a-com/kikd

go 1.17

Expand All @@ -15,9 +15,6 @@ require (
github.com/stretchr/testify v1.7.0
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
Loading