Configuring Automatic Git Mirroring

This section shows how to configure source code mirroring to FoundriesFactory® repositories. This helps to use external private or public Git repositories, hosted on services such as GitHub or Bitbucket.

This focuses on setting up GitHub Actions and Bitbucket pipelines for mirroring code, but the steps can be adapted for other Git services.

Creating Token

To allow external hosting services to access your FoundriesFactory repository, you need to create a token.

Create a new API Token by clicking on + New Token.

Complete with a Description and the Expiration date and select Next.

Check the Use for source code access box and select your Factory.


Fig. 26 Token for source code access

If Bitbucket is used, the token generated in the previous step is used as the <GIT_ACCESS_TOKEN> value.

If GitHub is used, convert the token value to a base64 string and save the output of this command. This is your <BASE64_FIO_TOKEN> value.

echo -n <FIO_TOKEN> | base64 -w0

Example Output:

host:~$ echo -n SQMD1Gx860mPI6jZFlLJLwaCXT5CqAaQi6nEfIfH | base64 -w0


<BASE64_FIO_TOKEN> should end with == with no carriage return.

Configuring GitHub Repository

Go to GitHub and find the repository you want to mirror.

Click on Settings:


Fig. 27 GitHub Settings

Click on Secrets and create a new secret by clicking on New repository secret.


Fig. 28 GitHub Secrets

The Github Action uses the variable GIT_ACCESS_TOKEN as the token to access your Foundries Factory repository.

However, complete the Name with GIT_ACCESS_TOKEN and on Value paste the <BASE64_FIO_TOKEN> provided above.

Finally, click on Add secret.


Fig. 29 GitHub New Secret

Creating Mirror Action

The FoundriesFactory CI only triggers builds for configured branches. This is configured in the ci-scripts.git repository in the factory-config.yml file.

Your factory-config.yml can be inspected by updating the following URL with your <FACTORY-NAME>:

Under lmp: and containers: the group tagging: shows the configured branches on refs/heads/<branch>:.


      - tag: main
      - tag: devel
      - tag: main
      - tag: devel

Based on the example, FoundriesFactory CI is configured to trigger new builds whenever a new commit is sent on main or devel branches. The following commands, guides you to mirror the main branch.


Notice that this example is updating the FoundriesFactory repository containers.git. The same approach can be used to update lmp-manifest.git and meta-subscriber-overrides.git.

Clone your GitHub repository and enter its directory:


Make sure to update the clone command with your repository URL.

git clone<host>/<repo_name>
cd <repo_name>

Check out the main branch.

git checkout main

In case you don’t have a master branch yet, create one:

git checkout -b main

You must store workflow files in the .github/workflows/ directory of your repository.

mkdir -p .github/workflows/

Finally, create the file mirror.yml and make sure you update the <FACTORY-NAME> with your Factory Name.

gedit .github/workflows/mirror.yml


name: Mirroring

on: [push]

    runs-on: ubuntu-20.04
      - uses: actions/checkout@v2
          fetch-depth: 0
      - uses: foundriesio/mirror-action@main
          REMOTE: "<FACTORY-NAME>/containers.git"
          GIT_ACCESS_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }}
          PUSH_ALL_REFS: "false"


PUSH_ALL_REFS is false. If true it synchronizes all branches.


Make sure you make a backup of any content in your FoundriesFactory repository that you want to preserve as this action can completely replace all branches.

Add the changed files, commit and push to your GitHub repository:

git add .github/workflows/mirror.yml
git commit -m "Adding Mirror Action"
git push

Github Action

Once the mirror.yml is in place on your GitHub repository, every change to the configured branch will start an Action on GitHub to mirror your repository to your FoundriesFactory Repository.

You can find the GitHub Action by clicking on Actions:


Fig. 30 GitHub Action

On that page, you can find the list of Actions as well as inspect each one.


Fig. 31 GitHub Action list

Your repositories from FoundriesFactory and GitHub should look the same.


Fig. 32 FoundriesFactory and GitHub

Configuring Bitbucket Repository

Go to the source repository on Bitbucket and click on Pipelines:


Fig. 33 Bitbucket Pipelines

Select the Starter pipeline:


Fig. 34 Bitbucket Starter Pipeline

Erase the default content and provide the following setup:

    - step:
       name: Mirror to
       image: alpine/git:latest
         - git push https://$<factory-name>/<repo-name>.git --all


Make sure to provide the GIT_ACCESS_TOKEN generated in Creating Token and to replace <factory-name> and <repo-name>.

Click on Commit file to enable this pipeline.

After this, every push to the Bitbucket repository mirrors all branches to and triggers builds for the branches enabled in your Factory.


This pipeline can be customized to mirror only specific branches as needed for your development.