问题
I am creating image using packer. I have used 2 provisioners i.e Shell
and ansible-local
and both are working fine and installed all the required packages.
But now i need to deploy my application code too into my image which is over Gitlab. I am out of idea how we can do this. Can you please help me how we can fetch the code from Gitlab to create image using packer?
Any assistance will be appreciated.
Thanks.
回答1:
You should use ssh agent forwarding.
On the host running Packer load a ssh key that have access to git repository
ssh-add <path to private key>
.Ensure that you have
"ssh_disable_agent_forwarding": false
(default) in your packer template. See Docs: Communicator.
Now in your packer provisioning script you should be able to clone the repository over SSH with git clone git@<GitLab server>:<repo.git>
.
来源:https://stackoverflow.com/questions/53826216/how-we-can-fetch-code-from-gitlab-when-create-image-using-packer