fix: build error #12
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: Deploy to EC2 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths-ignore: | |
| - '**.md' | |
| jobs: | |
| test-backend: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r backend/requirements.txt | |
| - name: Run Backend Tests | |
| run: | | |
| cd backend | |
| pytest | |
| test-frontend: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '20' | |
| - name: Install dependencies | |
| run: | | |
| cd frontend | |
| npm install | |
| - name: Run Component Tests | |
| run: | | |
| cd frontend | |
| npm run test:component | |
| deploy: | |
| needs: [test-backend, test-frontend] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Deploy to EC2 | |
| uses: appleboy/ssh-action@master | |
| env: | |
| ENV_FILE: ${{ secrets.ENV_FILE }} | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| envs: ENV_FILE | |
| script: | | |
| # Stop script on first error | |
| set -e | |
| # Add /usr/local/bin to PATH for this session | |
| export PATH=$PATH:/usr/local/bin | |
| # Navigate to the project directory | |
| cd ~/task_master | |
| # Pull the latest changes | |
| git pull origin main | |
| # Create .env file from secret | |
| echo "$ENV_FILE" > backend/.env | |
| # Rebuild and restart containers | |
| # Use sudo to ensure we have permissions | |
| # Disable BuildKit to avoid compatibility issues on Amazon Linux 2 | |
| sudo DOCKER_BUILDKIT=0 /usr/local/bin/docker-compose up -d --build | |
| # Prune unused images to save space | |
| sudo docker image prune -f |