-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: finish deployment function + add zip functionality to adapter +…
… start building delete function
- Loading branch information
Showing
26 changed files
with
668 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package deleteprojects | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"strings" | ||
"time" | ||
|
||
"github.com/aws/aws-lambda-go/events" | ||
"github.com/megakuul/battleshiper/lib/model/project" | ||
"github.com/megakuul/battleshiper/pipeline/delete/eventcontext" | ||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
func HandleDeleteProjects(eventCtx eventcontext.Context) func(context.Context, events.CloudWatchEvent) error { | ||
return func(ctx context.Context, event events.CloudWatchEvent) error { | ||
err := runHandleDeleteProjects(event, ctx, eventCtx) | ||
if err != nil { | ||
log.Printf("ERROR DELETEPROJECTS: %v\n", err) | ||
return err | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func runHandleDeleteProjects(request events.CloudWatchEvent, transportCtx context.Context, eventCtx eventcontext.Context) error { | ||
projectCollection := eventCtx.Database.Collection(project.PROJECT_COLLECTION) | ||
|
||
projectDoc := &project.Project{} | ||
err := projectCollection.FindOneAndUpdate(transportCtx, bson.D{ | ||
{Key: "name", Value: deployClaims.Project}, | ||
{Key: "owner_id", Value: deployClaims.UserID}, | ||
}, bson.M{ | ||
// Lock the pipeline, this step is used to ensure only one deployment runs at a time. | ||
// running multiple deployments at the same time should not cause major issues, | ||
// however it can cause weird or unintended behavior for the project. | ||
"$set": bson.M{ | ||
"pipeline_lock": true, | ||
}, | ||
}).Decode(&projectDoc) | ||
if err != nil { | ||
return fmt.Errorf("failed to fetch project from database") | ||
} | ||
if projectDoc.PipelineLock { | ||
return fmt.Errorf("project locked") | ||
} | ||
|
||
// Finish build step | ||
buildResult := project.BuildResult{ | ||
ExecutionIdentifier: deployRequest.Parameters.ExecutionIdentifier, | ||
Timepoint: time.Now().Unix(), | ||
} | ||
if strings.ToUpper(deployRequest.Status) != "SUCCEEDED" { | ||
buildResult.Successful = false | ||
result, err := projectCollection.UpdateByID(transportCtx, projectDoc.MongoID, bson.M{ | ||
"$set": bson.M{ | ||
"last_build_result": buildResult, | ||
"status": fmt.Errorf("BUILD FAILED: %v", err), | ||
}, | ||
}) | ||
if err != nil && result.MatchedCount < 1 { | ||
return fmt.Errorf("failed to update project (last_build_result)") | ||
} | ||
return nil | ||
} else { | ||
buildResult.Successful = true | ||
result, err := projectCollection.UpdateByID(transportCtx, projectDoc.MongoID, bson.M{ | ||
"$set": bson.M{ | ||
"last_build_result": buildResult, | ||
}, | ||
}) | ||
if err != nil && result.MatchedCount < 1 { | ||
return fmt.Errorf("failed to update project (last_build_result)") | ||
} | ||
} | ||
|
||
// Start actual deployment step | ||
deploymentResult := project.DeploymentResult{ | ||
ExecutionIdentifier: deployRequest.Parameters.ExecutionIdentifier, | ||
} | ||
if err := deployProject(transportCtx, eventCtx, projectDoc, deployClaims.UserID, deployRequest.Parameters.ExecutionIdentifier); err != nil { | ||
deploymentResult.Timepoint = time.Now().Unix() | ||
deploymentResult.Successful = false | ||
result, err := projectCollection.UpdateByID(transportCtx, projectDoc.MongoID, bson.M{ | ||
"$set": bson.M{ | ||
"last_deployment_result": deploymentResult, | ||
"status": fmt.Errorf("DEPLOYMENT FAILED: %v", err), | ||
}, | ||
}) | ||
if err != nil && result.MatchedCount < 1 { | ||
return fmt.Errorf("failed to update project (last_deployment_result)") | ||
} | ||
return nil | ||
} else { | ||
deploymentResult.Timepoint = time.Now().Unix() | ||
deploymentResult.Successful = true | ||
result, err := projectCollection.UpdateByID(transportCtx, projectDoc.MongoID, bson.M{ | ||
"$set": bson.M{ | ||
"last_deployment_result": deploymentResult, | ||
"status": "", | ||
}, | ||
}) | ||
if err != nil && result.MatchedCount < 1 { | ||
return fmt.Errorf("failed to update project (last_deployment_result)") | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package eventcontext | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go-v2/service/cloudformation" | ||
"github.com/aws/aws-sdk-go-v2/service/cloudfrontkeyvaluestore" | ||
"github.com/aws/aws-sdk-go-v2/service/s3" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
) | ||
|
||
type BucketConfiguration struct { | ||
StaticBucketName string | ||
} | ||
|
||
type CloudfrontConfiguration struct { | ||
CacheArn string | ||
} | ||
|
||
// Context provides data to event handlers. | ||
type Context struct { | ||
Database *mongo.Database | ||
S3Client *s3.Client | ||
CloudformationClient *cloudformation.Client | ||
CloudfrontCacheClient *cloudfrontkeyvaluestore.Client | ||
BucketConfiguration *BucketConfiguration | ||
CloudfrontConfiguration *CloudfrontConfiguration | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,47 @@ | ||
module github.com/megakuul/battleshiper/pipeline/deploy | ||
module github.com/megakuul/battleshiper/pipeline/delete | ||
|
||
go 1.23.0 | ||
|
||
require ( | ||
github.com/aws/aws-lambda-go v1.47.0 | ||
github.com/aws/aws-sdk-go-v2/config v1.27.33 | ||
github.com/aws/aws-sdk-go-v2/service/cloudformation v1.53.7 | ||
github.com/aws/aws-sdk-go-v2/service/cloudfrontkeyvaluestore v1.6.6 | ||
github.com/aws/aws-sdk-go-v2/service/s3 v1.61.2 | ||
github.com/megakuul/battleshiper/lib/helper v0.1.12 | ||
github.com/megakuul/battleshiper/lib/model v0.2.5 | ||
go.mongodb.org/mongo-driver v1.16.1 | ||
) | ||
|
||
require ( | ||
github.com/aws/aws-sdk-go-v2 v1.30.5 // indirect | ||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4 // indirect | ||
github.com/aws/aws-sdk-go-v2/credentials v1.17.32 // indirect | ||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.13 // indirect | ||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17 // indirect | ||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17 // indirect | ||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect | ||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.17 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.39.0 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.4 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.19 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.19 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.17 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.32.8 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/sso v1.22.7 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.7 // indirect | ||
github.com/aws/aws-sdk-go-v2/service/sts v1.30.7 // indirect | ||
github.com/aws/smithy-go v1.20.4 // indirect | ||
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect | ||
github.com/golang/snappy v0.0.4 // indirect | ||
github.com/jmespath/go-jmespath v0.4.0 // indirect | ||
github.com/klauspost/compress v1.17.9 // indirect | ||
github.com/montanaflynn/stats v0.7.1 // indirect | ||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect | ||
github.com/xdg-go/scram v1.1.2 // indirect | ||
github.com/xdg-go/stringprep v1.0.4 // indirect | ||
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect | ||
golang.org/x/crypto v0.27.0 // indirect | ||
golang.org/x/sync v0.8.0 // indirect | ||
golang.org/x/text v0.18.0 // indirect | ||
) |
Oops, something went wrong.