Files
docker/action.yaml
2025-04-23 09:56:51 +08:00

106 lines
3.0 KiB
YAML

---
name: "Docker builder"
description: "Build and push container images using docker"
author: Yi-Ting Shih <ytshih@it.cs.nycu.edu.tw>
inputs:
context:
description: "The context of the build environment"
required: false
default: .
file:
description: "The file location of Dockerfile"
required: false
default: ./Dockerfile
push:
description: "Whether the container will be pushed or not"
required: false
default: true
push-registry:
description: "The registry to push to"
required: false
default: gitea.konchin.com
cache:
description: "Whether the container will be cached or not"
required: false
default: true
registry-certificate:
description: "The certificate for registry"
required: false
username:
description: "The username of the user to use when push"
required: false
password:
description: "The password of the user to use when push"
required: false
outputs:
imageid:
description: "Image Id"
value: ${{ steps.build.outputs.imageid }}
digest:
description: "Image digest"
value: ${{ steps.build.outputs.digest }}
metadata:
description: "Build result metadata"
value: ${{ steps.build.outputs.metadata }}
runs:
using: composite
steps:
- name: Checkout repository
uses: actions/checkout@v4.2.2
- name: Setup env
run: |
echo "$GITHUB_REPOSITORY"
echo "GITEA_REPO=${GITHUB_REPOSITORY}" | \
tr '[:upper:]' '[:lower:]' >> $GITHUB_ENV
- name: Setup docker qemu
uses: docker/setup-qemu-action@v3.6.0
- name: Setup Root CA
run: |
echo "${{ inputs.registry-certificate }}" | tee ca.pem
- name: Setup Docker BuildX
uses: docker/setup-buildx-action@v3.10.0
with:
buildkitd-flags: --debug
config-inline: |
[registry."${{ inputs.push-registry }}"]
ca = ["ca.pem"]
- name: Login to registry
uses: docker/login-action@v3.4.0
with:
registry: ${{ inputs.push-registry }}
username: ${{ inputs.username }}
password: ${{ inputs.password }}
- name: Setup metadata
id: meta
uses: docker/metadata-action@v5.7.0
env:
NODE_OPTIONS: --use-openssl-ca
with:
context: git
images: |
${{ inputs.push-registry }}/${{ env.GITEA_REPO }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha
- name: Build and push with docker
id: build
uses: docker/build-push-action@v6.15.0
env:
DOCKER_BUILD_SUMMARY: false
ACTIONS_RUNTIME_TOKEN: ''
with:
context: ${{ inputs.context }}
file: ${{ inputs.file }}
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type:registry,ref=${{ inputs.push-registry }}/${{ env.GITEA_REPO }}/cache
cache-to: |
type:registry,ref=${{ inputs.push-registry }}/${{ env.GITEA_REPO }}/cache