-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (102 loc) · 3.14 KB
/
buildah.yml
File metadata and controls
113 lines (102 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
---
name: buildah
on:
push:
branches:
- main
paths:
- '*/**'
- '!.github/**'
pull_request:
paths:
- '*/**'
- '!.github/**'
workflow_dispatch:
inputs:
mode:
description: 'Run mode'
type: choice
options:
- build & push
- build
default: build & push
image:
description: 'Image to build (leave empty for all)'
required: false
permissions:
contents: read
packages: write
jobs:
detect:
runs-on: ubuntu-latest
outputs:
images: ${{ steps.find.outputs.images }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Find changed images
id: find
env:
INPUT_IMAGE: ${{ inputs.image }}
run: |
if [ -n "$INPUT_IMAGE" ]; then
# Specific image requested
echo "images=[\"$INPUT_IMAGE\"]" >> "$GITHUB_OUTPUT"
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
# Manual trigger without specific image: build all
echo "images=$(make list-images-json)" >> "$GITHUB_OUTPUT"
else
# Push event: only build changed images
echo "images=$(make changed-images)" >> "$GITHUB_OUTPUT"
fi
build:
name: ${{ inputs.mode || 'build & push' }}
needs: detect
if: needs.detect.outputs.images != '[]'
runs-on: ubuntu-latest
strategy:
matrix:
image: ${{ fromJson(needs.detect.outputs.images) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install buildah, podman, and hadolint
run: |
sudo apt-get update
sudo apt-get install -y buildah podman
mkdir -p $HOME/.local/bin
curl -sSL -o $HOME/.local/bin/hadolint \
https://github.com/hadolint/hadolint/releases/download/v2.12.0/hadolint-Linux-x86_64
chmod +x $HOME/.local/bin/hadolint
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Run pre-commit
uses: pre-commit/action@v3.0.1
env:
SKIP: no-commit-to-branch
- name: Build image
uses: redhat-actions/buildah-build@v2
with:
context: ${{ matrix.image }}
containerfiles: ${{ matrix.image }}/Containerfile
image: ${{ matrix.image }}
tags: latest ${{ github.sha }}
extra-args: --squash
- name: Push to registry
# Auto-deploy on push to main; for workflow_dispatch the user picks
# "build & push" to publish or "build" to dry-run.
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && inputs.mode == 'build & push')
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ matrix.image }}
tags: latest ${{ github.sha }}
registry: ghcr.io/makeitworkcloud
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}