|
| 1 | +on: |
| 2 | + workflow_call: |
| 3 | + inputs: |
| 4 | + env: |
| 5 | + required: true |
| 6 | + type: string |
| 7 | + secrets: |
| 8 | + AWS_ACCESS_KEY_ID: |
| 9 | + required: true |
| 10 | + AWS_SECRET_ACCESS_KEY: |
| 11 | + required: true |
| 12 | + |
| 13 | +name: Deploy to Amazon ECS |
| 14 | + |
| 15 | +jobs: |
| 16 | + deploy: |
| 17 | + name: Deploy |
| 18 | + runs-on: ubuntu-latest |
| 19 | + environment: production |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v2 |
| 24 | + |
| 25 | + - name: Configure AWS credentials |
| 26 | + uses: aws-actions/configure-aws-credentials@v1 |
| 27 | + with: |
| 28 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 29 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 30 | + aws-region: eu-west-2 |
| 31 | + |
| 32 | + - name: Login to Amazon ECR |
| 33 | + id: login-ecr |
| 34 | + uses: aws-actions/amazon-ecr-login@v1 |
| 35 | + |
| 36 | + - name: Build, tag, and push image to Amazon ECR |
| 37 | + id: build-image |
| 38 | + env: |
| 39 | + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
| 40 | + ECR_REPOSITORY: j4numbers/personal-website |
| 41 | + IMAGE_TAG: ${{ github.sha }} |
| 42 | + run: | |
| 43 | + # Build a docker container and |
| 44 | + # push it to ECR so that it can |
| 45 | + # be deployed to ECS. |
| 46 | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . |
| 47 | + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
| 48 | + echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" |
| 49 | +
|
| 50 | + - name: HashiCorp - Setup Terraform |
| 51 | + |
| 52 | + with: |
| 53 | + # The version of Terraform CLI to install. Defaults to `latest`. |
| 54 | + terraform_version: "> 0.15.5" |
| 55 | + |
| 56 | + - name: Validate and plan deployment Terraform |
| 57 | + id: terraform-plan-validate |
| 58 | + env: |
| 59 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 60 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 61 | + |
| 62 | + TF_VAR_deploy_version: ${{ github.sha }} |
| 63 | + TF_VAR_vpc_id: ${{ secrets.DEPLOY_VPC_ID }} |
| 64 | + TF_VAR_application_debug_mode: "false" |
| 65 | + |
| 66 | + TF_VAR_logger_level: "info" |
| 67 | + run: | |
| 68 | + cd tf/site/ |
| 69 | + terraform init -backend-config backend_config/dev.conf |
| 70 | + terraform validate |
| 71 | + terraform plan -no-color -out plan.tfplan |
| 72 | +
|
| 73 | + - name: Deploy Terraform |
| 74 | + id: terraform-apply |
| 75 | + env: |
| 76 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 77 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 78 | + run: cd tf/site/ && terraform apply plan.tfplan |
0 commit comments