.git files, submodules, and ssh keys

Hi @jason10 we have a couple of questions regarding your workflow.

  • Are you doing git push ... to send your code, or using the CLI such as balena push ...?
  • The private repository is that your code is somewhere else stored as private repository, such as a GitHub or GitLab private repo?

The git submodule update --init --recursive is indeed the right thing to to update the submodules, but when you are doing the docker build, the .git information is not available, it’s not built in a docker context, as you found out.

The next thing you do, is it pulling the same repository in the docker build that you are pushing to? In general we do not recommend pulling from the git repos that you have pushed to balena-cloud, I don’t think that’s really something you want to do.

For private repos in general, I think you would have to have some authentication as part of the docker build steps, for example adding an SSH key that git can use to pull with, or adding the https credentials (username/password) of a repo, if that’s applicable, but depends on what you tell us, where’s your private repo that you are pulling the submodules from.

Also, in general submodules are not supported in the project that you are pushing, but of course you can do that in your build steps. See one of our earlier answers about submodules in general:

For mor advice, it would be good if you can tell more about your project structure! Can you give more info on that?

So far what I’ve seen, our advice would be:

  • use a separate repo that has the submodules, compared to your balena deployment
  • the balena project in the pull step clones that other repo, and updates the submodules with credentials added

Alternatively, you can do local builds and then your balena deployment can use submodules (see balena build and balena deploy of the CLI). In that case all the build happens on your computer, with all the stuff checked out (thus you would initialize the submodules before running the build) and only the final containers are pushed. Not sure if that’s a viable aternative for you.

I know this is a lot of information, let us know if anything is unclear, and I’m checking with the team, if I’ve missed any options for you, especially if you can elaborate on the questions above. Thanks!