Search code examples
amazon-web-servicesmsbuildbitbucketaws-code-deploy

How do I configure my appspec.yml file to deploy an application rather than a single page?


I'm working through the AWS blog post on how to deploy code directly from BitBucket using AWS CodeDeploy. Most of it's fairly straightforward until I get to the point where it mentions an appspec.yml file. I understand that the purpose is to describe what to deploy and how to do it, but I'm not understanding how to do that for an application, rather than just a simple page. In my previous experience there would be a series of steps such as

  1. Pull from Repo
  2. Run MSBuild against X project.
  3. Run Tests against X project.
  4. Copy build artifacts to S3.
  5. Stop App Pool on web server.
  6. Run cmd file deploying build artifacts.
  7. Start App Pool on web server.
  8. Cleanup/Post Build steps.

I assume that there's some correlation between the steps I've written above and the "files" and "hooks" sections in the appspec.yml file detailed here. Unfortunately I can't figure out a mapping in my head between the two, and every blog post, online doc, and video I've found pretty much just says "you need this file" and points to an example that moves one static file and has one or two hooks. I'm at a loss as to how to integrate the actual build portions of the deployment.

Can anyone either provide an example appspec.yml file which accounts for a full application deployment, rather than a simple copy paste, or point me towards a resource which better explains this process?


Solution

  • CodeDeploy is for deploying a built application. Builds and anything beforehand need to be managed separately. Your zip file you pass to codedeploy should be the built application plus an appspec describing installation.

    Below is an appspec for a .NET application of mine.

    version: 0.0
    os: windows
    files:
      - source: /
        destination: C:\inetpub\wwwroot
    hooks:
       BeforeInstall:
         - location: CodeDeploy/appstop.bat       
           runas: administrator
       ApplicationStart:
         - location: CodeDeploy/appstart.bat       
           runas: administrator
    

    With regards to codedeploy, my process is this:

    1. Check code into Github,
    2. Github sends webhook to Jenkins
    3. Jenkins uses MS Build to run tests/build the code.
    4. Jenkins zips up the build artifact (the built solution) and uploads to S3
    5. Jenkins triggers a codedeploy deployment with the s3 zip file.
    6. Code deploy reads the appspec in the zip and extracts the contents accordingly.
    7. Lifecycle hooks are exectuted at the appropriate times. In my case, for starting and stopping IIS, and safely removing instances from an ELB.