Skip to content

Commit

Permalink
ci: setup ci docker build and push
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelgautier committed Jun 23, 2024
1 parent 64062b3 commit 0a9054e
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
list-dockerfiles:
runs-on: ubuntu-latest

outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}

steps:
- uses: actions/checkout@v4

- id: set-matrix
run: echo "matrix=$(find . -type f -name 'Dockerfile' -exec dirname {} \; | sort -u | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT

docker-build:
needs: list-dockerfiles
runs-on: ubuntu-latest

permissions:
packages: write

strategy:
matrix:
dockerfile: ${{ fromJson(needs.list-dockerfiles.outputs.matrix) }}

steps:
- uses: actions/checkout@v4

- name: Create Docker Image name
id: create-image-name
run: echo "image=ghcr.io/emmanuelgautier/awesome-dockerfiles/$(echo ${{ matrix.dockerfile }} | awk -F'/' '{print $NF}'):latest" >> $GITHUB_OUTPUT

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

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: ${{ matrix.dockerfile }}
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{ steps.create-image-name.outputs.image }}
cache-from: type=registry,ref=${{ steps.create-image-name.outputs.image }}
cache-to: type=inline
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 0a9054e

Please sign in to comment.