如何在AWS上使用子模块自动部署git存储库? [英] How to auto deploying git repositories with submodules on AWS?
问题描述
我的git信息库中有一个子模块,并且我的目录结构是
I have a submodule in my git repository and my directory structure is like,
app
-- folder1
-- folder2
-- submodule @5855
我已通过使用自动部署服务将代码部署在AWS上.现在,在服务器上,我在父目录中有代码,但是子模块目录为空.
I have deployed my code on AWS by using autodeploy service. Now, on server I have code in the parent-directory but submodule directories are empty.
Q1)如何获取子模块中的数据.我在服务器上的存储库不是git存储库.我是否需要先将其转换为git repo,然后运行 submodule
命令来获取它?
Q1) How can I get data in submodules. My repository on server is not git repository. Do I need to convert it firstly into git repo and then run submodule
commands to get it ?
Q2)我如何也可以自动化子模块部署?
Q2) How can I automate the submodule deployment as well?
谢谢
推荐答案
Codebuild现在具有"submodules"标记 https://docs.aws.amazon.com/codebuild/latest/APIReference/API_GitSubmodulesConfig.html
Codebuild now has a "submodules" flag https://docs.aws.amazon.com/codebuild/latest/APIReference/API_GitSubmodulesConfig.html
这是对我有用的
我们将重新初始化git存储库,然后在部署的构建阶段触发子模块克隆,从本质上打补丁以支持codepipeline/codebuild中的子模块
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
- 为您的github帐户生成一个新的SSH密钥,如果使用组织,您可能要创建一个部署用户
- 使用
aws ssm put-parameter --name build_ssh_key --type String --value"$(cat id_rsa)"
将此ssh密钥存储在aws参数存储中理想情况下,请使用SecureString而不是字符串,但是我遵循的指南仅使用了字符串,因此我不确定命令行是否需要任何额外的参数 - 进入IAM并授予您的CodePipeline用户对您的paramstore的读取权限,而我刚刚授予对SSM的读取权限
- 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
然后使您的buildspec.yml如下所示:
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 <Your Repo url here using the git protocol>
- git fetch
- git checkout -t origin/master
- git submodule init
- git submodule update --recursive
build:
commands:
- echo '...replace with real build commands...'
artifacts:
files:
- '**/*'
这篇关于如何在AWS上使用子模块自动部署git存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!