Merge pull request #30 from KUmmIT-Team3/new #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CD-React | |
| on: | |
| push: | |
| branches: | |
| - main | |
| env: | |
| IMAGE_NAME: ghcr.io/${{ secrets.GHCR_USERNAME }}/reactapp | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22.9.0' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Log in to GHCR | |
| run: echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin | |
| - name: Build Docker image | |
| run: docker build -t $IMAGE_NAME . | |
| - name: Push Docker image | |
| run: docker push $IMAGE_NAME | |
| - name: Deploy on remote Oracle VM | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SERVER_SSH_KEY }} | |
| script: | | |
| IMAGE_NAME=ghcr.io/${{ secrets.GHCR_USERNAME }}/reactapp | |
| echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin | |
| docker pull $IMAGE_NAME | |
| docker stop reactapp || true | |
| docker rm reactapp || true | |
| docker run -d --name reactapp -p 80:5173 $IMAGE_NAME |