Adicionar um arquivo de especificações de aplicativo a uma revisão para o CodeDeploy - AWS CodeDeploy

Adicionar um arquivo de especificações de aplicativo a uma revisão para o CodeDeploy

Este tópico mostra como adicionar um arquivo AppSpec à sua implantação. Também inclui modelos para criar um arquivo AppSpec para uma implantação no AWS Lambda e EC2/On-Premises.

Adicionar um arquivo AppSpec para uma implantação no Amazon ECS

Para uma implantação em uma plataforma de computação do Amazon ECS:

  • O arquivo AppSpec especifica a definição de tarefa do Amazon ECS usada para a implantação, um nome de contêiner e o mapeamento de porta usado para rotear o tráfego e funções do Lambda opcionais executadas após os eventos de ciclo de vida de implantação.

  • Uma revisão é o mesmo que um arquivo AppSpec.

  • Um arquivo AppSpec pode ser escrito usando JSON ou YAML.

  • Um arquivo AppSpec pode ser salvo como um arquivo de texto ou inserido diretamente em um console quando você cria uma implantação. Para obter mais informações, consulte Criar uma implantação da plataforma de computação do Amazon ECS (console).

Criar um arquivo AppSpec

  1. Copie o modelo JSON ou YAML em um editor de texto ou no editor de AppSpec no console.

  2. Modifique o template conforme necessário.

  3. Use um validador JSON ou YAML para validar seu arquivo AppSpec. Se você usar o editor de AppSpec, o arquivo é validado quando você escolher Criar implantação.

  4. Se você usar um editor de texto, salve o arquivo. Se você usar a AWS CLI para criar sua implantação, faça referência ao arquivo AppSpec se ele estiver em seu disco rígido ou um bucket do Amazon S3. Se você usar o console, é necessário enviar seu o arquivo AppSpec para o Amazon S3.

Modelo de arquivo AppSpec em YAML para uma implantação do Amazon ECS com instruções

O seguinte é um modelo YAML de um arquivo AppSpec para uma implantação do Amazon ECS com todas as opções disponíveis. Para obter informações sobre os eventos de ciclo de vida que serão usados na seção hooks, consulte A seção “hooks” AppSpec para uma implantação Amazon ECS.

# This is an appspec.yml template file for use with an Amazon ECS deployment in CodeDeploy. # The lines in this template that start with the hashtag are # comments that can be safely left in the file or # ignored. # For help completing this file, see the "AppSpec File Reference" in the # "CodeDeploy User Guide" at # https://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html version: 0.0 # In the Resources section, you must specify the following: the Amazon ECS service, task definition name, # and the name and port of the load balancer to route traffic, # target version, and (optional) the current version of your AWS Lambda function. Resources: - TargetService: Type: AWS::ECS::Service Properties: TaskDefinition: "" # Specify the ARN of your task definition (arn:aws:ecs:region:account-id:task-definition/task-definition-family-name:task-definition-revision-number) LoadBalancerInfo: ContainerName: "" # Specify the name of your Amazon ECS application's container ContainerPort: "" # Specify the port for your container where traffic reroutes # Optional properties PlatformVersion: "" # Specify the version of your Amazon ECS Service NetworkConfiguration: AwsvpcConfiguration: Subnets: ["",""] # Specify one or more comma-separated subnets in your Amazon ECS service SecurityGroups: ["",""] # Specify one or more comma-separated security groups in your Amazon ECS service AssignPublicIp: "" # Specify "ENABLED" or "DISABLED" # (Optional) In the Hooks section, specify a validation Lambda function to run during # a lifecycle event. Hooks: # Hooks for Amazon ECS deployments are: - BeforeInstall: "" # Specify a Lambda function name or ARN - AfterInstall: "" # Specify a Lambda function name or ARN - AfterAllowTestTraffic: "" # Specify a Lambda function name or ARN - BeforeAllowTraffic: "" # Specify a Lambda function name or ARN - AfterAllowTraffic: "" # Specify a Lambda function name or ARN

Arquivo AppSpec em JSON para um modelo de implantação do Amazon ECS

O seguinte é um modelo JSON para um arquivo AppSpec para uma implantação do Amazon ECS com todas as opções disponíveis. Para obter instruções do modelo, consulte os comentários na versão YAML da seção anterior. Para obter informações sobre os eventos de ciclo de vida que serão usados na seção hooks, consulte A seção “hooks” AppSpec para uma implantação Amazon ECS.

