Skip to content

Merge pull request #39 from Monamoxie/dependabot/npm_and_yarn/fronten… #443

Merge pull request #39 from Monamoxie/dependabot/npm_and_yarn/fronten…

Merge pull request #39 from Monamoxie/dependabot/npm_and_yarn/fronten… #443

Workflow file for this run

name: Metton Workflow
on:
push:
branches: ["master"]
pull_request:
branches: ["master"]
env:
ECS_TASK_DEFINITION: ./.aws/ecs-task-definition.json
IMAGE_TAG: latest
PROJECT_NAME: metton
ECS_CLUSTER: default
ECS_SERVICE: ecs-service
ECR_REPOSITORY: default
# ECR_REGISTRY: ${{ secrets.AWS_ECR_REGISTRY }}
ECR_REGISTRY: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com
jobs:
app-deployment:
name: Metton Deployment
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Change to the root directory
run: cd ${{ github.workspace }}
# - name: Start containers
# run: docker-compose up --build -d
# - name: Check All Container status
# run: docker ps -a
# - name: Stop containers
# run: docker-compose down -v
- 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: ${{ vars.AWS_REGION }}
- name: Login to AWS ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
mask-password: "true"
env:
AWS_REGISTRY: $ECR_REGISTRY
- name: Deploy to ECR
id: build-image
run: |
services=$(docker compose config --services)
for service in $services; do
if [[ "$service" != "rabbitmq" && "$service" != "postgres" ]]; then
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$service-$IMAGE_TAG -f ./.docker/Dockerfile.$service .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$service-$IMAGE_TAG
fi
done
- name: Generate ECS Task Definition from Template
env:
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
run: |
jq --arg aws_account_id "${{ env.AWS_ACCOUNT_ID }}" \
--arg aws_region "${{ vars.AWS_REGION }}" \
--arg aws_static_root_id "${{ vars.AWS_STATIC_ROOT_ID }}" \
--arg aws_media_root_id "${{ vars.AWS_MEDIA_ROOT_ID }}" \
'.executionRoleArn |= "arn:aws:iam::\($aws_account_id):role/ecsTaskExecutionRole" |
.taskRoleArn |= "arn:aws:iam::\($aws_account_id):role/ecsTaskExecutionRole" |
.containerDefinitions[0].logConfiguration.options["awslogs-region"] |= $aws_region |
.containerDefinitions[1].logConfiguration.options["awslogs-region"] |= $aws_region |
.volumes[0].efsVolumeConfiguration.fileSystemId |= $aws_static_root_id |
.volumes[1].efsVolumeConfiguration.fileSystemId |= $aws_media_root_id |
(.containerDefinitions[0].secrets[] |= (.valueFrom |= gsub("\\$\\{AWS_REGION\\}"; $aws_region))) |
(.containerDefinitions[1].secrets[] |= (.valueFrom |= gsub("\\$\\{AWS_REGION\\}"; $aws_region))) |
(.containerDefinitions[0].secrets[] |= (.valueFrom |= gsub("\\$\\{AWS_ACCOUNT_ID\\}"; $aws_account_id))) |
(.containerDefinitions[1].secrets[] |= (.valueFrom |= gsub("\\$\\{AWS_ACCOUNT_ID\\}"; $aws_account_id)))' \
./.aws/ecs-task-template.json > ./.aws/ecs-task-definition.json
- name: Python ECS task definition
id: python-task-def
uses: aws-actions/[email protected]
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: python_container
image: ${{ secrets.AWS_ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:python-${{ env.IMAGE_TAG }}
- name: Nginx ECS task definition
id: nginx-task-def
uses: aws-actions/[email protected]
with:
task-definition: ${{ steps.python-task-def.outputs.task-definition }}
container-name: nginx_container
image: ${{ secrets.AWS_ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:nginx-${{ env.IMAGE_TAG }}
- name: Deploy ECS
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.nginx-task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: false