|
| 1 | +name: CI/CD Digital Ocean PROD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [deploy] |
| 6 | + |
| 7 | +env: |
| 8 | + REACT_APP_CLIENT_URL: ${{secrets.REACT_APP_CLIENT_URL}} |
| 9 | + REACT_APP_SERVER_URL: ${{secrets.REACT_APP_SERVER_URL}} |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + strategy: |
| 16 | + matrix: |
| 17 | + node-version: [14.x] |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: 'Checkout Repository' |
| 21 | + uses: actions/checkout@v2 |
| 22 | + |
| 23 | + - name: Use Node.js ${{ matrix.node-version }} |
| 24 | + uses: actions/setup-node@v1 |
| 25 | + with: |
| 26 | + node-version: ${{ matrix.node-version }} |
| 27 | + |
| 28 | + - name: Install and Build Server |
| 29 | + run: cd server && npm install && npm run build |
| 30 | + |
| 31 | + - name: Install and Build Client |
| 32 | + run: cd client && npm install --force --production && npm run build |
| 33 | + |
| 34 | + - name: Upload to Server Digital Ocean |
| 35 | + uses: appleboy/scp-action@master # This is the action |
| 36 | + with: |
| 37 | + host: ${{secrets.SSH_HOST_PROD}} # IP address of the server you wish to ssh into |
| 38 | + key: ${{secrets.SSH_KEY}} # Private or public key of the server |
| 39 | + username: ${{ secrets.SSH_USERNAME }} # User of the server you want to ssh into |
| 40 | + passphrase: ${{ secrets.SSH_PASSPHRASE }} |
| 41 | + source: 'server/dist' # Path to the directory you want to copy |
| 42 | + target: '~/' # Path to the directory you want to copy to |
| 43 | + |
| 44 | + - name: Upload to Client Digital Ocean |
| 45 | + uses: appleboy/scp-action@master # This is the action |
| 46 | + with: |
| 47 | + host: ${{secrets.SSH_HOST_PROD}} # IP address of the server you wish to ssh into |
| 48 | + key: ${{secrets.SSH_KEY}} # Private or public key of the server |
| 49 | + username: ${{ secrets.SSH_USERNAME }} # User of the server you want to ssh into |
| 50 | + passphrase: ${{ secrets.SSH_PASSPHRASE }} |
| 51 | + source: 'client/build' # Path to the directory you want to copy |
| 52 | + target: '/var/www/html' # Path to the directory you want to copy to |
| 53 | + |
| 54 | + - name: Start Server |
| 55 | + uses: appleboy/[email protected] # This is the action |
| 56 | + with: |
| 57 | + host: ${{secrets.SSH_HOST_PROD}} # IP address of the server you wish to ssh into |
| 58 | + key: ${{secrets.SSH_KEY}} # Private or public key of the server |
| 59 | + username: ${{ secrets.SSH_USERNAME }} # User of the server you want to ssh into |
| 60 | + passphrase: ${{ secrets.SSH_PASSPHRASE }} |
| 61 | + |
| 62 | + script: | |
| 63 | + rm -rf ~/caucus |
| 64 | + git clone https://github.com/Rishabh-malhotraa/caucus.git |
| 65 | + mv ~/server/dist ~/caucus/server/ |
| 66 | + cd ~/caucus/server && npm install --production && cd ~/ && rm -rf ./server |
| 67 | + pm2 stop caucus-server caucus-crdt-server |
| 68 | + pm2 start ~/env/ecosystem.config.js --env production |
| 69 | + echo 'Deployment successful to digital ocean' |
0 commit comments