Ivan C Myrvold
Ivan C Myrvold

Reputation: 840

CDK pipelines with several application repositories

I have successful setup a pipeline for my application with CDK Pipelines construct that was introduced this summer. The application is a microservice (UserService) compiled with CodeBuild and creates a ECS Fargate service. The source of the application is in a GitHub repository. The project stored in GitHub repository is like this:

.
+-- cdk
+-- Dockerfile_OrderService
+-- Dockerfile_ProductService
+-- Dockerfile_UserService
+-- OrderService
+-- ProductService
+-- UserService

OrderService, ProductService and UserService are folders containing source code of the microservices that needs to be compiled with CodeBuild. I have only implemented UserService so far, and that works fine. When I push a change from the UserService folder, the pipeline is triggered, and the source code are built with CodeBuild, and the service is deployed to ECS Fargate.

When I set up a pipeline for the other two services, a push from any of the services folders will trigger CodePipeline for all three services. I don't want that, I want the pipeline for the specific service is triggered, not the other two, but I am not sure how to do that.

I was thinking about each service to have it's own repository, but I also need the infrastructure code under cdk to be present.

Do anyone have an example of how to do this?

Upvotes: 1

Views: 1495

Answers (1)

nsquires
nsquires

Reputation: 1119

My team uses a monorepo with different cdk-pipelines for each product/service that we offer. It does trigger each pipeline when we push to the develop branch, but if there are no changes in 'ProductService' or 'OrderService' then technically I don't think there's no harm letting it update all of them.

But if you do want separate triggers, you would have to use separate branches that trigger each microservice. You are allowed to specify a branch for 'GitHubSourceActionProps.Branch'. For example, the pipeline construct for 'UserService' could look like this: (C#)

        var pipeline = new Amazon.CDK.Pipelines.CdkPipeline(this, "My-Cdk-Pipeline", new CdkPipelineProps()
        {
            SourceAction = new GitHubSourceAction(new GitHubSourceActionProps()
            {
                ActionName = "GitHubSourceAction",
                Branch = user-service,
                Repo = "my-cool-repo",
                Trigger = GitHubTrigger.WEBHOOK,
            }),                                                                      
        };

aws cdk api reference githubsourceactionprops

Upvotes: 0

Related Questions