109 lines
3.0 KiB
YAML
109 lines
3.0 KiB
YAML
on:
|
|
workflow_call:
|
|
inputs:
|
|
lfs:
|
|
type: boolean
|
|
default: false
|
|
tag:
|
|
type: string
|
|
required: false
|
|
default: latest
|
|
force_build:
|
|
type: boolean
|
|
default: false
|
|
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: gpu
|
|
env:
|
|
CR_REGISTRY: crp8vh46gd976oq8ipla
|
|
CR_REPO: ${{ github.event.repository.name }}
|
|
IMAGE_TAG: ${{ github.sha }}
|
|
steps:
|
|
- name: notify
|
|
uses: https://bb.hublab.ru/HUB/workflows/.gitea/actions/notify@HEAD
|
|
with:
|
|
result: 'started'
|
|
name: build tag ${{ inputs.tag }}
|
|
secrets: ${{ toJSON(secrets) }}
|
|
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
lfs: ${{ inputs.lfs }}
|
|
|
|
- name: Use ssh key
|
|
uses: webfactory/ssh-agent@v0.9.0
|
|
with:
|
|
ssh-private-key: |
|
|
${{ secrets.LIB_SSH_KEY }}
|
|
${{ secrets.LIB_NEW_SSH_KEY }}
|
|
|
|
- name: Yandex Cloud Login
|
|
uses: yc-actions/yc-cr-login@v2
|
|
with:
|
|
yc-sa-json-credentials: ${{ secrets.YC_SA_JSON_CREDENTIALS }}
|
|
|
|
- name: Set up Docker Buildx
|
|
id: buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
with:
|
|
install: true
|
|
|
|
- name: Shorten commit SHA
|
|
run: echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV
|
|
|
|
- name: Normalize tag
|
|
id: normalize
|
|
run: |
|
|
SAFE_TAG=$(echo "${{ inputs.tag }}" | tr '/' '-')
|
|
echo "SAFE_TAG=$SAFE_TAG" >> $GITHUB_ENV
|
|
|
|
- name: Restore Docker layer cache
|
|
uses: actions/cache/restore@v4
|
|
with:
|
|
path: /cache/buildx-cache
|
|
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
|
restore-keys: |
|
|
${{ runner.os }}-buildx-
|
|
|
|
- name: Build and push multi-arch image
|
|
id: build-step
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
push: true
|
|
context: .
|
|
builder: ${{ steps.buildx.outputs.name }}
|
|
tags: |
|
|
cr.yandex/${{ env.CR_REGISTRY }}/${{ env.CR_REPO }}:${{ env.SHORT_SHA }}
|
|
cr.yandex/${{ env.CR_REGISTRY }}/${{ env.CR_REPO }}:${{ env.SAFE_TAG }}
|
|
platforms: linux/amd64,linux/arm64/v8
|
|
ssh: default
|
|
no-cache: ${{ inputs.force_build }}
|
|
build-args: |
|
|
GIT_COMMIT=${{ github.sha }}
|
|
cache-from: |
|
|
type=local,src=/cache/buildx-cache
|
|
cache-to: |
|
|
type=local,dest=/cache/buildx-cache-new,mode=max
|
|
|
|
- name: Move new cache
|
|
if: always()
|
|
run: |
|
|
rm -rf /cache/buildx-cache
|
|
mv /cache/buildx-cache-new /cache/buildx-cache
|
|
|
|
- name: Save Docker layer cache
|
|
if: always()
|
|
uses: actions/cache/save@v4
|
|
with:
|
|
path: /cache/buildx-cache
|
|
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
|
|
|
- name: post-notify
|
|
if: always()
|
|
uses: https://bb.hublab.ru/HUB/workflows/.gitea/actions/notify@HEAD
|
|
with:
|
|
result: ${{ steps.build-step.outcome }}
|
|
name: build tag ${{ inputs.tag }}
|
|
secrets: ${{ toJSON(secrets) }} |