Skip to main content

Integrate Edgegap in your CI/CD

With those examples of CI/CD pipelines, you will deploy your applications on Edgegap with a simple push!

CI/CD concepts#

Semantic versioning give your release version a "name" and convey some helpful information. Semantic versioning follows the X.Y.Z pattern. This version tag can be prefixed or suffixed with some alphanumeric characters. Example of semantic versioning:

  • MAJOR.MINOR.PATCH

    • Increasing MAJOR means adding non-backward compatible changes.
    • Increasing MINOR means backward compatible feature additions.
    • Increasing PATCH means backward compatible bug fixes.
  • YEAR.MONTH.DAY This goes pretty well when you are releasing daily.

So the goal here is to have a name for your release versions that can increase over time. You can talk about versioning with your team about which concept fits you most.

Git branching strategy is essential to make your CI/CD pipelines more manageable. You must separate your development from your production-ready application. There are multiple tutorials on managing your branches, but the easiest way to do this is to have at least two branches.

  • develop: branch in which features are developed and bugs are corrected. It should be ahead of the main branch or even when a merge is done with the main.
  • main or master: branch in which develop is merged to do a release of your newest features or bug fixes.

With Container Registry#

Using Edgegap's Container Registry service will remove the overhead of creating and managing an app version each time your image is pushed. For more information on the Container Registry service see doc.

Requirements#

  1. Get access to Edgegap's Container Registry
  2. An app template (optional and only if you want your app version to be created automatically)
  3. A Github project with admin permissions
  4. A Dockerfile located at the root of your project

Integration#

Banch names : In this example, we are using a branch named `develop` and `main`.

Setup#

This example with Github's Actions will show how you can automatically increase the MINOR of your version tag every time you merge the develop into the main branch. It will also create a new Application Version in Arbitrium if you are using Edgegap's Container registry.

  1. In your project settings on Github, under Security -> Secrets -> Action, create four Action secrets. One for each field in the Edgegap's Container Registry.
    • PROJECT The auto-generated name by Edgegap's Container Registry
    • REGISTRY URL of the registry (ex: registry.edgegap.net)
    • REGISTRY_USERNAME The username to login into the project
    • REGISTRY_TOKEN The password to login into your project

img img

  1. Create a file at the root of your project named VERSION with your version number inside and push it to Github.
0.0.1
  1. Create a file in .github/workflows/increment-minor.yml and and push it to Github. Don't forget to change IMAGE_NAME. Github will automatically detect new Actions and show them in your repository's under the Action tab.
name: Increment MINOR version, building image and pushing to the registry
on:
push:
branches: [main]
env:
REGISTRY: ${{ secrets.REGISTRY }}
PROJECT: ${{ secrets.PROJECT }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
IMAGE_NAME: unity-pong
VERSION_FILE: VERSION
VERSION_FRAGMENT: feature
jobs:
tagging:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Read VERSION file
id: current_version
run: echo "::set-output name=version::$(cat $VERSION_FILE)"
- name: Bump version
id: bump_version
uses: christian-draeger/increment-semantic-version@1.0.2
with:
current-version: ${{ steps.current_version.outputs.version }}
version-fragment: "${{ env.VERSION_FRAGMENT}}"
- name: Updating version file content
run: echo ${{ steps.bump_version.outputs.next-version }} > $VERSION_FILE
- uses: avakar/tag-and-release@v1
with:
tag_name: ${{ steps.bump_version.outputs.next-version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit and push changes
uses: devops-infra/action-commit-push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_message: Bumped new Version
building-and-pushing-image:
needs: tagging
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: develop
- name: Get current version
id: current_version
run: echo "::set-output name=version::$(cat $VERSION_FILE)"
- name: Print current version
run: cat $VERSION_FILE
- name: Build the image
run: docker build . --file Dockerfile --tag $REGISTRY/$PROJECT/$IMAGE_NAME
- name: Login to Edgegap Registry
run: docker login $REGISTRY -u $REGISTRY_USERNAME -p $REGISTRY_TOKEN
- name: Tagging the image to desired version
run: docker tag $REGISTRY/$PROJECT/$IMAGE_NAME $REGISTRY/$PROJECT/$IMAGE_NAME:${{ steps.current_version.outputs.version }}
- name: Pushing to Edgegap Registry
run: docker push $REGISTRY/$PROJECT/$IMAGE_NAME:${{ steps.current_version.outputs.version }}
- name: Tagging the image to latest
run: docker tag $REGISTRY/$PROJECT/$IMAGE_NAME $REGISTRY/$PROJECT/$IMAGE_NAME:latest
- name: Pushing latest to Edgegap Registry
run: docker push $REGISTRY/$PROJECT/$IMAGE_NAME:latest

Pipeline Environment variables#

  • REGISTRY URL of the registry (set in Action Secret)
  • PROJECT The auto-generated name by Edgegap's Registry Container (set in Action Secret)
  • REGISTRY_USERNAME The username to login into the project (set in Action Secret)
  • REGISTRY_TOKEN The password to login into your project (set in Action Secret)
  • IMAGE_NAME The name of your image, can be your project name
  • VERSION_FILE Path to the file containing your version
  • VERSION_FRAGMENT feature for a MINOR (see more here)

Tagging

To tag a new MINOR version on Github, you'll only need to create a pull request to merge develop into main. This script's first job makes a git tag each time a pull request from develop has been merged into the main branch, then updates the VERSION file to the newest tag.

Building and pushing image

The following job builds and pushes to Edgegap's Container Registry your image using your version number as the name of the image tag. This pipeline also pushes to the latest tag, but you should not use it in your production environment; see why.

Please note : This is a basic tutorial to show an end-to-end process. You will need more conditional Actions to handle MAJOR and PATCH correctly.

Triggering your pipelines#

  1. Create a new branch from develop

  2. Git Checkout on your new branch

  3. Change some code (can be updating the README)

  4. Commit and push your changes in your branch

  5. Create a pull request from your branch to develop

  6. Accept your pull request

  7. Create another pull request from develop to main (or master)

  8. Accept your second pull request

  9. See your pipeline triggering:

    The Increment MINOR version, building image and pushing to the registry Action will start. img

  10. Once completed, you should see a new repository in Edgegap Registry Dashboard with one artifact 0.1.0 img

Optional#
  1. If you didn't have an application template, create one. img
  2. Repeat 1 to 9 steps again
  3. See that everytime you are building a new tag, a new app version is created img