81 lines
2.9 KiB
YAML
81 lines
2.9 KiB
YAML
name: Build & Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main, master]
|
|
pull_request:
|
|
branches: [main, master]
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: linux
|
|
container: node:24-alpine
|
|
steps:
|
|
- name: Install git
|
|
run: apk add --no-cache git
|
|
|
|
- name: Checkout repository
|
|
run: git clone --depth=1 http://x-access-token:${{ github.token }}@192.168.1.39:3000/${{ github.repository }}.git .
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Run build
|
|
run: node ace build
|
|
|
|
docker:
|
|
needs: build
|
|
runs-on: dind
|
|
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
|
|
steps:
|
|
- name: Checkout repository
|
|
run: git clone --depth=1 http://x-access-token:${{ github.token }}@192.168.1.39:3000/${{ github.repository }}.git .
|
|
|
|
- name: Login to Gitea Container Registry
|
|
run: echo "${{ secrets.TOKEN }}" | docker login http://192.168.1.39:3000 -u "${{ secrets.USERNAME }}" --password-stdin
|
|
|
|
- name: Build and push Docker image
|
|
run: |
|
|
IMAGE=192.168.1.39:3000/$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
|
|
docker build -t ${IMAGE}:latest -t ${IMAGE}:${{ github.sha }} .
|
|
docker push ${IMAGE}:latest
|
|
docker push ${IMAGE}:${{ github.sha }}
|
|
|
|
deploy:
|
|
needs: docker
|
|
runs-on: dind
|
|
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
|
|
steps:
|
|
- name: Checkout repository
|
|
run: git clone --depth=1 http://x-access-token:${{ github.token }}@192.168.1.39:3000/${{ github.repository }}.git .
|
|
|
|
- name: Deploy on NAS
|
|
run: |
|
|
apk add --no-cache openssh-client
|
|
|
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > /tmp/id_ed25519
|
|
chmod 600 /tmp/id_ed25519
|
|
|
|
SSH="ssh -i /tmp/id_ed25519 -o StrictHostKeyChecking=no -o ConnectTimeout=10 -o BatchMode=yes Stude12@192.168.1.39"
|
|
|
|
# Copier docker-compose.prod.yml
|
|
cat docker-compose.prod.yml | $SSH "mkdir -p /volume1/docker/adam-acs && cat > /volume1/docker/adam-acs/docker-compose.prod.yml"
|
|
|
|
# Créer le .env sur le NAS (valeurs fixes + secrets sensibles uniquement)
|
|
$SSH "cat > /volume1/docker/adam-acs/.env" <<EOF
|
|
APP_KEY=${{ secrets.APP_KEY }}
|
|
APP_URL=https://adam-acs.stude12-ugreen.ddns.net
|
|
APP_PORT=8080
|
|
LOG_LEVEL=info
|
|
WEBUI_USERNAME=Admin
|
|
WEBUI_PASSWORD=${{ secrets.WEBUI_PASSWORD }}
|
|
API_KEY=${{ secrets.API_KEY }}
|
|
EOF
|
|
|
|
# Déployer
|
|
$SSH "
|
|
cd /volume1/docker/adam-acs &&
|
|
echo '${{ secrets.SSHPASS }}' | sudo -S /usr/bin/docker compose -f docker-compose.prod.yml pull &&
|
|
echo '${{ secrets.SSHPASS }}' | sudo -S /usr/bin/docker compose -f docker-compose.prod.yml up -d --remove-orphans
|
|
"
|