From 55e2b440e4e20823532935f89b216a1665818d1f Mon Sep 17 00:00:00 2001 From: mmahipal Date: Mon, 8 Nov 2021 11:39:47 +0530 Subject: [PATCH 1/4] Added github actions --- .github/workflows/github-actions.yml | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .github/workflows/github-actions.yml diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml new file mode 100644 index 00000000..fe14aede --- /dev/null +++ b/.github/workflows/github-actions.yml @@ -0,0 +1,57 @@ +name: Operator Image + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +env: + REGISTRY: ghcr.io + # github.repository as / + IMAGE: ${{ github.repository }} + + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Golang setup + uses: actions/setup-go@v1 + with: + go-version: 1.16 + id: go + + - name: Checkout repository + uses: actions/checkout@v2 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # extract branch name + - name: Extract branch name + if: github.event_name != 'pull_request' + run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> "$GITHUB_ENV" + + # extract branch name on pull request + - name: Extract branch name + if: github.event_name == 'pull_request' + run: echo "BRANCH_NAME=${GITHUB_HEAD_REF}" >> "$GITHUB_ENV" + + # Build and push Operator image + - name: Build and push Operator image + run: | + make generate + make manifests + IMAGE_NAME=${{ env.IMAGE }} + IMAGE_NAME=${IMAGE,,} + make docker-build IMG="${{ env.REGISTRY }}/${IMAGE_NAME}:${{ env.BRANCH_NAME }}" + docker push "${{ env.REGISTRY }}/${IMAGE_NAME}:${{ env.BRANCH_NAME }}" + docker rmi "${{ env.REGISTRY }}/${IMAGE_NAME}:${{ env.BRANCH_NAME }}" && docker system prune -f + rm -rf bin/ From 19fe1a313996ca7448e03b21a089603674e397d7 Mon Sep 17 00:00:00 2001 From: mmahipal Date: Mon, 8 Nov 2021 11:41:56 +0530 Subject: [PATCH 2/4] Changed a comment --- .github/workflows/github-actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index fe14aede..4bbc979b 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -25,7 +25,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - # Login against a Docker registry except on PR + # Login against a Docker registry # https://github.com/docker/login-action - name: Log into registry ${{ env.REGISTRY }} uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c From 36da1a88446b689750e74160bf52a2548abff06e Mon Sep 17 00:00:00 2001 From: Mahi0911 Date: Thu, 18 Nov 2021 12:23:05 +0530 Subject: [PATCH 3/4] Change image tag on merge --- .github/workflows/github-actions.yml | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 4bbc979b..ee01241a 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -10,7 +10,7 @@ env: REGISTRY: ghcr.io # github.repository as / IMAGE: ${{ github.repository }} - + TAG: latest jobs: build: @@ -34,15 +34,10 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - # extract branch name - - name: Extract branch name - if: github.event_name != 'pull_request' - run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> "$GITHUB_ENV" - - # extract branch name on pull request + # extract branch name on pull request to use as image tag - name: Extract branch name if: github.event_name == 'pull_request' - run: echo "BRANCH_NAME=${GITHUB_HEAD_REF}" >> "$GITHUB_ENV" + run: echo "TAG=${GITHUB_HEAD_REF}" >> "$GITHUB_ENV" # Build and push Operator image - name: Build and push Operator image @@ -51,7 +46,6 @@ jobs: make manifests IMAGE_NAME=${{ env.IMAGE }} IMAGE_NAME=${IMAGE,,} - make docker-build IMG="${{ env.REGISTRY }}/${IMAGE_NAME}:${{ env.BRANCH_NAME }}" - docker push "${{ env.REGISTRY }}/${IMAGE_NAME}:${{ env.BRANCH_NAME }}" - docker rmi "${{ env.REGISTRY }}/${IMAGE_NAME}:${{ env.BRANCH_NAME }}" && docker system prune -f - rm -rf bin/ + make docker-build IMG="${{ env.REGISTRY }}/${IMAGE_NAME}:${{ env.TAG }}" + make docker-push "${{ env.REGISTRY }}/${IMAGE_NAME}:${{ env.TAG }}" + From 18eb9a21c291698d759eab9e864c6e310cb5e4b8 Mon Sep 17 00:00:00 2001 From: Mahi0911 Date: Thu, 18 Nov 2021 12:33:55 +0530 Subject: [PATCH 4/4] Change image tag on merge --- .github/workflows/github-actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index ee01241a..5a57f7d7 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -47,5 +47,5 @@ jobs: IMAGE_NAME=${{ env.IMAGE }} IMAGE_NAME=${IMAGE,,} make docker-build IMG="${{ env.REGISTRY }}/${IMAGE_NAME}:${{ env.TAG }}" - make docker-push "${{ env.REGISTRY }}/${IMAGE_NAME}:${{ env.TAG }}" + make docker-push IMG="${{ env.REGISTRY }}/${IMAGE_NAME}:${{ env.TAG }}"