{ "version": 0.0, "Resources": [ { "TargetService": { "Type": "AWS::ECS::Service", "Properties": { "TaskDefinition": "", "LoadBalancerInfo": { "ContainerName": "", "ContainerPort": }, "PlatformVersion": "", "NetworkConfiguration": { "AwsvpcConfiguration": { "Subnets": [ "", "" ], "SecurityGroups": [ "", "" ], "AssignPublicIp": "" } } } } } ], "Hooks": [ { "BeforeInstall": "" }, { "AfterInstall": "" }, { "AfterAllowTestTraffic": "" }, { "BeforeAllowTraffic": "" }, { "AfterAllowTraffic": "" } ] }

Adicionar um arquivo AppSpec para uma implantação do AWS Lambda

Para uma implantação em uma plataforma de computação do AWS Lambda:

  • O arquivo AppSpec contém instruções sobre as funções do Lambda que serão implantadas e usadas para validação da implantação.

  • Uma revisão é o mesmo que um arquivo AppSpec.

  • Um arquivo AppSpec pode ser escrito usando JSON ou YAML.

  • Um arquivo AppSpec pode ser salvo como um arquivo de texto ou digitado diretamente em um editor de AppSpec do console durante a criação de uma implantação. Para obter mais informações, consulte Crie uma implantação de Plataforma de Computação do AWS Lambda (console).

Criar um arquivo AppSpec:

  1. Copie o modelo JSON ou YAML em um editor de texto ou no editor de AppSpec no console.

  2. Modifique o template conforme necessário.

  3. Use um validador JSON ou YAML para validar seu arquivo AppSpec. Se você usar o editor de AppSpec, o arquivo é validado quando você escolher Criar implantação.

  4. Se você usar um editor de texto, salve o arquivo. Se você usar a AWS CLI para criar sua implantação, faça referência ao arquivo AppSpec se ele estiver em seu disco rígido ou um bucket do Amazon S3. Se você usar o console, é necessário enviar seu o arquivo AppSpec para o Amazon S3.

Modelo de arquivo AppSpec em YAML para uma implantação do AWS Lambda com instruções

Para obter informações sobre os eventos de ciclo de vida utilizados na seção "Hooks", consulte A seção “hooks” AppSpec para uma implantação AWS Lambda.

# This is an appspec.yml template file for use with an AWS Lambda deployment in CodeDeploy. # The lines in this template starting with the hashtag symbol are # instructional comments and can be safely left in the file or # ignored. # For help completing this file, see the "AppSpec File Reference" in the # "CodeDeploy User Guide" at # https://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html version: 0.0 # In the Resources section specify the name, alias, # target version, and (optional) the current version of your AWS Lambda function. Resources: - MyFunction: # Replace "MyFunction" with the name of your Lambda function Type: AWS::Lambda::Function Properties: Name: "" # Specify the name of your Lambda function Alias: "" # Specify the alias for your Lambda function CurrentVersion: "" # Specify the current version of your Lambda function TargetVersion: "" # Specify the version of your Lambda function to deploy # (Optional) In the Hooks section, specify a validation Lambda function to run during # a lifecycle event. Replace "LifeCycleEvent" with BeforeAllowTraffic # or AfterAllowTraffic. Hooks: - LifeCycleEvent: "" # Specify a Lambda validation function between double-quotes.

Arquivo AppSpec em JSON para um modelo de implantação do AWS Lambda

No modelo a seguir, substitua “MyFunction” pelo nome de sua função do AWS Lambda. Na seção opcional "Hooks", substitua os eventos de ciclo de vida por "BeforeAllowTraffic" ou "AfterAllowTraffic".

Para obter informações sobre os eventos de ciclo de vida utilizados na seção "Hooks", consulte A seção “hooks” AppSpec para uma implantação AWS Lambda.

{ "version": 0.0, "Resources": [{ "MyFunction": { "Type": "AWS::Lambda::Function", "Properties": { "Name": "", "Alias": "", "CurrentVersion": "", "TargetVersion": "" } } }], "Hooks": [{ "LifeCycleEvent": "" } ] }

Adicionar um arquivo AppSpec para uma implantação do EC2/On-Premises

Sem um arquivo AppSpec, o CodeDeploy não pode mapear os arquivos de origem na sua revisão do aplicativo para os respectivos destinos ou executar scripts de sua implantação em uma plataforma de computação do EC2/On-Premises.

Cada revisão deve conter somente um arquivo AppSpec.

