Codepipeline: Deploy only specific files to s3

不打扰是莪最后的温柔 提交于 2020-06-29 03:21:21

问题


I am having trouble with AWS Codepipeline, rather than deploying the entire GitHub repo to an S3 bucket, I would like Codepipeline to only deploy a single file.

Edit: I am using AWS CodeBuild, my deployment yaml file is this

version: 0.2
phases:
  install: 
    runtime-versions:
      nodejs: 8
    commands:
      - npm i npm@latest -g
      - pip install --upgrade pip
      - pip install --upgrade awscli
  pre_build:
    commands:
      - npm install redoc-cli -g
  build:
    commands:
      - redoc-cli bundle ./orchestra/api/api.yml
artifacts:
  files:
    - redoc-static.html

回答1:


You are almost there. You are already exporting just that "one" file (redoc-static.html) that needs to be deployed to S3 from the CodeBuild project (artifacts section of buildspec). Now in your CodePipeline, in the CodeBuild stage, name a new 'Output artifact' for the action, then make sure in the Deploy stage (Deploy to S3) to use this Output Artifact from the Build stage which will include just the one file (build artifact) from the CodeBuild stage.




回答2:


This would be a complete CodePipeline snippet to use in CodeFormation to deploy the content listed as artifacts: / files: into an existing S3 Bucket passed into the template parameter named S3Bucket. Optionally, the "Source" stage here is pulling from a linked GitHub repo. Note that ArtifactBucket is a different "ephemeral" one used by the CodePipeline as an intermediary during the process

  Pipeline:
    Type: AWS::CodePipeline::Pipeline
    Properties:
      RoleArn: !GetAtt CodePipelineServiceRole.Arn
      ArtifactStore:
        Type: S3
        Location: !Ref ArtifactBucket
      Stages:
        - Name: Source
          Actions:
            - Name: App
              ActionTypeId:
                Category: Source
                Owner: ThirdParty
                Version: 1
                Provider: GitHub
              Configuration:
                Owner: !Ref GitHubRepoOwner
                Repo: !Ref GitHubRepo
                Branch: !Ref GitHubBranch
                OAuthToken: !Ref GitHubToken
              OutputArtifacts:
                - Name: App
              RunOrder: 1
        - Name: Build
          Actions:
            - Name: Build
              ActionTypeId:
                Category: Build
                Owner: AWS
                Version: 1
                Provider: CodeBuild
              Configuration:
                ProjectName: !Ref CodeBuildProject
              InputArtifacts:
                - Name: App
              OutputArtifacts:
                - Name: BuildOutput
              RunOrder: 1 
        - Name: Deploy
          Actions:
            - Name: Deploy
              ActionTypeId:
                Category: Deploy
                Owner: AWS
                Version: 1
                Provider: S3
              Configuration:
                BucketName: !Ref S3Bucket
                Extract: true
              InputArtifacts:
                - Name: BuildOutput
              RunOrder: 1


来源:https://stackoverflow.com/questions/58418164/codepipeline-deploy-only-specific-files-to-s3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!