added action

added action so that when a containerfile is added/changed said containerfile will get built and pushed to scm
This commit is contained in:
Wyatt J. Miller 2024-05-05 19:58:20 -04:00
parent bcf02a056f
commit 5ea3a90343

39
.github/workflows/build.yml vendored Normal file
View File

@ -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 }}