Best practices for getting code into a container (git clone vs. copy vs. data container)

What if we want go pull code from a private repo and build this code at go build time .
To goal this,i have do some tries.
1.Do RUN ADD /root/.ssh/id_rsa /root/.ssh/id_rsa
2.Use shell script in Docker file,the script do-ssh.sh is:

eval "$(ssh-agent)" && ssh-agent -s
chmod 0600 /root/.ssh/id_rsa
ssh-add /root/.ssh/id_rsa
git clone git@103.6.128.106:fw/product.git -b new

then, RUN do-ssh.sh
id_rsa` was add into agent,but it still do not work