I'm trying to build docker image using github actions and it's triggered if a tagged commit happens and if a push or pull request on staging & main branches. I'm using also kustomize to customize the legacy manifest depending on the commit. But i have an issue every time i tried to tag a commit to trigger the pipeline, it fails at the part of committing the kustomize.yaml with this error
Run ad-m/github-push-action@master
Push to branch refs/tags/v0.3.8
To https://github.com/ahmedappout08/robo-demo.git
! [rejected] HEAD -> v0.3.8 (already exists)
error: failed to push some refs to 'https://github.com/ahmedappout08/robo-demo.git'
hint: Updates were rejected because the tag already exists in the remote.
Error: Invalid exit code: 1
at ChildProcess.<anonymous> (/home/runner/work/_actions/ad-m/github-push-action/master/start.js:29:21)
at ChildProcess.emit (events.js:210:5)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
code: 1
}
Error: Invalid exit code: 1
at ChildProcess.<anonymous> (/home/runner/work/_actions/ad-m/github-push-action/master/start.js:29:21)
at ChildProcess.emit (events.js:210:5)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
And here's the Ci.yaml file:
name: Docker
on:
push:
branches:
- main
- staging
tags:
- v*
pull_request:
branches:
- main
- staging
env:
# TODO: Change variable to your image's name.
IMAGE_NAME: robo-demo
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
runs-on: ubuntu-latest
steps:
- name: Checkout master
uses: actions/checkout@main
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
- name: Push image tag
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging' }} == false
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
#VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
VERSION=$GITHUB_SHA
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
echo IMAGE_ID=$IMAGE_ID
#echo VERSION=${GITHUB_REF##*/}
echo VERSION=$GITHUB_SHA
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
- name: push image main & staging
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging' }}
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
echo IMAGE_ID=$IMAGE_ID
echo VERSION=${GITHUB_REF##*/}
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
- name: congrats
run: |
echo "Image Built on Branch" ${GITHUB_REF##*/}
- name: Setup Kustomize
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging' }} == false
uses: imranismail/setup-kustomize@v1
with:
kustomize-version: "3.6.1"
- name: Update Kubernetes resources
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging' }} == false
run: |
cd k8s-deployment/feature-version
kustomize edit set image robo-image=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME:$GITHUB_SHA
cat kustomization.yaml
- name: Commit files
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging' }} == false
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git commit -am "Bump docker tag"
- name: Push changes
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging' }} == false
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
I don't how to fix that to push the commit to the branch itself connected to the tag as i need to update the kustomize.yaml there after each building