16 Commits

2 changed files with 23 additions and 14 deletions

View File

@@ -11,6 +11,9 @@ on:
force_build: force_build:
type: boolean type: boolean
default: false default: false
arch:
type: string
default: "linux/amd64,linux/arm64/v8"
secrets: secrets:
VK_TEAMS_BOT_TOKEN: VK_TEAMS_BOT_TOKEN:
required: true required: true
@@ -69,9 +72,10 @@ jobs:
- name: Restore Docker layer cache - name: Restore Docker layer cache
uses: actions/cache/restore@v4 uses: actions/cache/restore@v4
with: with:
path: /cache/buildx-cache path: /cache/${{ github.repository }}/buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }} key: ${{ runner.os }}-${{ github.repository }}-buildx-${{ hashFiles(format('{0}/Dockerfile', github.workspace), format('{0}/**/requirements.txt', github.workspace), format('{0}/**/*lock*', github.workspace), format('{0}/**/package-lock.json', github.workspace), format('{0}/**/poetry.lock', github.workspace)) }}
restore-keys: | restore-keys: |
${{ runner.os }}-${{ github.repository }}-buildx-
${{ runner.os }}-buildx- ${{ runner.os }}-buildx-
- name: Build and push multi-arch image - name: Build and push multi-arch image
@@ -84,23 +88,24 @@ jobs:
tags: | tags: |
cr.yandex/${{ env.CR_REGISTRY }}/${{ env.CR_REPO }}:${{ env.SHORT_SHA }} cr.yandex/${{ env.CR_REGISTRY }}/${{ env.CR_REPO }}:${{ env.SHORT_SHA }}
cr.yandex/${{ env.CR_REGISTRY }}/${{ env.CR_REPO }}:${{ env.SAFE_TAG }} cr.yandex/${{ env.CR_REGISTRY }}/${{ env.CR_REPO }}:${{ env.SAFE_TAG }}
platforms: linux/amd64,linux/arm64/v8 platforms: ${{ inputs.arch }}
ssh: default ssh: default
no-cache: ${{ inputs.force_build }} no-cache: ${{ inputs.force_build }}
build-args: | build-args: |
GIT_COMMIT=${{ github.sha }} GIT_COMMIT=${{ github.sha }}
cache-from: | cache-from: |
type=local,src=/cache/buildx-cache type=local,src=/cache/${{ github.repository }}/buildx-cache
cache-to: | cache-to: |
type=local,dest=/cache/buildx-cache-new,mode=max type=local,dest=/cache/${{ github.repository }}/buildx-cache-new,mode=max
- name: Move new cache if it exists - name: Move new cache if it exists
if: always() if: always()
run: | run: |
if [ -d /cache/buildx-cache-new ]; then mkdir -p /cache/${{ github.repository }}
if [ -d /cache/${{ github.repository }}/buildx-cache-new ]; then
echo "Found new buildx cache, replacing old one..." echo "Found new buildx cache, replacing old one..."
rm -rf /cache/buildx-cache rm -rf /cache/${{ github.repository }}/buildx-cache
mv /cache/buildx-cache-new /cache/buildx-cache mv /cache/${{ github.repository }}/buildx-cache-new /cache/${{ github.repository }}/buildx-cache
else else
echo "No new buildx cache found, keeping old one." echo "No new buildx cache found, keeping old one."
fi fi
@@ -109,8 +114,8 @@ jobs:
if: always() if: always()
uses: actions/cache/save@v4 uses: actions/cache/save@v4
with: with:
path: /cache/buildx-cache path: /cache/${{ github.repository }}/buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }} key: ${{ runner.os }}-${{ github.repository }}-buildx-${{ hashFiles(format('{0}/Dockerfile', github.workspace), format('{0}/**/requirements.txt', github.workspace), format('{0}/**/*lock*', github.workspace), format('{0}/**/package-lock.json', github.workspace), format('{0}/**/poetry.lock', github.workspace)) }}
- name: Notify (result) - name: Notify (result)
if: always() if: always()

View File

@@ -24,7 +24,7 @@ on:
jobs: jobs:
deploy: deploy:
if: contains(format(',{0},', vars.ADMIN_USERS), format(',{0},', github.actor)) || inputs.environment=='stage' if: ${{ contains(format(',{0},', vars.ADMIN_USERS), format(',{0},', github.actor)) || startsWith(inputs.environment, 'stage') }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
CR_REGISTRY: crp8vh46gd976oq8ipla CR_REGISTRY: crp8vh46gd976oq8ipla
@@ -33,9 +33,11 @@ jobs:
steps: steps:
- name: notify - name: notify
uses: https://bb.hublab.ru/HUB/workflows/.gitea/actions/vk-notify@main uses: https://bb.hublab.ru/HUB/workflows/.gitea/actions/vk-notify@main
env:
VK_TEAMS_BOT_TOKEN: ${{ secrets.VK_TEAMS_BOT_TOKEN }}
VK_TEAMS_CHAT_ID: ${{ secrets.VK_TEAMS_CHAT_ID }}
with: with:
result: 'started' result: 'started'
secrets: ${{ toJSON(secrets) }}
name: deploy ${{ inputs.environment }} tag ${{ inputs.tag }} name: deploy ${{ inputs.environment }} tag ${{ inputs.tag }}
- name: deploy - name: deploy
id: k8s_deploy id: k8s_deploy
@@ -48,7 +50,9 @@ jobs:
- name: post-notify - name: post-notify
if: always() if: always()
uses: https://bb.hublab.ru/HUB/workflows/.gitea/actions/vk-notify@main uses: https://bb.hublab.ru/HUB/workflows/.gitea/actions/vk-notify@main
env:
VK_TEAMS_BOT_TOKEN: ${{ secrets.VK_TEAMS_BOT_TOKEN }}
VK_TEAMS_CHAT_ID: ${{ secrets.VK_TEAMS_CHAT_ID }}
with: with:
result: ${{ steps.k8s_deploy.outcome }} result: ${{ steps.k8s_deploy.outcome }}
name: k8s deploy ${{ inputs.environment }} tag ${{ inputs.tag }} name: k8s deploy ${{ inputs.environment }} tag ${{ inputs.tag }}
secrets: ${{ toJSON(secrets) }}