|
| 1 | +name: Déploiement sur VPS (dev) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +env: |
| 9 | + APP_NAME: ${{ github.event.repository.name }} |
| 10 | + APP_PATH: /home/apps/${{ github.event.repository.name }} |
| 11 | + NODE_ENV: dev |
| 12 | + |
| 13 | +jobs: |
| 14 | + deploy: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Vérifier le code |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Créer le dossier de l'application sur le VPS |
| 21 | + uses: appleboy/ssh-action@v1.0.3 |
| 22 | + with: |
| 23 | + host: ${{ secrets.VPS_HOST }} |
| 24 | + username: ${{ secrets.VPS_USERNAME }} |
| 25 | + key: ${{ secrets.VPS_SSH_KEY }} |
| 26 | + port: ${{ secrets.VPS_PORT }} |
| 27 | + script: | |
| 28 | + mkdir -p ${{ env.APP_PATH }} |
| 29 | + cd ${{ env.APP_PATH }} |
| 30 | + if [ -d "app" ]; then |
| 31 | + rm -rf app |
| 32 | + fi |
| 33 | + mkdir -p app |
| 34 | +
|
| 35 | + - name: Copier les fichiers de l'application |
| 36 | + uses: appleboy/scp-action@v0.1.7 |
| 37 | + with: |
| 38 | + host: ${{ secrets.VPS_HOST }} |
| 39 | + username: ${{ secrets.VPS_USERNAME }} |
| 40 | + key: ${{ secrets.VPS_SSH_KEY }} |
| 41 | + port: ${{ secrets.VPS_PORT }} |
| 42 | + source: "." |
| 43 | + target: "${{ env.APP_PATH }}/app" |
| 44 | + strip_components: 0 |
| 45 | + |
| 46 | + - name: Mettre à jour le docker-compose avec le nom de l'application |
| 47 | + uses: appleboy/ssh-action@v1.0.3 |
| 48 | + with: |
| 49 | + host: ${{ secrets.VPS_HOST }} |
| 50 | + username: ${{ secrets.VPS_USERNAME }} |
| 51 | + key: ${{ secrets.VPS_SSH_KEY }} |
| 52 | + port: ${{ secrets.VPS_PORT }} |
| 53 | + script: | |
| 54 | + cd "${{ env.APP_PATH }}/app" |
| 55 | + sed -i "1s/^/name: ${{ env.APP_NAME }}\n/" compose.${{ env.NODE_ENV }}.yaml |
| 56 | +
|
| 57 | + - name: Construire et démarrer les conteneurs Docker |
| 58 | + uses: appleboy/ssh-action@v1.0.3 |
| 59 | + with: |
| 60 | + host: ${{ secrets.VPS_HOST }} |
| 61 | + username: ${{ secrets.VPS_USERNAME }} |
| 62 | + key: ${{ secrets.VPS_SSH_KEY }} |
| 63 | + port: ${{ secrets.VPS_PORT }} |
| 64 | + script: | |
| 65 | + cd "${{ env.APP_PATH }}/app" |
| 66 | + docker compose -f compose.${{ env.NODE_ENV }}.yaml down || true |
| 67 | + docker compose -f compose.${{ env.NODE_ENV }}.yaml build --no-cache |
| 68 | + docker compose -f compose.${{ env.NODE_ENV }}.yaml up -d |
| 69 | + docker system prune -f |
0 commit comments