Skip to content

Instantly share code, notes, and snippets.

@zahidhassanshaikot
Last active June 6, 2024 10:37
Show Gist options
  • Select an option

  • Save zahidhassanshaikot/b613713804ac3d59ac15b91616b29e60 to your computer and use it in GitHub Desktop.

Select an option

Save zahidhassanshaikot/b613713804ac3d59ac15b91616b29e60 to your computer and use it in GitHub Desktop.
---
image: alpine:latest
stages:
- deploy
stage-deploy:
stage: deploy
environment:
name: staging
url: http://example.com
when: manual
before_script:
- 'command -v ssh-agent >/dev/null || ( apk add --update openssh )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan -p $PORT $HOST >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- ssh -p $PORT $SSH_USER@$HOST "cd /deployed_path && git pull && more-commands"
workflow:
rules:
- if: $CI_COMMIT_BRANCH == 'main'
when: always
- when: never
stages:
- deploy-production
stage-deploy-production:
stage: deploy-production
image: alpine
script:
# Connect to the server and run deploy script
- apk add --update openssh
- chmod 400 $NOBIN_KEY
- ssh -i $NOBIN_KEY -o StrictHostKeyChecking=no -p $NOBIN_PORT $SSH_USER@$HOST "cd /home/laraveltheme/admin-nobin.laravel-theme.com/ && git pull origin main && composer install --optimize-autoloader --no-dev --no-interaction && yes | php artisan migrate && php artisan optimize:clear && exit"
only:
- main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment