Skip to content

Commit a481ed8

Browse files
authored
Merge pull request #146 from Clever/INFRANG-6712
[INFRANG-6712] Call catalogue sync service from goci
2 parents ae4fe3b + f7f7d94 commit a481ed8

File tree

4 files changed

+43
-20
lines changed

4 files changed

+43
-20
lines changed

internal/catapult/catapult.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/Clever/circle-ci-integrations/gen-go/client"
1313
"github.com/Clever/circle-ci-integrations/gen-go/models"
1414
"github.com/Clever/wag/logging/wagclientlogger"
15+
16+
"golang.org/x/sync/errgroup"
1517
)
1618

1719
// Artifact aliases a catapult models.CatapultApplication, and contains
@@ -44,21 +46,36 @@ func New() *Catapult {
4446

4547
// Publish a list of build artifacts to catapult.
4648
func (c *Catapult) Publish(ctx context.Context, artifacts []*Artifact) error {
49+
grp, grpCtx := errgroup.WithContext(ctx)
50+
4751
for _, art := range artifacts {
48-
fmt.Println("Publishing", art.ID)
49-
err := c.client.PostCatapultV2(ctx, &models.CatapultPublishRequest{
50-
Username: environment.CircleUser,
51-
Reponame: environment.Repo,
52-
Buildnum: environment.CircleBuildNum,
53-
App: art,
52+
grp.Go(func() error {
53+
fmt.Println("Publishing", art.ID)
54+
err := c.client.PostCatapultV2(grpCtx, &models.CatapultPublishRequest{
55+
Username: environment.CircleUser,
56+
Reponame: environment.Repo,
57+
Buildnum: environment.CircleBuildNum,
58+
App: art,
59+
})
60+
if err != nil {
61+
return fmt.Errorf("failed to publish %s with catapult: %v", art.ID, err)
62+
}
63+
64+
err = c.client.SyncCatalogApp(grpCtx, &models.SyncCatalogAppInput{
65+
App: art.ID,
66+
})
67+
if err != nil {
68+
return fmt.Errorf("failed to sync catalog app %s with catalogue config: %v", art.ID, err)
69+
}
70+
return nil
5471
})
55-
if err != nil {
56-
return fmt.Errorf("failed to publish %s with catapult: %v", art.ID, err)
57-
}
5872
}
59-
return nil
73+
return grp.Wait()
6074
}
6175

76+
// Deploy a list of apps via catapult. Note that it is only possible to
77+
// deploy to production, even if you pass an env param to
78+
// circle-ci-integrations, which seems to ignore the param.
6279
func (c *Catapult) Deploy(ctx context.Context, apps []string) error {
6380
for _, app := range apps {
6481
fmt.Println("Deploying", app)

internal/docker/targets.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@ import (
99
"github.com/Clever/ci-scripts/internal/repo"
1010
)
1111

12+
// DockerTarget contains information about how to build and push a
13+
// docker build target.
1214
type DockerTarget struct {
1315
// Tags are the list of tags to push for the built docker image.
1416
Tags []string
1517
// Command is the command to run to build the lambda artifact.
1618
Command string
1719
}
1820

19-
// BuildTargets returns a map of dockerfile path keys with their
20-
// associated tags for pushing to a remote repository. If multiple apps
21-
// share a repository then only the first matching Dockerfile and its
22-
// set of tags will be in the final list. This is an optimization so we
23-
// do not build multiple copies of the same Dockerfile which only differ
24-
// at runtime.
21+
// BuildTargets returns a map of dockerfile path keys with their build
22+
// command and associated tags for pushing to a remote repository. If
23+
// multiple apps share a repository then only the first matching
24+
// Dockerfile and its set of tags will be in the final list. This is an
25+
// optimization so we do not build multiple copies of the same
26+
// Dockerfile which only differ at runtime.
2527
func BuildTargets(apps map[string]*models.LaunchConfig) (map[string]DockerTarget, []*catapult.Artifact) {
2628
var (
2729
targets = map[string]DockerTarget{}

internal/lambda/targets.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ type LambdaTarget struct {
2222

2323
// BuildTargets returns a set of lambda targets to build and publish to
2424
// S3 as well as a list of artifacts to be published to catapult. The
25-
// targets map has the artifact name as the key and the already built
26-
// local zip location as the value. Any apps with a shared artifact
27-
// will have only one entry in the map, but will still have individual
28-
// entries in the catapult build artifacts
25+
// targets map has the artifact name as the key and a build command and
26+
// destination zip file in the value struct. Any apps with a shared
27+
// artifact will have only one entry in the map, but will still have
28+
// individual entries in the catapult build artifacts
2929
func BuildTargets(apps map[string]*models.LaunchConfig) (map[string]LambdaTarget, []*catapult.Artifact) {
3030
var (
3131
targets = map[string]LambdaTarget{}

internal/repo/repo.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,17 @@ func ArtifactName(appName string, lc *models.LaunchConfig) string {
120120
return artifactName
121121
}
122122

123+
// BuildCommand returns the build command for the application artifact,
124+
// if any is specified. Otherwise it returns an empty string.
123125
func BuildCommand(lc *models.LaunchConfig) string {
124126
if lc.Build == nil || lc.Build.Artifact == nil {
125127
return ""
126128
}
127129
return lc.Build.Artifact.Command
128130
}
129131

132+
// ExecBuild runs the build command for the application artifact, if any
133+
// exists. If the command is empty, it returns nil after performing nop.
130134
func ExecBuild(c string) error {
131135
if c == "" {
132136
return nil

0 commit comments

Comments
 (0)