Code Monkey home page Code Monkey logo

gitops-pr-action's Introduction

gitops-pr-action

Table of Contents

Usage

- name: Checkout
  uses: actions/checkout@v2
  with:
    # Repository name with owner. For example, actions/checkout
    # Default: ${{ github.repository }}
    repository: ''

    # Personal access token (PAT) used to fetch the repository.
    # If the repository is public, then default is fine.
    # Default: ${{ github.token }}
    token: ''

- uses: WhatTheFar/gitops-pr-action@v1-beta
  with:
    # Relative path under $GITHUB_WORKSPACE to the config template.
    #
    # Required
    configPath: ''

    # Full image URI, including a registry name, repository and tag.
    # For example, gcr.io/PROJECT-ID/my-image:tag1
    #
    # Required
    image: ''

    # Personal access token (PAT), used to open a pull request to the GitOps repository.
    #
    # We recommend using a service account with the least permissions necessary.
    # Also when generating a new PAT, select the least scopes necessary.
    #
    # [Learn more about creating personal access tokens](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token)
    # [Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
    #
    # Required
    token: ''

    # String, used to render {{ .Version }} in the config template.
    #
    # We use `gomplate` as a template engine behind the scene.
    # For more information, visits [gomplate](https://github.com/hairyhenderson/gomplate).
    #
    # Required
    version: ''

    # Object, used to render the config template.
    #
    # We use `gomplate` as a template engine behind the scene.
    # For more information, visits [gomplate](https://github.com/hairyhenderson/gomplate).
    #
    # Optional
    vars: |
      # e.g. this render {{ .Name }} to 'hello-world'
      Name: 'hello-world'

Config Template

We use gomplate cli as a template renderer behind the scene. So the config template supports full capabilities of go template engine and some addtional functionalities from gomplate.

At its most basic, gomplate can be used with environment variables. For example, the template can access $USER via {{ .Env.USER }}. For more details, please kindly visits gomplate docs.

Config reference

# Configuration management tool that your GitOps uses.
# For now, the tool supports only `kustomize`.
#
# Required
using: ''

# Options for kustomize
#
# Required if `using: kustomize` is set
kustomize:
  # Base image to be overriden by the image URI defined on gitops-pr-action.
  # Required
  baseImage: ''

  # Ralative path from config path to a directory, containing `kustomization.yaml`,
  # `kustomization.yml` or `Kustomize`.
  # Required
  directory: ''

# Use the given string as the commit message for git.
#
# Required
commitMessage: ''

# Options for opening a pull request
#
# Required
pullRequest:
  # Title of the pull request
  # Required
  title: ''

  # Branch name used to commit changes and open a pull request
  # Required
  branch: ''

  # Target branch where the pull request will merge into.
  # For example, 'main' or 'master'
  # Required
  baseBranch: ''

  # Options for requesting reviewers
  reviewers:
    # An array of user logins that will be requested.
    users:
      - ''
    # An array of team slugs that will be requested.
    teams:
      - ''

  # Usernames of people to assign this issue to.
  # NOTE: Only users with push access can add assignees to an issue. Assignees are silently ignored otherwise.
  assignees:
    - ''

# Options to configure git user
#
# Required
gitUser:
  # Used for `git config --global user.name`
  # Required
  name: GitHub Action

  # Used for `git config --global user.email`
  # Required
  email: [email protected]

Example for kustomize

File tree:

.
├── gitops.kustomize.yml
└── kustomize
    └── kustomization.yaml

gitops.kustomization.yml:

using: kustomize
kustomize:
  baseImage: gitops-pr-action/hello-world
  directory: kustomize

commitMessage: >
  feat(hello-world): hello-world image {{ .Version }}

pullRequest:
  title: Deploy hello-world {{ .Version }}
  branch: deploy/hello-world/{{ .Version }}
  baseBranch: main

gitUser:
  name: GitHub Action
  email: [email protected]

kustomize/kustomization.yaml:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

images:
  - name: gitops-pr-action/hello-world
    newName: hello-world
    newTag: latest

Scenarios

Get version from tag

Assume the project create a release using semantic versioning via tags.

on:
  push:
    tags:
      - v*
jobs:
  gitops:
    steps:
      - name: Get the version
        id: get-version
        run: echo ::set-output name=version::${GITHUB_REF#refs/tags/}

      - uses: WhatTheFar/gitops-pr-action@v1-beta
        with:
          configPath: '' # Required
          image: '' # Required
          token: '' # Required
          version: ${{ steps.get-version.outputs.version }}

Deliver image to AWS ECR

- name: Configure AWS credentials
  uses: aws-actions/configure-aws-credentials@v1
  with:
    aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
    aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    aws-region: ap-southeast-1

- name: Login to Amazon ECR
  id: login-ecr
  uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
  env:
    ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
    ECR_REPOSITORY: my-ecr-repo
    IMAGE_TAG: ${{ github.sha }}
  run: |
    docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
    docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

- name: Open a pull request to deploy new image from Amazon ECR
  uses: WhatTheFar/gitops-pr-action@v1-beta
  with:
    configPath: '' # Required
    image: ${{ steps.login-ecr.outputs.registry }}/my-ecr-repo:${{ github.sha }}
    token: '' # Required
    version: ${{ github.sha }}

gitops-pr-action's People

Contributors

whatthefar avatar

Stargazers

Chotpisit Adunsehawat avatar Suphon T. avatar Supakarin Niansupornpun avatar

Watchers

James Cloos avatar  avatar Supakarin Niansupornpun avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.