name: Build and Push Docker Image on: push: branches: [ main, dev ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 env: GIT_SSL_NO_VERIFY: true - name: Login to Registry uses: docker/login-action@v2 with: registry: ${{ vars.REGISTRY_HOST }} username: ${{ secrets.REGISTRY_USER }} password: ${{ secrets.REGISTRY_PASSWORD }} - name: Build Docker Image env: BRANCH_NAME: ${{ github.ref_name }} SHORT_HASH: ${{ github.sha }} run: | # Build the image with the commit hash tag docker build --build-arg BUILD_IDENTIFIER=${SHORT_HASH:0:5} -t ${{ vars.REGISTRY_HOST }}/${GITHUB_REPOSITORY}:${BRANCH_NAME}-${SHORT_HASH:0:5} . # Tag the same image as "latest" docker tag ${{ vars.REGISTRY_HOST }}/${GITHUB_REPOSITORY}:${BRANCH_NAME}-${SHORT_HASH:0:5} ${{ vars.REGISTRY_HOST }}/${GITHUB_REPOSITORY}:${BRANCH_NAME}-latest - name: Push Docker Images env: BRANCH_NAME: ${{ github.ref_name }} SHORT_HASH: ${{ github.sha }} run: | docker push ${{ vars.REGISTRY_HOST }}/${GITHUB_REPOSITORY}:${BRANCH_NAME}-${SHORT_HASH:0:5} docker push ${{ vars.REGISTRY_HOST }}/${GITHUB_REPOSITORY}:${BRANCH_NAME}-latest - name: Log out from registry if: always() run: docker logout ${{ vars.REGISTRY_HOST }}