Configuring Automatic Git Mirroring

This section shows how to configure a GitHub Action for mirroring your commits to the FoundriesFactory repository.

This is very useful when you want to use an external private or public git repository such as GitHub.

This section can be adapted for other git repository hosting services.

Creating Token

To allow GitHub to access your FoundriesFactory repository, you need to create a token.

Go to Tokens and create a new Api Token by clicking on + New Token.

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

For GitHub, check the Use for source code access box and select your Factory.

../../_images/mirror-action.png

Fig. 85 Token for source code access

Convert the token value to a base64 string:

echo -n <FIO_TOKEN> | base64 -w0

Example Output:

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

Save the output of this command to your copy buffer. This is your <BASE64_FIO_TOKEN> value.

Note

Your value should end with == and the output won’t have a carriage return added.

Configuring GitHub Repository

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

Click on Settings:

../../_images/mirror-action-github-setting.png

Fig. 86 GitHub Settings

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

../../_images/mirror-action-github-secrets.png

Fig. 87 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.

../../_images/mirror-action-github-new-secret.png

Fig. 88 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>:.

Example:

lmp:
  tagging:
    refs/heads/master:
      - tag: master
    refs/heads/devel:
      - tag: devel
...
containers:
  tagging:
    refs/heads/master:
      - tag: master
    refs/heads/devel:
      - tag: devel
...

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

Note

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:

Note

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

git clone https://github.com/<host>/<repo_name>
cd <repo_name>

Check out the master branch.

git checkout master

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

git checkout -b master

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

.github/workflows/mirror.yml:

name: Mirroring

on: [push]

jobs:
  to_foundries:
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - uses: foundriesio/mirror-action@master
        with:
          REMOTE: "https://source.foundries.io/factories/<FACTORY-NAME>/containers.git"
          GIT_ACCESS_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }}
          PUSH_ALL_REFS: "false"

Warning

PUSH_ALL_REFS is false. If true it synchronizes all branches.

Warning

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:

../../_images/mirror-action-github-action.png

Fig. 89 GitHub Action

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

../../_images/mirror-action-github-action-list.png

Fig. 90 GitHub Action list

Your repositories from FoundriesFactory and GitHub should look the same.

../../_images/mirror-action-github-compare.png

Fig. 91 FoundriesFactory and GitHub