devex/.gitea/workflows/build-frontend.yml

155 lines
5.4 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: 'Build Frontend'
on:
workflow_dispatch:
inputs:
repo_path:
description: 'Репозиторий'
required: true
type: choice
options:
- devspc/devspace-selfkit-ui
default: devspc/devspace-selfkit-ui
branch:
description: 'Ветка'
required: true
type: string
default: 'feature/DEVX-182-ApiRegistry-overhaul-p2-ApiCardEdit'
version:
default: latest
description: 'Версия образа'
required: true
type: string
jobs:
deploy-dev:
name: 'Deploy to dev'
runs-on: ubuntu-latest
steps:
- name: Cloning2
uses: https://git.binom.pw/otp/devops/clone@main
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
repository: ${{ github.event.inputs.repo_path }}
branch: ${{ github.event.inputs.branch }}
- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4 # Use the setup-node action
with:
node-version: 24
cache: 'npm'
- name: Building
run: |
npm install
npm run build
cat > entrypoint.sh << EOF
#!/bin/sh
export PREFIX=${PREFIX:-devspace-ui}
echo "PREFIX: ${PREFIX}"
set -e
export PREFIX=${PREFIX:-devspace-ui}
echo "PREFIX: ${PREFIX}"
echo 'Environments:'
env
# Применяем переменные окружения к шаблону конфига
envsubst '${PREFIX}' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf
# Запускаем nginx с переданными аргументами
#exec "$@"
echo 'Result configuration:'
cat /etc/nginx/conf.d/default.conf
exec nginx -g "daemon off;"
EOF
cat > default.conf.template << EOF
server {
listen 80;
server_name localhost;
# Префикс из переменной окружения (по умолчанию devspace-ui)
set $prefix_internal ${PREFIX:-devspace-ui};
# Редирект с /$prefix_internal на /$prefix_internal/
location = /$prefix_internal {
return 301 /$prefix_internal/;
}
# Отдача статики по префиксу
location /$prefix_internal/ {
alias /usr/share/nginx/html/;
autoindex off;
try_files $uri =404;
}
# Health check (всегда 200)
location /health {
access_log off;
return 200 "OK\n";
add_header Content-Type text/plain;
}
# Все остальные пути — 404
location / {
return 404;
}
}
EOF
cat > Dockerfile << EOF
FROM nginx:stable-alpine
# Установка gettext для envsubst (уже есть в alpine, но для ясности)
RUN apk add --no-cache gettext
# Удаляем дефолтный конфиг
RUN rm /etc/nginx/conf.d/default.conf
# Создаём папку для шаблонов
WORKDIR /etc/nginx/templates
# Копируем шаблон конфигурации
COPY default.conf.template /etc/nginx/templates/default.conf.template
# Копируем entrypoint-скрипт
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Копируем статические файлы
COPY ./dist /usr/share/nginx/html
EXPOSE 80
ENTRYPOINT ["/entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]
EOF
- name: Build Docker Image
uses: https://git.binom.pw/subochev/devops/build-docker@main
with:
image_name: "otp/${{ github.event.inputs.repo_path }}"
tags: latest ${{ github.event.inputs.version }}
- name: Kuebrnetus config
run: |
echo '${{ secrets.KUBE_CONFIG }}' > ./ku.yaml
- name: "Install Helm"
uses: azure/setup-helm@v4.3.0
- name: 'Clone Helms'
uses: https://github.com/actions/checkout@v4
with:
repository: otp/devex
path: 'helms'
- name: Deploy
run: |
pathToHelm='./helms/${{ github.event.inputs.repo_path }}'
releaseName=$(basename "$pathToHelm")
echo "Release Name: $releaseName"
helm upgrade --install "$releaseName" "$pathToHelm" \
--namespace devx \
--kubeconfig ./ku.yaml \
--create-namespace \
--set-string 'image.version=${{ github.event.inputs.version }}' \
--set-string 'image.name=images.binom.pw/otp/${{ github.event.inputs.repo_path }}' \
--set-string 'repository.name=${{ github.event.inputs.repo_path }}' \
--set-string 'repository.branch=${{ github.event.inputs.branch }}' \
--set "imagePullSecrets[0].name=regcred" \
--wait
- name: 'Cleanup'
if: always()
shell: bash
run: |
echo 'Cleaning...'
rm -rf ~/.ssh/config
rm -rf ~/.ssh/my_key