Skip to content

Commit

Permalink
Move reusable workflow and everest-clang-format from everest-utils to…
Browse files Browse the repository at this point in the history
… everest-ci (#16)

* Add reusable worklfow deploy-single-docker-image

Signed-off-by: Andreas Heinrich <[email protected]>

* move reusable workflow

Signed-off-by: Andreas Heinrich <[email protected]>

* Rename deploy build-kit workflow

Signed-off-by: Andreas Heinrich <[email protected]>

* Add everest-clang-format image

Signed-off-by: Andreas Heinrich <[email protected]>

* Pin version of docker image

Signed-off-by: Andreas Heinrich <[email protected]>

---------

Signed-off-by: Andreas Heinrich <[email protected]>
  • Loading branch information
andistorm authored Apr 25, 2024
1 parent ea4a417 commit 2cfebc1
Show file tree
Hide file tree
Showing 6 changed files with 601 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build-kit docker image
name: Deploy build-kit docker image

on:
workflow_dispatch:
Expand All @@ -17,8 +17,8 @@ on:
default: 'latest'

jobs:
main:
name: Build and push
deploy-build-kit-image:
name: Build and push build-kit docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/deploy-docker-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build and push docker images

on:
workflow_dispatch:
inputs:
force_rebuild:
description: 'Force rebuild of all images'
default: false
type: boolean
push:
branches:
- '**'
tags:
- 'v*'

env:
REGISTRY: ghcr.io

jobs:
build-and-push-all-images:
name: Build and push all docker images
strategy:
matrix:
image_name: [everest-clang-format]
uses: everest/everest-ci/.github/workflows/[email protected]
with:
force_rebuild: ${{ inputs.force_rebuild || (github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/' )) || false }}
image_name: ${{ matrix.image_name }}
docker_directory: docker/images/
docker_registry: ghcr.io
github_ref_before: ${{ github.event.before }}
github_ref_after: ${{ github.event.after }}
secrets:
SA_GITHUB_PAT: ${{ secrets.SA_GITHUB_PAT }}
SA_GITHUB_USERNAME: ${{ secrets.SA_GITHUB_USERNAME }}
113 changes: 113 additions & 0 deletions .github/workflows/deploy-single-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Build and push single docker image

on:
workflow_call:
inputs:
image_name:
description: 'Name of the image to build and push'
required: true
type: string
docker_directory:
description: 'Directory containing the docker directory'
required: true
type: string
default: docker/
docker_registry:
description: 'Docker registry to push to'
required: true
default: 'ghcr.io'
type: string
github_ref_before:
description: 'Github ref before the change'
required: true
type: string
github_ref_after:
description: 'Github ref after the change'
required: true
type: string
force_rebuild:
description: 'Forces rebuild of docker image, even if no changes are detected'
default: false
type: boolean
secrets:
SA_GITHUB_PAT:
description: 'Github PAT with access to the repository'
required: true
SA_GITHUB_USERNAME:
description: 'Github username'
required: true

jobs:
check:
name: Check for changes
outputs:
changed_files: ${{ steps.changed-files.outputs.changed_files }}
runs-on: ubuntu-22.04
steps:
- name: Checkout Dockerfile
uses: actions/checkout@v3
with:
repository: ${{ github.repository }}
path: source
ref: ${{ inputs.github_ref_after }}
token: ${{secrets.SA_GITHUB_PAT}}
fetch-depth: 0
- name: Get changed files
id: changed-files
run: |
echo "changed_files=$(git diff --name-only ${{ inputs.github_ref_before }} ${{ inputs.github_ref_after }} | grep "^${{inputs.docker_directory}}/${{inputs.image_name}}" | wc -l)" >> $GITHUB_OUTPUT
working-directory: source

build-and-push:
name: Build and push
needs: check
if: ${{ needs.check.outputs.changed_files > 0 || inputs.force_rebuild }}
runs-on: ubuntu-22.04
steps:
- name: Checkout Dockerfile
uses: actions/checkout@v3
with:
repository: ${{ github.repository }}
path: source
ref: ${{github.ref}}
token: ${{secrets.SA_GITHUB_PAT}}
fetch-depth: 0
- name: Get context / Path of Dockerfile
id: get-context
run: |
if [ -f source/${{ inputs.docker_directory }}/${{ inputs.image_name }}/Dockerfile ]; then
echo "::set-output name=path::source/${{ inputs.docker_directory }}/${{ inputs.image_name }}/"
elif [ -f source/${{ inputs.docker_directory }}/${{ inputs.image_name }}/.devcontainer/Dockerfile ]; then
echo "::set-output name=path::source/${{ inputs.docker_directory }}/${{ inputs.image_name }}/.devcontainer/"
else
echo "No Dockerfile found for image ${{ inputs.image_name }}!"
exit 1
fi
- name: Extract metadata
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ inputs.docker_registry }}/${{ github.repository_owner }}/${{ inputs.image_name }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
image: tonistiigi/binfmt:latest
platforms: all
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
registry: ${{ inputs.docker_registry }}
username: ${{ secrets.SA_GITHUB_USERNAME }}
password: ${{ secrets.SA_GITHUB_PAT }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: ${{ steps.get-context.outputs.path }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
cache-from: type=gha
cache-to: type=gha,mode=max
15 changes: 15 additions & 0 deletions docker/images/everest-clang-format/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ARG BASE_IMAGE=debian:12
FROM ${BASE_IMAGE}

RUN apt update && apt upgrade -y
RUN apt update && \
apt install -y \
clang-format-15=1:15.0.6*
RUN ln -s /usr/bin/clang-format-15 /usr/bin/clang-format

RUN apt install -y \
python-is-python3

COPY run-clang-format.py /usr/bin/run-clang-format

ENTRYPOINT ["/usr/bin/run-clang-format"]
Loading

0 comments on commit 2cfebc1

Please sign in to comment.