|
|
|
name: AWS Deployment
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_call:
|
|
|
|
inputs:
|
|
|
|
aws_account_id:
|
|
|
|
required: true
|
|
|
|
type: string
|
|
|
|
aws_resource_prefix:
|
|
|
|
required: true
|
|
|
|
type: string
|
|
|
|
environment:
|
|
|
|
required: true
|
|
|
|
type: string
|
|
|
|
|
|
|
|
concurrency:
|
|
|
|
group: deploy-${{ inputs.environment }}
|
|
|
|
cancel-in-progress: true
|
|
|
|
|
|
|
|
env:
|
|
|
|
app_repo_role: arn:aws:iam::815624722760:role/core-application-repo
|
|
|
|
aws_region: eu-west-2
|
|
|
|
repository: core
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
push_docker_image:
|
|
|
|
if: inputs.environment != 'staging'
|
|
|
|
name: Push docker image to AWS
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
|
|
|
id-token: write
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Checkout code
|
|
|
|
uses: actions/checkout@v3
|
|
|
|
|
|
|
|
- name: Configure AWS credentials
|
|
|
|
uses: aws-actions/configure-aws-credentials@v3
|
|
|
|
with:
|
|
|
|
aws-region: ${{ env.aws_region }}
|
|
|
|
role-to-assume: ${{ env.app_repo_role }}
|
|
|
|
|
|
|
|
- name: Login to Amazon ECR
|
|
|
|
id: ecr-login
|
|
|
|
uses: aws-actions/amazon-ecr-login@v1
|
|
|
|
with:
|
|
|
|
mask-password: 'true'
|
|
|
|
|
|
|
|
- name: Build, tag, and push docker image to ECR
|
|
|
|
id: build-image
|
|
|
|
env:
|
|
|
|
registry: ${{ steps.ecr-login.outputs.registry }}
|
|
|
|
commit_tag: ${{ github.sha }}
|
|
|
|
run: |
|
|
|
|
docker build -t $registry/$repository:$commit_tag . --target=production
|
|
|
|
docker push $registry/$repository:$commit_tag
|
|
|
|
|
|
|
|
deploy:
|
|
|
|
name: Deploy image
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
environment: ${{ inputs.environment }}
|
|
|
|
needs: push_docker_image
|
|
|
|
if: |
|
|
|
|
always() &&
|
|
|
|
needs.push_docker_image.result == 'success'
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Configure AWS credentials
|
|
|
|
uses: aws-actions/configure-aws-credentials@v3
|
|
|
|
with:
|
|
|
|
aws-region: ${{ env.aws_region }}
|
|
|
|
role-to-assume: ${{ env.app_repo_role }}
|
|
|
|
|
|
|
|
- name: Login to Amazon ECR
|
|
|
|
id: ecr-login
|
|
|
|
uses: aws-actions/amazon-ecr-login@v1
|
|
|
|
with:
|
|
|
|
mask-password: 'true'
|
|
|
|
|
|
|
|
- name: Get timestamp
|
|
|
|
id: timestamp
|
|
|
|
run: echo "timestamp=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV
|