diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..92a195a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,39 @@ +name: Docker Build and Publish + +on: + push: + paths: + - "**/Dockerfile" + +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=")[^"]*' Dockerfile) + 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 '^Dockerfile$'; 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 }}