Update Docker image tag from 0.2 to 0.3 #29
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: CI/CD Application Deployment | |
| on: | |
| push: | |
| branches: ["main"] | |
| jobs: | |
| # ------------------- | |
| # CI JOB | |
| # ------------------- | |
| ci: | |
| name: Continuous Integration | |
| 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: 20 | |
| - name: Install dependencies | |
| run: npm install | |
| working-directory: next-ui | |
| - name: Run tests | |
| run: | | |
| if npm run | grep -q test; then | |
| npm test | |
| else | |
| echo "No tests found, skipping..." | |
| fi | |
| working-directory: next-ui | |
| - name: Build app | |
| run: npm run build | |
| working-directory: next-ui | |
| # ------------------- | |
| # CD JOB | |
| # ------------------- | |
| cd: | |
| name: Docker Build, Push & Deploy to EC2 | |
| runs-on: ubuntu-latest | |
| needs: ci | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./next-ui | |
| file: ./next-ui/Dockerfile | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKERHUB_USERNAME }}/alienui:0.3 | |
| cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/alienui:0.2 | |
| cache-to: type=inline | |
| - name: Setup SSH Key | |
| run: | | |
| echo "${{ secrets.EC2_SSH_PRIVATE_KEY }}" > key.pem | |
| chmod 600 key.pem | |
| - name: Deploy to EC2 | |
| run: | | |
| ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@${{ secrets.EC2_HOST }} << "EOF" | |
| sudo docker stop alienui || true | |
| sudo docker rm alienui || true | |
| sudo docker system prune -af || true | |
| sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/alienui:0.3 | |
| sudo docker run -d \ | |
| --name alienui \ | |
| -p 80:3000 \ | |
| --restart unless-stopped \ | |
| ${{ secrets.DOCKERHUB_USERNAME }}/alienui:0.3 | |
| EOF |