CodePipeline failing - appspec file most likely my issue

0

With our server count increasing I want to add some automation with rollouts. I have code-deploy withing with a windows farm (was a while ago) however this one is for a java app on linux, so the developers will really just be commiting a new .WAR file. I would like that file to be put in a /tmp folder, then a script will follow up to undeploy the app from the running server and then deploy the new as well as move the existing WAR to a backup folder with the date/time. So locally that bash script runs fine so now I wish to automate. I have the pipeline setup and its failing on BeforeInstall event.

The appspec file is quite basic;

version: 0.0
os: linux
files:
  - source: /code.war
    destination: /tmp
    file_exists_behavior: OVERWRITE
hooks:
BeforeInstall:
    - location: /mnt/admin/scripts/cd_prepare.sh
      timeout: 30
      runas: root
  AfterInstall:
    - location: /mnt/admin/scripts/cd_p6_update.sh
      timeout: 600
      runas: root

I am getting an error;

[Aws::CodeDeployCommand::Client 200 0.019456 0 retries] put_host_command_complete(command_status:"Failed",diagnostics:{format:"JSON",payload:"{"error_code":5,"script_name":"","message":"(<unknown>): did not find expected key while parsing a block mapping at line 1 column 1\

There will always be just that one code.war file, so I simply want to stick that in /tmp, then run the script after install but was getting an error saying the location was missing (even though it was there), when I put the BeforeInstall section, that error disappeared and made it to the next, I am sure it's something simple I am missing or have wrong so any help is appreciated.

Thanks,

feita há 10 meses492 visualizações
2 Respostas
0
Resposta aceita

Notes..

Location: Required. The location in the bundle of the script file for the revision. The location of scripts you specify in the hooks section is relative to the root of the application revision bundle. For more information, see Plan a revision for CodeDeploy.

This is why your seeing the error

What you are trying to do I believe is execute a file that is already located on the file system. However, in the appspec file you are referencing files in the package relative to the package root i.e. /opt/codedeploy-agent/deployment-root/deployment-group-id/deployment-id/deployment-archive

So when you try and execute a file defined in the appspec /mnt/admin/scripts/cd_p6_update.sh what your actually executing is /opt/codedeploy-agent/deployment-root/deployment-group-id/deployment-id/deployment-archive/mnt/admin/scripts/cd_p6_update.sh

You have 2 options

  1. Copy your cd_p6_update.sh over with each deployment and execute with appspec as you are doing now. At least doing it this way you can update this script if you ever need to change it
  2. Have a script in your your package copied each time that when execute, excutes the existing file located on the machine
profile picture
ESPECIALISTA
respondido há 10 meses
  • Thanks for that update. I didn't want to have the script, etc. as the developers really just provide that single file, but I guess that is really my only option, but #2 sounds a bit more promising. So if I am understanding #2 the cd_p6_update.sh script could be put into the package, would land in /tmp and when executed had access to the filesystem, it could then say run /scripts/newscript that did everything, that would be a decent solution. The core reason is you need credentials that you can't pass in a script and must be read from a file, so I didn't want all of that in the code, so I will play a bit more, but this was a big help and appreciate the time you put in to help me understand that!

  • Your most welcome... So long as you have a script in the package to call another script already on the system that should do it.. What you could do is store that password in Parameter store or secret manager and grab the secure password each time the script ran so you dont have to worry about storing sensitive information in code yet be able to script it all..

0

As you rightly pointed out, your Yaml is incorrect.. Please try the following.. Im not a fan of Yaml :-)

Hopefully this resolves your issue. Great idea moving to codedeploy to automate the deployment.. You could explore codepipline at some point if you want to add multi steps in there like a blue/green deployment also at the same time

2 x Usefull sites to validate your YAML..

  1. https://yaml-online-parser.appspot.com/
  2. https://jsonformatter.org/yaml-parser
version: 0.0
os: linux
files:
  - source: /code.war
    destination: /tmp
    file_exists_behavior: OVERWRITE
hooks:
   BeforeInstall:
     - location: /mnt/admin/scripts/cd_prepare.sh
       timeout: 30
       runas: root
   AfterInstall:
     - location: /mnt/admin/scripts/cd_p6_update.sh
       timeout: 600
       runas: root
profile picture
ESPECIALISTA
respondido há 10 meses
  • Ah that page is excellent (now bookmarked)!

    Already have that in a code pipeline, so when there is a commit to codecommit, it will deploy using a pipeline, and it did error again, oddly telling me a script is missing; (note I didn't need the BeforeInstall) so its really just this now;

    version: 0.0 os: linux files: source: / destination: /tmp file_exists_behavior: OVERWRITE hooks: AfterInstall: location: /mnt/admin/scripts/cd_p6_update.sh timeout: 600 runas: root


    And it's failing with the error:

    /mnt/admin/scripts/cd_p6_update.sh Message Script does not exist at specified location: /opt/codedeploy-agent/deployment-root/796c9472-334e-495b-ab5a-2840f73a2c04/d-EC4M8D1LO/deployment-archive/mnt/admin/scripts/cd_p6_update.sh

    Oddly the appspec has the full path "location: /mnt/admin/scripts/cd_prepare.sh" but its looking here '/opt/codedeploy-agent/deployment-root/796c9472-334e-495b-ab5a-2840f73a2c04/d-T0QR7D1LO/deployment-archive/mnt/admin/scripts/cd_prepare.sh"

    The code.war does appear in the /tmp folder (which is 1/2 the battle), now just need to know why its trying to run the script from that location, is something wrong with that as well?

  • There’s a simple explanation to that. Will follow up shortly with an answer as I can format correctly

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas