fix: XMIXDEVOPS-1290 updating Image artifacts to DEV ACR (#12)

Adding Docker push to Dev ACR
This commit is contained in:
tanujbhatia1708 2022-09-16 19:30:24 +05:30 committed by GitHub
parent 059d8e678f
commit 45c7f75d06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 59 additions and 0 deletions

View File

@ -6,6 +6,7 @@ on:
tags:
- '*' # matches every tag that doesn't contain a '/'
jobs:
build_and_push_image:
runs-on: self-hosted
@ -64,3 +65,61 @@ jobs:
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
build_and_push_acrimage:
runs-on: self-hosted
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Prepare
id: prep
run: |
ACR_REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}')
ACR_REGISTRY_PATH="${{ secrets.DEVACR_URL }}/docker/base-images/${ACR_REPOSITORY_NAME}"
VERSION=edge
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${ACR_REGISTRY_PATH}:${VERSION}"
# TODO: Refine... was creating too many hashes
# if [ "${{ github.event_name }}" = "push" ]; then
# TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
# fi
# if we pushed a tag, we also want publish a new latest image
if [[ $GITHUB_REF == refs/tags/* ]]; then
TAGS="$TAGS,${ACR_REGISTRY_PATH}:latest"
fi
echo "TAGS to build and push are ${TAGS}"
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to ACR Docker
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ${{ secrets.DEVACR_URL }}
username: ${{ secrets.XMIX_DEVACR_USERNAME }}
password: ${{ secrets.XMIX_DEVACR_PASSWORD }}
-
name: Build and push to acr
uses: docker/build-push-action@v2
with:
build-args: VERSION=${{ steps.prep.outputs.version }}
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}