ajustes
This commit is contained in:
parent
a8e7868c7a
commit
7543805b40
1 changed files with 95 additions and 50 deletions
|
|
@ -1,50 +1,95 @@
|
||||||
apiVersion: apps/v1
|
name: Deploy Backend and Backoffice Dev
|
||||||
kind: Deployment
|
|
||||||
metadata:
|
on:
|
||||||
name: gohorse-backoffice-dev
|
workflow_dispatch:
|
||||||
namespace: gohorsejobsdev
|
push:
|
||||||
spec:
|
branches:
|
||||||
replicas: 1
|
- dev
|
||||||
selector:
|
|
||||||
matchLabels:
|
jobs:
|
||||||
app: gohorse-backoffice-dev
|
build-and-push:
|
||||||
template:
|
runs-on: docker-ready
|
||||||
metadata:
|
env:
|
||||||
labels:
|
REGISTRY: pipe.gohorsejobs.com
|
||||||
app: gohorse-backoffice-dev
|
DOCKER_API_VERSION: "1.43"
|
||||||
env: development
|
defaults:
|
||||||
spec:
|
run:
|
||||||
imagePullSecrets:
|
shell: sh
|
||||||
- name: registry-auth
|
steps:
|
||||||
initContainers:
|
- name: Install Dependencies
|
||||||
- name: set-mtu
|
run: |
|
||||||
image: busybox
|
sed -i 's/dl-cdn.alpinelinux.org/mirror.leaseweb.com/g' /etc/apk/repositories
|
||||||
# CORREÇÃO: Usando $(VAR) para o Kubernetes injetar o valor corretamente
|
apk add --no-cache git docker-cli nodejs
|
||||||
command: ['sh', '-c', 'ifconfig eth0 mtu $(MTU_VALUE) || true']
|
|
||||||
env:
|
- name: Checkout code
|
||||||
- name: MTU_VALUE
|
uses: actions/checkout@v4
|
||||||
valueFrom:
|
with:
|
||||||
secretKeyRef:
|
fetch-depth: 1
|
||||||
name: backend-secrets
|
|
||||||
key: MTU
|
- name: Login to Registry
|
||||||
securityContext:
|
run: |
|
||||||
privileged: true
|
echo "${{ secrets.FORGEJO_TOKEN }}" | docker login ${{ env.REGISTRY }} -u bohessefm --password-stdin
|
||||||
containers:
|
|
||||||
- name: backoffice
|
- name: Build and Push Backend
|
||||||
image: pipe.gohorsejobs.com/bohessefm/backoffice:latest
|
run: |
|
||||||
imagePullPolicy: Always
|
cd backend
|
||||||
ports:
|
docker build -t ${{ env.REGISTRY }}/bohessefm/gohorsejobs:latest -t ${{ env.REGISTRY }}/bohessefm/gohorsejobs:${{ github.sha }} .
|
||||||
- containerPort: 3001
|
docker push ${{ env.REGISTRY }}/bohessefm/gohorsejobs:latest
|
||||||
envFrom:
|
docker push ${{ env.REGISTRY }}/bohessefm/gohorsejobs:${{ github.sha }}
|
||||||
- secretRef:
|
|
||||||
name: backend-secrets
|
- name: Build and Push Backoffice
|
||||||
env:
|
run: |
|
||||||
- name: NODE_TLS_REJECT_UNAUTHORIZED
|
cd backoffice
|
||||||
value: "0"
|
docker build -t ${{ env.REGISTRY }}/bohessefm/backoffice:latest -t ${{ env.REGISTRY }}/bohessefm/backoffice:${{ github.sha }} .
|
||||||
resources:
|
docker push ${{ env.REGISTRY }}/bohessefm/backoffice:latest
|
||||||
requests:
|
docker push ${{ env.REGISTRY }}/bohessefm/backoffice:${{ github.sha }}
|
||||||
memory: "512Mi" # Reduzi um pouco o request para facilitar o agendamento no nó
|
|
||||||
cpu: "300m"
|
deploy-to-k3s:
|
||||||
limits:
|
needs: build-and-push
|
||||||
memory: "2Gi"
|
runs-on: docker-ready
|
||||||
cpu: "800m"
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: sh # <--- CRUCIAL: Adicionado para evitar erro de 'bash not found'
|
||||||
|
steps:
|
||||||
|
- name: Install Tools
|
||||||
|
run: |
|
||||||
|
sed -i 's/dl-cdn.alpinelinux.org/mirror.leaseweb.com/g' /etc/apk/repositories
|
||||||
|
apk add --no-cache git curl
|
||||||
|
if [ ! -f /usr/local/bin/kubectl ]; then
|
||||||
|
KVER=$(curl -L -s https://dl.k8s.io/release/stable.txt)
|
||||||
|
curl -LO "https://dl.k8s.io/release/${KVER}/bin/linux/amd64/kubectl"
|
||||||
|
chmod +x kubectl
|
||||||
|
mv kubectl /usr/local/bin/
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Deploy to K3s
|
||||||
|
run: |
|
||||||
|
mkdir -p $HOME/.kube
|
||||||
|
echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config
|
||||||
|
chmod 600 $HOME/.kube/config
|
||||||
|
export KUBECONFIG=$HOME/.kube/config
|
||||||
|
|
||||||
|
# 1. Namespace
|
||||||
|
kubectl create namespace gohorsejobsdev --dry-run=client -o yaml | kubectl apply -f -
|
||||||
|
|
||||||
|
# 2. Secret de Pull (Nomeado como registry-auth conforme sua preferência)
|
||||||
|
kubectl -n gohorsejobsdev create secret docker-registry registry-auth \
|
||||||
|
--docker-server=${{ env.REGISTRY }} \
|
||||||
|
--docker-username=bohessefm \
|
||||||
|
--docker-password='${{ secrets.FORGEJO_TOKEN }}' \
|
||||||
|
--dry-run=client -o yaml | kubectl apply -f -
|
||||||
|
|
||||||
|
# 3. Secrets da Aplicação (Idempotente)
|
||||||
|
kubectl -n gohorsejobsdev create secret generic backend-secrets \
|
||||||
|
--from-literal=DATABASE_URL='${{ vars.DATABASE_URL }}' \
|
||||||
|
--dry-run=client -o yaml | kubectl apply -f -
|
||||||
|
|
||||||
|
# 4. Aplicar Manifestos
|
||||||
|
kubectl apply -f k8s/dev/ -n gohorsejobsdev
|
||||||
|
|
||||||
|
# 5. Atualização Direta de Imagem
|
||||||
|
kubectl -n gohorsejobsdev set image deployment/gohorse-backend-dev backend=${{ env.REGISTRY }}/bohessefm/gohorsejobs:${{ github.sha }}
|
||||||
|
kubectl -n gohorsejobsdev set image deployment/gohorse-backoffice-dev backoffice=${{ env.REGISTRY }}/bohessefm/backoffice:${{ github.sha }}
|
||||||
Loading…
Reference in a new issue