name: Docker Build and Publish on: push: paths: - "**/Containerfile" jobs: build_and_publish: name: Build and Publish Docker Image runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v2 - name: Get Dockerfile image name id: get_image_name run: | IMAGE_NAME=$(grep -Po '(?<=name=")[^"]*' Containerfile) echo "::set-output name=image_name::$IMAGE_NAME" - name: Login to container registry run: docker login -u ${{ secrets.REGISTRY_USERNAME }} -p ${{ secrets.REGISTRY_PASSWORD }} scm.wyattjmiller.com - name: Check for Dockerfile changes id: dockerfile_changed run: | if git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '^Containerfile$'; then echo "::set-output name=changed::true" else echo "::set-output name=changed::false" fi - name: Build and Publish Docker image if: steps.dockerfile_changed.outputs.changed == 'true' run: | docker build -t scm.wyattjmiller.com/${{ steps.get_image_name.outputs.image_name }}:${{ github.sha }} . docker push scm.wyattjmiller.com/${{ steps.get_image_name.outputs.image_name }}:${{ github.sha }}