Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- name: CI/CD Pipeline
- on:
- push:
- branches:
- - main
- permissions:
- contents: write
- packages: write
- jobs:
- # lint:
- # runs-on: ubuntu-latest
- # steps:
- # - uses: actions/checkout@v4
- #
- # - name: Setup PHP
- # uses: shivammathur/setup-php@v2
- # with:
- # php-version: '8.4'
- #
- # - name: Install Dependencies
- # run: |
- # composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- # npm install
- #
- # - name: Run Pint
- # run: vendor/bin/pint
- #
- # - name: Format Frontend
- # run: npm run format
- #
- # - name: Lint Frontend
- # run: npm run lint
- #
- ## - name: Commit Changes
- ## uses: stefanzweifel/git-auto-commit-action@v5
- ## with:
- ## commit_message: fix code style
- ## commit_options: '--no-verify'
- #
- # test:
- # runs-on: ubuntu-latest
- # needs: lint
- # steps:
- # - name: Checkout
- # uses: actions/checkout@v4
- #
- # - name: Setup PHP
- # uses: shivammathur/setup-php@v2
- # with:
- # php-version: 8.4
- # tools: composer:v2
- # coverage: xdebug
- #
- # - name: Setup Node
- # uses: actions/setup-node@v4
- # with:
- # node-version: '22'
- # cache: 'npm'
- #
- # - name: Install Node Dependencies
- # run: npm ci
- #
- # - name: Build Assets
- # run: npm run build
- #
- # - name: Create SQLite Database
- # run: touch database/database.sqlite
- #
- # - name: Install PHP Dependencies
- # run: composer install --no-interaction --prefer-dist --optimize-autoloader
- #
- # - name: Copy Environment File
- # run: cp .env.example .env
- #
- # - name: Generate Application Key
- # run: php artisan key:generate
- #
- # - name: Set Database to SQLite
- # run: echo "DB_CONNECTION=sqlite" >> .env
- #
- # - name: Run Migrations
- # run: php artisan migrate --force
- #
- # - name: Run Tests
- # run: ./vendor/bin/pest
- build_and_push:
- runs-on: ubuntu-latest
- # needs: [ lint, test ]
- steps:
- - name: Checkout Repository
- uses: actions/checkout@v4
- - name: Set up QEMU
- uses: docker/setup-qemu-action@v2
- - name: Set up Docker Buildx
- uses: docker/setup-buildx-action@v2
- - name: Log in to GHCR
- run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- - name: Build and Push Docker Image with Cache
- uses: docker/build-push-action@v4
- with:
- context: .
- push: true
- tags: ghcr.io/${{ github.repository_owner }}/apotek-app:${{ vars.CURRENT_VERSION }}
- cache-from: type=gha
- cache-to: type=gha,mode=max
- deploy:
- runs-on: ubuntu-latest
- needs: build_and_push
- steps:
- - name: Setup SSH Key
- run: |
- mkdir -p ~/.ssh
- echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- ssh-keyscan -H ${{ vars.HOST }} >> ~/.ssh/known_hosts
- - name: Deploy via SSH
- run: |
- ssh -i ~/.ssh/id_rsa ${{ vars.USERNAME }}@${{ vars.HOST }} << 'EOF'
- set -e
- cd ${{ vars.APP_PATH }}
- echo "Logging in to GHCR..."
- echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin || { echo "GHCR login failed"; exit 1; }
- echo "Pulling new image..."
- docker pull ghcr.io/${{ github.repository_owner }}/apotek-app:${{ vars.CURRENT_VERSION}} || { echo "Docker pull failed"; exit 1; }
- echo "Tagging image..."
- docker tag ghcr.io/${{ github.repository_owner }}/apotek-app:${{ vars.CURRENT_VERSION}} apotek-app:${{ vars.CURRENT_VERSION }}
- echo "Stopping existing containers..."
- docker compose down || echo "No containers running, skipping shutdown."
- echo "Remove inertia-build volume..."
- docker volume rm apotekcodewithcyou_app-public || echo "Volume apotekcodewithcyou_app-public_app-public tidak ditemukan, lanjut..."
- echo "Starting new containers..."
- docker compose up -d || { echo "Docker compose up failed"; exit 1; }
- echo "Cleaning up unused images..."
- docker image prune -f
- EOF
Advertisement
Add Comment
Please, Sign In to add comment