diff --git a/.github/workflows/deploy_dev.yml b/.github/workflows/deploy_dev.yml new file mode 100644 index 00000000..150899a8 --- /dev/null +++ b/.github/workflows/deploy_dev.yml @@ -0,0 +1,35 @@ +name: Deploy OpenKab Dev with Ansible + +on: + pull_request: + branches: [rilis-dev] + types: [closed] + +permissions: + contents: read + +concurrency: + group: deploy-openkab-dev + cancel-in-progress: true + +jobs: + deploy: + if: github.event.pull_request.merged == true + name: Deploy OpenKab Dev to Production Server + runs-on: ubuntu-latest + + steps: + - name: Checkout Ansible Code + uses: actions/checkout@v4 + + - name: Deploy via SSH using appleboy/ssh-action + uses: appleboy/ssh-action@v1.2.0 + with: + host: ${{ secrets.CICD_SERVER_IP }} + username: ${{ secrets.CICD_SERVER_USER }} + key: ${{ secrets.CICD_SERVER_PRIVATE_KEY }} + port: ${{ secrets.CICD_SERVER_PORT }} + script: | + set -euo pipefail + cd ${{ secrets.CICD_SERVER_PATH }} + ansible-playbook -i inventories/production/inventory.yml playbooks/deploy-openkab-dev.yml diff --git a/.github/workflows/deploy_prod.yml b/.github/workflows/deploy_prod.yml deleted file mode 100644 index 5f761827..00000000 --- a/.github/workflows/deploy_prod.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Deploy OpenKab to Production - -on: - release: - types: [published] - -jobs: - deploy: - name: Deploy to Production Server - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup SSH - uses: appleboy/ssh-action@v1 - with: - host: ${{ secrets.PROD_HOST }} - username: ${{ secrets.PROD_USER }} - key: ${{ secrets.PROD_SSH_KEY }} - port: ${{ secrets.PROD_PORT }} - script: | - cd ${{ secrets.PROD_DEPLOY_PATH }} - # Restore to the state of the remote branch - git fetch origin ${{ secrets.BRANCH || 'main' }} - git reset --hard origin/${{ secrets.BRANCH || 'main' }} - # Pull the latest changes from the remote branch - git pull origin ${{ secrets.BRANCH || 'main' }} - composer install --no-interaction --prefer-dist --optimize-autoloader - php artisan migrate --force - php artisan admin:menu-update - php artisan config:cache - php artisan route:cache - php artisan view:cache \ No newline at end of file diff --git a/.github/workflows/deploy_rilis.yml b/.github/workflows/deploy_rilis.yml new file mode 100644 index 00000000..31089fa3 --- /dev/null +++ b/.github/workflows/deploy_rilis.yml @@ -0,0 +1,35 @@ +name: Deploy OpenKab Rilis with Ansible + +on: + release: + types: [published] + +permissions: + contents: read + +concurrency: + group: deploy-openkab-rilis + cancel-in-progress: true + +jobs: + deploy: + # rilis dari branch 'master' & bukan prerelease + if: github.event.release.target_commitish == 'master' && github.event.release.prerelease == false + name: Deploy OpenKab Rilis to Production Server + runs-on: ubuntu-latest + + steps: + - name: Checkout Ansible Code + uses: actions/checkout@v4 + + - name: Deploy via SSH using appleboy/ssh-action + uses: appleboy/ssh-action@v1.2.0 + with: + host: ${{ secrets.CICD_SERVER_IP }} + username: ${{ secrets.CICD_SERVER_USER }} + key: ${{ secrets.CICD_SERVER_PRIVATE_KEY }} + port: ${{ secrets.CICD_SERVER_PORT }} + script: | + set -euo pipefail + cd ${{ secrets.CICD_SERVER_PATH }} + ansible-playbook -i inventories/production/inventory.yml playbooks/deploy-openkab-rilis.yml --extra-vars "release_tag=${{ github.event.release.tag_name }} diff --git a/.github/workflows/deploy_staging.yml b/.github/workflows/deploy_staging.yml deleted file mode 100644 index 9b2e2ef0..00000000 --- a/.github/workflows/deploy_staging.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Deploy OpenKab to Staging - -on: - release: - types: [published] - -jobs: - deploy: - name: Deploy to Staging Server - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup SSH - uses: appleboy/ssh-action@v1 - with: - host: ${{ secrets.STAG_HOST }} - username: ${{ secrets.STAG_USER }} - key: ${{ secrets.STAG_SSH_KEY }} - port: ${{ secrets.STAG_PORT }} - script: | - cd ${{ secrets.STAG_DEPLOY_PATH }} - # Restore to the state of the remote branch - git fetch origin ${{ secrets.BRANCH || 'main' }} - git reset --hard origin/${{ secrets.BRANCH || 'main' }} - # Pull the latest changes from the remote branch - git pull origin ${{ secrets.BRANCH || 'main' }} - composer install --no-interaction --prefer-dist --optimize-autoloader - php artisan migrate --force - php artisan admin:menu-update - php artisan config:cache - php artisan route:cache - php artisan view:cache \ No newline at end of file