Skip to content

Commit

Permalink
Merge pull request #4 from synapsestudios/2/add-github-actions-for-de…
Browse files Browse the repository at this point in the history
…ployment-to-ghcr

2/add GitHub actions for deployment to ghcr
  • Loading branch information
dragonfleas authored Feb 27, 2024
2 parents 17453e8 + b723151 commit 4d2ccc1
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "docker"
directory: "images/meat-runner-22.04/"
schedule:
interval: "daily"
25 changes: 25 additions & 0 deletions .github/workflows/create_matrix.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
- id: set-matrix
run: |
echo "matrix=$(ls -d ${{ inputs.image_directory }}/* | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
43 changes: 43 additions & 0 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]

- 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 }}
50 changes: 50 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]

- 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
File renamed without changes.

0 comments on commit 4d2ccc1

Please sign in to comment.