diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..b2b5b1e --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,57 @@ +# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs + +name: Labor-Lawbot CI/CD + +on: + push: + branches: [ "develop" ] + pull_request: + branches: [ "develop" ] + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [20.x] + + steps: + - name: Checkout + - uses: actions/checkout@v4 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - name: Install dependencies + run: npm install + + - name: Create .env.production + run: | + echo "VITE_API_BASE_URL=${{ secrets.VITE_API_BASE_URL }}" >> .env.production + echo "VITE_WS_BASE_URL=${{ secrets.VITE_WS_BASE_URL }}" >> .env.production + + - name: Build React App + run: npm run build + + - name: Deploy to EC2 + uses: appleboy/scp-action@v0.1.4 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.EC2_SSH_KEY }} + source: "build/*" + target: "/home/ubuntu/lawbot/build" + + - name: Restart Nginx + uses: appleboy/ssh-action@v0.1.6 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.EC2_SSH_KEY }} + script: | + sudo systemctl restart nginx +