How to auto deploying git repositories with submodules on AWS?

前端 未结 8 968
长发绾君心
长发绾君心 2021-02-04 15:02

I have a submodule in my git repository and my directory structure is like,

app
  -- folder1
  -- folder2
  -- submodule @5855

I have deployed

8条回答
  •  执念已碎
    2021-02-04 15:28

    Edit: Codebuild now has a "submodules" flag https://docs.aws.amazon.com/codebuild/latest/APIReference/API_GitSubmodulesConfig.html

    Here's what worked for me

    We're going to reinitialize the git repository and then trigger a submodule clone during the build phase of our deploy, essentially patching in support for submodules in codepipeline / codebuild

    • Generate a new SSH key for your github account, if using an organization you may want to create a deploy user
    • Store this ssh key in your aws parameter store using aws ssm put-parameter --name build_ssh_key --type String --value "$(cat id_rsa)" ideally use SecureString instead of String but the guide I was following simply used string so I'm not sure if the commandline will require any extra params
    • Go into IAM and grant your CodePipeline user read access to your paramstore, I just granted read access to SSM

    Then make your buildspec.yml look like the following:

    version: 0.2
    
    env:
      parameter-store:
        build_ssh_key: "build_ssh_key"
    
    phases:
      install:
        commands:
          - mkdir -p ~/.ssh
          - echo "$build_ssh_key" > ~/.ssh/id_rsa
          - chmod 600 ~/.ssh/id_rsa
          - ssh-keygen -F github.com || ssh-keyscan github.com >>~/.ssh/known_hosts
          - git config --global url."git@github.com:".insteadOf "https://github.com/"
          - git init
          - git remote add origin 
          - git fetch
          - git checkout -t origin/master
          - git submodule init
          - git submodule update --recursive
      build:
        commands:
          - echo '...replace with real build commands...'
    
    artifacts:
      files:
        - '**/*'
    

提交回复
热议问题