3

We have an app with web and worker nodes - the code for both is in the same git but gets deployed to different autoscaling groups. The problem is that there is only one appspec file, however the deployment scripts (AfterInstall, AppStart, etc.) for the web/worker nodes are different. How would I go about setting my CodeDeploy to deploy both apps and execute different deployment scripts ?

  • (Right now we have an appspec file that just invokes chef recipes that execute different actions based on the role of the node)

5 Answers 5

6

I know this question is very old, but I had the same question/issue recently and found an easy way to make it work.

I have added two appspec files on the same git: appspec-staging.yml, appspec-storybook.yml.

Also added two buildspec files buildspec-staging.yml, buildspec-storybook.yml(AWS CodeBuild allows specify the buildspec file).

The idea is after the build is done, we will copy and rename the specific appspec-xx.yml file to the final appspec.yml file, so finally, in the stage of CodeDeploy, we will have a proper appspec.yml file to deploy. Below command is for linux environment.

   post_build:
    commands:
      - mv appspec-staging.yml appspec.yml
Sign up to request clarification or add additional context in comments.

1 Comment

It worked for me! The best answer, in my opinion.
2

You can make use of environment variables exposed by the agent in your deployment scripts to identify which deployment group is being deployed. Here's how you can use them https://blogs.aws.amazon.com/application-management/post/Tx1PX2XMPLYPULD/Using-CodeDeploy-Environment-Variables

Thanks, Surya.

Comments

1

Update - according to an Amazon technical support representative it is not possible. They recommend having separate gits for different environments (prod,staging,dev,etc.) and different apps. Makes it harder to share code, but probably doable.

Comments

0

The way I have got around this is to have an appspec.yml.web and an appspec.yml.worker in the root of the project. I then have two jobs in Jenkins; one each that correspond to the worker and the web deployments. In each, it renames the appropriate one to be just appspec.yml and does the bundling to send to codedeploy.

Comments

0

Although this is old question, I am recently encounter the same issue in AWS codepipeline. The work around for me after attempts is at codebuild stage, output an artifacts with your desired appspec.yml in the root dir of this artifacts. To elaborate more, in my use case, i have a folder contains my appspec.yml and others, in my buildspec.yml,

artifacts:
  files:
    - 'parent_folder_of_appspec_file/*'
  discard-paths: yes

you may also include other necessary files together in this artifacts. Then you shall use this artifacts output from codebuild stage as the source of codedeploy stage.

Lastly, you shall build separate codepipelines for different appspec.yml files in the same branch.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.