All checks were successful
Build with Kaniko and Deploy / build-and-deploy (push) Successful in 14s
59 lines
2.2 KiB
YAML
59 lines
2.2 KiB
YAML
name: Build with Kaniko and Deploy
|
|
|
|
on: [push]
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0 # Получаем полную историю для корректного хеша
|
|
|
|
- name: Get commit SHA (full)
|
|
id: vars
|
|
run: |
|
|
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
|
|
echo "sha_full=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build and push with Kaniko
|
|
uses: aevea/action-kaniko@master
|
|
with:
|
|
registry: harbor.apps.kopikopi.com.ru
|
|
username: ${{ secrets.HARBOR_USERNAME }}
|
|
password: ${{ secrets.HARBOR_PASSWORD }}
|
|
image: drone/test
|
|
tag: ${{ steps.vars.outputs.sha_short }} # Только короткий хеш
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
cache: true
|
|
cache-repo: harbor.apps.kopikopi.com.ru/proxy/cache
|
|
extra-args: |
|
|
--label "org.label-schema.vcs-ref=${{ steps.vars.outputs.sha_full }}"
|
|
--label "org.label-schema.build-date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
|
|
|
|
- name: Update infrastructure repository
|
|
run: |
|
|
# Клонируем инфра-репозиторий
|
|
git clone https://${{ secrets.USER }}:${{ secrets.GITEA }}@git.apps.kopikopi.com.ru/examples/nginx-infra.git
|
|
cd nginx-infra/apps/static-site
|
|
|
|
# Простое решение: используем sed для изменения deployment.yaml
|
|
NEW_IMAGE="harbor.apps.kopikopi.com.ru/drone/test:${{ steps.vars.outputs.sha_short }}"
|
|
|
|
# Обновляем deployment.yaml
|
|
sed -i "s|image:.*drone/test:.*|image: $NEW_IMAGE|g" deployment.yaml
|
|
|
|
# Проверяем изменение
|
|
echo "Updated deployment.yaml:"
|
|
grep image deployment.yaml
|
|
|
|
# Коммитим изменения
|
|
git config user.name "CI/CD Bot"
|
|
git config user.email "ci-cd@kopikopi.com.ru"
|
|
git add deployment.yaml
|
|
git commit -m "Update image to ${{ steps.vars.outputs.sha_short }}"
|
|
git push
|