53 lines
2.1 KiB
YAML
53 lines
2.1 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 with Kustomize
|
|
run: |
|
|
# Клонируем инфра-репозиторий
|
|
git clone https://${{ secrets.USER }}:${{ secrets.GITEA }}@gitea.apps.kopikopi.com.ru/examples/nginx-intrasture.git
|
|
cd nginx-intrasture/apps/static-site
|
|
|
|
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O yq
|
|
chmod +x yq
|
|
|
|
# Обновляем ТЕГ образа в deployment.yaml (не только в kustomization.yaml)
|
|
./yq eval -i '.spec.template.spec.containers[0].image = "harbor.apps.kopikopi.com.ru/drone/test:'${{ steps.vars.outputs.sha_short }}'"' deployment.yaml
|
|
# Коммитим и пушим
|
|
git config user.name "CI/CD Bot"
|
|
git config user.email "ci-cd@kopikopi.com.ru"
|
|
git add kustomization.yaml
|
|
git commit -m "Update image to ${{ steps.vars.outputs.sha_short }}"
|
|
git push |