|
| 1 | +name: Deploy to Production |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - multitenancy |
| 7 | + |
| 8 | +jobs: |
| 9 | + deploy: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + timeout-minutes: 30 |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout source code |
| 15 | + uses: actions/checkout@v3 |
| 16 | + |
| 17 | + - name: Configure AWS credentials |
| 18 | + uses: aws-actions/configure-aws-credentials@v1 |
| 19 | + with: |
| 20 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 21 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 22 | + aws-region: us-east-1 |
| 23 | + |
| 24 | + - name: Login to Amazon ECR |
| 25 | + id: login-ecr |
| 26 | + uses: aws-actions/amazon-ecr-login@v1 |
| 27 | + |
| 28 | + - name: Set up Docker Buildx (for multi-platform builds) |
| 29 | + uses: docker/setup-buildx-action@v2 |
| 30 | + |
| 31 | + - name: Build, tag, and push image to Amazon ECR |
| 32 | + env: |
| 33 | + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
| 34 | + ECR_REPOSITORY: finishline-production |
| 35 | + IMAGE_TAG: ${{ github.sha }} |
| 36 | + run: | |
| 37 | + echo "Building Docker image for AMD64 architecture..." |
| 38 | + |
| 39 | + # Build for AMD64 architecture (t3.small instances are AMD64) |
| 40 | + docker buildx build \ |
| 41 | + --platform linux/amd64 \ |
| 42 | + --tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \ |
| 43 | + --tag $ECR_REGISTRY/$ECR_REPOSITORY:latest \ |
| 44 | + --push \ |
| 45 | + . |
| 46 | + |
| 47 | + echo "✅ Image pushed successfully" |
| 48 | + echo "Image: $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" |
| 49 | +
|
| 50 | + - name: Update Dockerrun.aws.json |
| 51 | + env: |
| 52 | + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
| 53 | + ECR_REPOSITORY: finishline-production |
| 54 | + IMAGE_TAG: ${{ github.sha }} |
| 55 | + run: | |
| 56 | + # Create a deployment-specific Dockerrun.aws.json with the commit SHA |
| 57 | + cat > Dockerrun.aws.json <<EOF |
| 58 | + { |
| 59 | + "AWSEBDockerrunVersion": "1", |
| 60 | + "Image": { |
| 61 | + "Name": "$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG", |
| 62 | + "Update": "true" |
| 63 | + }, |
| 64 | + "Ports": [ |
| 65 | + { |
| 66 | + "ContainerPort": 3001, |
| 67 | + "HostPort": 3001 |
| 68 | + } |
| 69 | + ] |
| 70 | + } |
| 71 | + EOF |
| 72 | + |
| 73 | + echo "✅ Dockerrun.aws.json updated with image tag: $IMAGE_TAG" |
| 74 | +
|
| 75 | + - name: Create deployment package |
| 76 | + run: | |
| 77 | + # Include .ebextensions for health check configuration |
| 78 | + zip -r deploy.zip Dockerrun.aws.json .ebextensions/ .ebignore |
| 79 | + |
| 80 | + echo "✅ Deployment package created" |
| 81 | +
|
| 82 | + - name: Deploy to Elastic Beanstalk |
| 83 | + uses: einaregilsson/beanstalk-deploy@v21 |
| 84 | + with: |
| 85 | + aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 86 | + aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 87 | + application_name: finishline-production |
| 88 | + environment_name: finishline-production-env |
| 89 | + version_label: ${{ github.sha }} |
| 90 | + region: us-east-1 |
| 91 | + deployment_package: deploy.zip |
| 92 | + wait_for_deployment: true |
| 93 | + wait_for_environment_recovery: 300 |
| 94 | + |
| 95 | + - name: Verify deployment |
| 96 | + run: | |
| 97 | + echo "🎉 Deployment completed successfully!" |
| 98 | + echo "" |
| 99 | + echo "Deployment Details:" |
| 100 | + echo " Image: ${{ steps.login-ecr.outputs.registry }}/finishline-production:${{ github.sha }}" |
| 101 | + echo " Version: ${{ github.sha }}" |
| 102 | + echo " Environment: finishline-production-env" |
0 commit comments