martinms

Untitled

Oct 7th, 2025
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.39 KB | None | 0 0
  1. name: CI/CD Pipeline
  2.  
  3. on:
  4.   push:
  5.     branches:
  6.       - main
  7.  
  8. permissions:
  9.   contents: write
  10.   packages: write
  11.  
  12. jobs:
  13. #  lint:
  14. #    runs-on: ubuntu-latest
  15. #    steps:
  16. #      - uses: actions/checkout@v4
  17. #
  18. #      - name: Setup PHP
  19. #        uses: shivammathur/setup-php@v2
  20. #        with:
  21. #          php-version: '8.4'
  22. #
  23. #      - name: Install Dependencies
  24. #        run: |
  25. #          composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
  26. #          npm install
  27. #
  28. #      - name: Run Pint
  29. #        run: vendor/bin/pint
  30. #
  31. #      - name: Format Frontend
  32. #        run: npm run format
  33. #
  34. #      - name: Lint Frontend
  35. #        run: npm run lint
  36. #
  37. ##      - name: Commit Changes
  38. ##        uses: stefanzweifel/git-auto-commit-action@v5
  39. ##        with:
  40. ##          commit_message: fix code style
  41. ##          commit_options: '--no-verify'
  42. #
  43. #  test:
  44. #    runs-on: ubuntu-latest
  45. #    needs: lint
  46. #    steps:
  47. #      - name: Checkout
  48. #        uses: actions/checkout@v4
  49. #
  50. #      - name: Setup PHP
  51. #        uses: shivammathur/setup-php@v2
  52. #        with:
  53. #          php-version: 8.4
  54. #          tools: composer:v2
  55. #          coverage: xdebug
  56. #
  57. #      - name: Setup Node
  58. #        uses: actions/setup-node@v4
  59. #        with:
  60. #          node-version: '22'
  61. #          cache: 'npm'
  62. #
  63. #      - name: Install Node Dependencies
  64. #        run: npm ci
  65. #
  66. #      - name: Build Assets
  67. #        run: npm run build
  68. #
  69. #      - name: Create SQLite Database
  70. #        run: touch database/database.sqlite
  71. #
  72. #      - name: Install PHP Dependencies
  73. #        run: composer install --no-interaction --prefer-dist --optimize-autoloader
  74. #
  75. #      - name: Copy Environment File
  76. #        run: cp .env.example .env
  77. #
  78. #      - name: Generate Application Key
  79. #        run: php artisan key:generate
  80. #
  81. #      - name: Set Database to SQLite
  82. #        run: echo "DB_CONNECTION=sqlite" >> .env
  83. #
  84. #      - name: Run Migrations
  85. #        run: php artisan migrate --force
  86. #
  87. #      - name: Run Tests
  88. #        run: ./vendor/bin/pest
  89.  
  90.   build_and_push:
  91.     runs-on: ubuntu-latest
  92. #    needs: [ lint, test ]
  93.    steps:
  94.       - name: Checkout Repository
  95.         uses: actions/checkout@v4
  96.  
  97.       - name: Set up QEMU
  98.         uses: docker/setup-qemu-action@v2
  99.  
  100.       - name: Set up Docker Buildx
  101.         uses: docker/setup-buildx-action@v2
  102.  
  103.       - name: Log in to GHCR
  104.         run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
  105.  
  106.       - name: Build and Push Docker Image with Cache
  107.         uses: docker/build-push-action@v4
  108.         with:
  109.           context: .
  110.           push: true
  111.           tags: ghcr.io/${{ github.repository_owner }}/apotek-app:${{ vars.CURRENT_VERSION }}
  112.           cache-from: type=gha
  113.           cache-to: type=gha,mode=max
  114.  
  115.   deploy:
  116.     runs-on: ubuntu-latest
  117.     needs: build_and_push
  118.     steps:
  119.       - name: Setup SSH Key
  120.         run: |
  121.           mkdir -p ~/.ssh
  122.           echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa
  123.           chmod 600 ~/.ssh/id_rsa
  124.           ssh-keyscan -H ${{ vars.HOST }} >> ~/.ssh/known_hosts
  125.  
  126.       - name: Deploy via SSH
  127.         run: |
  128.           ssh -i ~/.ssh/id_rsa ${{ vars.USERNAME }}@${{ vars.HOST }} << 'EOF'
  129.             set -e
  130.             cd ${{ vars.APP_PATH }}
  131.  
  132.             echo "Logging in to GHCR..."
  133.             echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin || { echo "GHCR login failed"; exit 1; }
  134.  
  135.             echo "Pulling new image..."
  136.             docker pull ghcr.io/${{ github.repository_owner }}/apotek-app:${{ vars.CURRENT_VERSION}} || { echo "Docker pull failed"; exit 1; }
  137.  
  138.             echo "Tagging image..."
  139.             docker tag ghcr.io/${{ github.repository_owner }}/apotek-app:${{ vars.CURRENT_VERSION}} apotek-app:${{ vars.CURRENT_VERSION }}
  140.  
  141.             echo "Stopping existing containers..."
  142.             docker compose down || echo "No containers running, skipping shutdown."
  143.  
  144.             echo "Remove inertia-build volume..."
  145.             docker volume rm apotekcodewithcyou_app-public || echo "Volume apotekcodewithcyou_app-public_app-public tidak ditemukan, lanjut..."
  146.  
  147.             echo "Starting new containers..."
  148.             docker compose up -d || { echo "Docker compose up failed"; exit 1; }
  149.  
  150.             echo "Cleaning up unused images..."
  151.             docker image prune -f
  152.           EOF
Advertisement
Add Comment
Please, Sign In to add comment