#Help me write a github workflow!

1 messages · Page 1 of 1 (latest)

remote hazel
#

Hi, I need to write a matrix github workflow which will find a Dockerfile and spawn a job for each one, build it and then deploy to ghcr, how do i properly set it?

muted wagonBOT
#

<@&987246964494204979> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#
TJ-Bot
Hi, I need to write a matrix github workflow which will find a Dockerfile and spawn a job for each one, build it and then deploy to ghcr, how do i properly set it?

Sure! Here's a sample GitHub workflow YAML file that achieves what you're looking for:

name: Docker Build and Deploy

on:
  push:
    paths:
      - 'Dockerfile'

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        dockerfile: [ 'Dockerfile' ]
    
    steps:
      - name: Check out code
        uses: actions/checkout@v2

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1

      - name: Login to ghcr
        run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
      
      - name: Build and push Docker image
        run: |
          docker buildx build --platform linux/amd64,linux/arm64 -t ghcr.io/${{ github.repository }}/my-image:${{ github.run_number }} .
          docker push ghcr.io/${{ github.repository }}/my-image:${{ github.run_number }}

This workflow will trigger on a push event that includes changes to a Dockerfile, set up the necessary tools for building the Docker image, login to GitHub Container Registry (ghcr), build the Docker image with different platforms using Buildx, and finally push the built image to ghcr. You can customize it further based on your specific requirements. Let me know if you need more help!

spare shuttle
#

Hey, could you please specify what exactly you mean with 'which will find a Dockerfile'? Do you want to run separate workflows for each found Dockerfile in a push, or repository, or something like that? thinkies