diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..9cd2ca3 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "docker" + directory: "images/meat-runner-22.04/" + schedule: + interval: "daily" diff --git a/.github/workflows/create_matrix.yml b/.github/workflows/create_matrix.yml new file mode 100644 index 0000000..5e29957 --- /dev/null +++ b/.github/workflows/create_matrix.yml @@ -0,0 +1,25 @@ +name: Create Matrix + +on: + workflow_call: + inputs: + image_directory: + description: "Directory that contains image directories e.g. images/image1, images/image2, ..." + required: true + type: string + outputs: + matrix: + description: "Matrix of image directories" + value: ${{ jobs.create_matrix.outputs.matrix }} + +jobs: + create_matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - name: Checkout code + uses: actions/checkout@v4.1.1 + - id: set-matrix + run: | + echo "matrix=$(ls -d ${{ inputs.image_directory }}/* | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml new file mode 100644 index 0000000..1d84ecc --- /dev/null +++ b/.github/workflows/merge.yml @@ -0,0 +1,43 @@ +name: Merge to Main CI + +on: + push: + branches: + - main + +jobs: + create_matrix: + uses: ./.github/workflows/create_matrix.yml + with: + image_directory: "./images" + + build-and-push: + runs-on: ubuntu-latest + needs: create_matrix + strategy: + matrix: + image_folder: ${{fromJson(needs.create_matrix.outputs.matrix)}} + steps: + - name: Checkout code + uses: actions/checkout@v4.1.1 + + - name: Set Image Name output + run: echo "image_name=$(python3 -c "print('${{ matrix.image_folder }}'.split('/')[-1])")" >> $GITHUB_OUTPUT + id: set_image_name + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: ${{ matrix.image_folder }}/. + push: true + tags: ghcr.io/${{ github.repository_owner }}/${{ steps.set_image_name.outputs }}:${{ github.sha }} diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..d492228 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,50 @@ +name: PR Build + +on: + pull_request: + branches: + - main + +jobs: + create_matrix: + uses: ./.github/workflows/create_matrix.yml + with: + image_directory: "./images" + + build: + runs-on: ubuntu-latest + needs: create_matrix + strategy: + matrix: + image_folder: ${{fromJson(needs.create_matrix.outputs.matrix)}} + + services: + registry: + image: registry:2 + ports: + - 5000:5000 + + steps: + - name: Checkout code + uses: actions/checkout@v4.1.1 + + - name: Set Image Name output + run: echo "image_name=$(python3 -c "print('${{ matrix.image_folder }}'.split('/')[-1])")" >> $GITHUB_OUTPUT + id: set_image_name + + - name: Set up Docker + uses: docker/setup-buildx-action@v3 + with: + driver-opts: network=host + + - name: Build and push to GHA + uses: docker/build-push-action@v5 + with: + context: ${{ matrix.image_folder }}/. + push: true + tags: localhost:5000/${{ steps.set_image_name.outputs.image_name }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Check build status + run: docker run --rm localhost:5000/${{ steps.set_image_name.outputs.image_name }}:latest diff --git a/meat-runner-22.04/dockerfile b/images/meat-runner-22.04/dockerfile similarity index 100% rename from meat-runner-22.04/dockerfile rename to images/meat-runner-22.04/dockerfile