Para adicionar um arquivo AppSpec a uma revisão:

  1. Copie o template para um editor de texto.

  2. Modifique o template conforme necessário.

  3. Use um validador YAML para verificar a validade do seu arquivo AppSpec.

  4. Salve o arquivo como appspec.yml no diretório raiz da revisão.

  5. Execute um dos comandos a seguir para verificar se você inseriu seu arquivo AppSpec no diretório raiz:

    • Para Linux, macOS ou Unix:

      find /path/to/root/directory -name appspec.yml

      Não haverá saída se o arquivo AppSpec não for encontrado lá.

    • Para Windows:

      dir path\to\root\directory\appspec.yml

      O erro Arquivo não encontrado será exibido se o arquivo AppSpec não estiver armazenado lá.

  6. Envie a revisão para o Amazon S3 ou o GitHub.

    Para instruções, consulte Enviar uma revisão para CodeDeploy ao Amazon S3 (somente implantações do EC2/On-Premises).

Modelo de arquivo AppSpec para uma implantação do EC2/On-Premises com instruções

nota

As implantações em instâncias do Windows Server não oferecem suporte ao elemento runas. Se você estiver implantando em instâncias do Windows Server, não o inclua em seu arquivo AppSpec.

# This is an appspec.yml template file for use with an EC2/On-Premises deployment in CodeDeploy. # The lines in this template starting with the hashtag symbol are # instructional comments and can be safely left in the file or # ignored. # For help completing this file, see the "AppSpec File Reference" in the # "CodeDeploy User Guide" at # https://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html version: 0.0 # Specify "os: linux" if this revision targets Amazon Linux, # Red Hat Enterprise Linux (RHEL), or Ubuntu Server # instances. # Specify "os: windows" if this revision targets Windows Server instances. # (You cannot specify both "os: linux" and "os: windows".) os: linux # os: windows # During the Install deployment lifecycle event (which occurs between the # BeforeInstall and AfterInstall events), copy the specified files # in "source" starting from the root of the revision's file bundle # to "destination" on the Amazon EC2 instance. # Specify multiple "source" and "destination" pairs if you want to copy # from multiple sources or to multiple destinations. # If you are not copying any files to the Amazon EC2 instance, then remove the # "files" section altogether. A blank or incomplete "files" section # may cause associated deployments to fail. files: - source: destination: - source: destination: # For deployments to Amazon Linux, Ubuntu Server, or RHEL instances, # you can specify a "permissions" # section here that describes special permissions to apply to the files # in the "files" section as they are being copied over to # the Amazon EC2 instance. # For more information, see the documentation. # If you are deploying to Windows Server instances, # then remove the # "permissions" section altogether. A blank or incomplete "permissions" # section may cause associated deployments to fail. permissions: - object: pattern: except: owner: group: mode: acls: - context: user: type: range: type: - # If you are not running any commands on the Amazon EC2 instance, then remove # the "hooks" section altogether. A blank or incomplete "hooks" section # may cause associated deployments to fail. hooks: # For each deployment lifecycle event, specify multiple "location" entries # if you want to run multiple scripts during that event. # You can specify "timeout" as the number of seconds to wait until failing the deployment # if the specified scripts do not run within the specified time limit for the # specified event. For example, 900 seconds is 15 minutes. If not specified, # the default is 1800 seconds (30 minutes). # Note that the maximum amount of time that all scripts must finish executing # for each individual deployment lifecycle event is 3600 seconds (1 hour). # Otherwise, the deployment will stop and CodeDeploy will consider the deployment # to have failed to the Amazon EC2 instance. Make sure that the total number of seconds # that are specified in "timeout" for all scripts in each individual deployment # lifecycle event does not exceed a combined 3600 seconds (1 hour). # For deployments to Amazon Linux, Ubuntu Server, or RHEL instances, # you can specify "runas" in an event to # run as the specified user. For more information, see the documentation. # If you are deploying to Windows Server instances, # remove "runas" altogether. # If you do not want to run any commands during a particular deployment # lifecycle event, remove that event declaration altogether. Blank or # incomplete event declarations may cause associated deployments to fail. # During the ApplicationStop deployment lifecycle event, run the commands # in the script specified in "location" starting from the root of the # revision's file bundle. ApplicationStop: - location: timeout: runas: - location: timeout: runas: # During the BeforeInstall deployment lifecycle event, run the commands # in the script specified in "location". BeforeInstall: - location: timeout: runas: - location: timeout: runas: # During the AfterInstall deployment lifecycle event, run the commands # in the script specified in "location". AfterInstall: - location: timeout: runas: - location: timeout: runas: # During the ApplicationStart deployment lifecycle event, run the commands # in the script specified in "location". ApplicationStart: - location: timeout: runas: - location: timeout: runas: # During the ValidateService deployment lifecycle event, run the commands # in the script specified in "location". ValidateService: - location: timeout: runas: - location: timeout: runas: