81 lines
2.5 KiB
YAML
81 lines
2.5 KiB
YAML
name: Reusable Build and Push
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
path:
|
|
description: "The path of the Containerfile, eg. main"
|
|
required: true
|
|
type: string
|
|
runner:
|
|
description: "Runner, use when need ARM64 runner"
|
|
required: false
|
|
type: string
|
|
default: lxc
|
|
push_to_ghcr:
|
|
description: "Push to ghcr.io"
|
|
required: false
|
|
type: boolean
|
|
default: true
|
|
tag:
|
|
description: Only one line
|
|
required: true
|
|
type: string
|
|
default: ""
|
|
extra_tags:
|
|
description: |
|
|
"Extra Tags, ONE TAG ONE LINE, ex:
|
|
type=raw,value=test
|
|
type=raw,value=py311
|
|
type=raw,value=py311-{{date 'YYYYMMDD'}}
|
|
"
|
|
required: false
|
|
type: string
|
|
default: ""
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ${{ inputs.runner }}
|
|
|
|
steps:
|
|
- name: Check out the repository
|
|
uses: https://git.xlion.tw/actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
|
|
- name: Install Podman and buildah
|
|
run: |
|
|
apt-get update
|
|
apt-get install -y podman buildah
|
|
|
|
- name: Extract metadata for Docker
|
|
id: meta
|
|
uses: https://git.xlion.tw/gh-mirror/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
|
|
with:
|
|
images: git.xlion.tw/${{ github.repository }}
|
|
flavor: |
|
|
latest=false
|
|
tags: |
|
|
type=raw,value=${{ inputs.tag }}-{{date 'YYYYMMDD'}},enable={{is_default_branch}}
|
|
type=raw,value=${{ inputs.tag }},enable={{is_default_branch}}
|
|
type=ref,event=pr,suffix=-${{ inputs.tag }}
|
|
${{ inputs.extra_tags }}
|
|
|
|
- name: Buildah Action
|
|
id: build-image
|
|
uses: https://git.xlion.tw/gh-mirror/buildah-build@061ffd31bb5c3f8733a6f9bbdf00a9fb02eb708c
|
|
with:
|
|
context: ${{ inputs.path }}
|
|
containerfiles: ${{ inputs.path }}/Containerfile
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
oci: true
|
|
|
|
- name: Push
|
|
id: push
|
|
uses: https://git.xlion.tw/gh-mirror/push-to-registry@5ed88d269cf581ea9ef6dd6806d01562096bee9c # v2.8
|
|
if: ${{ inputs.push_to_ghcr == true }}
|
|
with:
|
|
image: ${{ steps.build-image.outputs.image }}
|
|
tags: ${{ steps.build-image.outputs.tags }}
|
|
registry: git.xlion.tw
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.PUSH_TOKEN }}
|
|
extra-args: |
|
|
--compression-format=zstd
|