fix:lint issue fixed #9
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 AWS ECS | |
| on: | |
| push: | |
| branches: [main, production] | |
| pull_request: | |
| branches: [main] | |
| env: | |
| AWS_REGION: us-east-1 | |
| ECR_REPOSITORY: laravel-blog | |
| ECS_SERVICE: laravel-blog-service | |
| ECS_CLUSTER: laravel-blog-cluster | |
| ECS_TASK_DEFINITION: laravel-blog-task | |
| CONTAINER_NAME: laravel-app | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| services: | |
| mysql: | |
| image: mysql:8.0 | |
| env: | |
| MYSQL_ROOT_PASSWORD: password | |
| MYSQL_DATABASE: laravel_test | |
| options: >- | |
| --health-cmd="mysqladmin ping" | |
| --health-interval=10s | |
| --health-timeout=5s | |
| --health-retries=3 | |
| ports: | |
| - 3306:3306 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.2' | |
| extensions: mbstring, dom, fileinfo, mysql, redis | |
| - name: Install dependencies | |
| run: | | |
| composer install --prefer-dist --no-progress --no-suggest | |
| npm install | |
| npm run build | |
| - name: Setup environment | |
| run: | | |
| cp .env.example .env | |
| php artisan key:generate | |
| - name: Run Pint (Code Style Check) | |
| run: ./vendor/bin/pint --preset psr12 --test | |
| - name: Configure test database | |
| run: | | |
| echo "DB_CONNECTION=mysql" >> .env | |
| echo "DB_HOST=127.0.0.1" >> .env | |
| echo "DB_PORT=3306" >> .env | |
| echo "DB_DATABASE=laravel_test" >> .env | |
| echo "DB_USERNAME=root" >> .env | |
| echo "DB_PASSWORD=password" >> .env | |
| php artisan config:clear | |
| cat .env | |
| - name: Wait for services | |
| run: | | |
| echo "Waiting for MySQL..." | |
| while ! mysqladmin ping -h"127.0.0.1" -P"3306" -u"root" -p"password" --silent; do | |
| sleep 2 | |
| done | |
| echo "MySQL is ready!" | |
| - name: Run tests | |
| run: | | |
| php artisan migrate --force | |
| php artisan test | |
| deploy: | |
| name: Deploy to ECS | |
| runs-on: ubuntu-latest | |
| needs: test | |
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/production' | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Login to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| - name: Build, tag, and push image to Amazon ECR | |
| id: build-image | |
| env: | |
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
| IMAGE_TAG: ${{ github.sha }} | |
| run: | | |
| # Build Docker image for production | |
| docker build -f docker/php/Dockerfile.prod -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
| echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
| - name: Fill in the new image ID in the Amazon ECS task definition | |
| id: task-def | |
| uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
| with: | |
| task-definition: aws/task-definition.json | |
| container-name: ${{ env.CONTAINER_NAME }} | |
| image: ${{ steps.build-image.outputs.image }} | |
| - name: Deploy Amazon ECS task definition | |
| uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | |
| with: | |
| task-definition: ${{ steps.task-def.outputs.task-definition }} | |
| service: ${{ env.ECS_SERVICE }} | |
| cluster: ${{ env.ECS_CLUSTER }} | |
| wait-for-service-stability: true |