Skip to content

Commit

Permalink
Static staging deployment workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
sshrihar committed Mar 1, 2024
1 parent 0d1193f commit 4b7761b
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/staging_deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: static-staging
on:
push:
branches: ['staging']
workflow_dispatch:
env:
AWS_REGION: eu-west-1
ECR_REPOSITORY: static-staging-ecr
ECS_SERVICE: static-staging-ecs-service
ECS_CLUSTER: frontend-staging-ecs-cluster
ECS_TASK_DEFINITION: staging-taskdef.json
CONTAINER_NAME: static-staging

jobs:
deploy:
name: static-staging-deploy-job
permissions:
id-token: write
contents: write
environment: staging
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: arn:aws:iam::042947190491:role/static-staging-GithubActionsRole
role-session-name: GithubActionsSession

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- 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: |
docker build -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: ${{ env.ECS_TASK_DEFINITION }}
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
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM nginx:alpine

COPY . /usr/share/nginx/html
RUN rm -rf /usr/share/nginx/html/.git*

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
143 changes: 143 additions & 0 deletions staging-taskdef.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"requiresCompatibilities": [
"FARGATE"
],
"inferenceAccelerators": [],
"containerDefinitions": [
{
"dnsSearchDomains": null,
"environmentFiles": [],
"logConfiguration": {
"logDriver": "awsfirelens",
"options": {
"Name": "datadog",
"Host": "http-intake.logs.datadoghq.com",
"dd_service": "static-staging",
"dd_source": "nodejs",
"TLS": "on",
"provider": "ecs"
},
"secretOptions": [
{
"name": "apiKey",
"valueFrom": "arn:aws:ssm:$region:070528468658:parameter/DATADOG_APIKEY"
}
]
},
"entryPoint": null,
"portMappings": [
{
"hostPort": 80,
"protocol": "tcp",
"containerPort": 80
}
],
"command": null,
"linuxParameters": null,
"cpu": 0,
"environment": null,
"resourceRequirements": null,
"ulimits": null,
"dnsServers": null,
"mountPoints": null,
"workingDirectory": null,
"secrets": [],
"dockerSecurityOptions": null,
"memory": null,
"memoryReservation": null,
"volumesFrom": null,
"stopTimeout": null,
"image": "nginx:latest",
"startTimeout": null,
"firelensConfiguration": null,
"dependsOn": null,
"disableNetworking": null,
"interactive": null,
"healthCheck": null,
"essential": true,
"links": null,
"hostname": null,
"extraHosts": null,
"pseudoTerminal": null,
"user": null,
"readonlyRootFilesystem": null,
"dockerLabels": null,
"systemControls": null,
"privileged": null,
"name": "static-staging",
"repositoryCredentials": {
"credentialsParameter": ""
}
},
{
"essential": true,
"image": "amazon/aws-for-fluent-bit:stable",
"name": "log_router",
"firelensConfiguration": {
"type": "fluentbit",
"options": {
"enable-ecs-log-metadata": "true"
}
},
"environment": null,
"secrets": null,
"memoryReservation": 50,
"resourceRequirements": null,
"portMappings": [],
"environmentFiles": [],
"mountPoints": null,
"volumesFrom": null,
"hostname": null,
"user": null,
"workingDirectory": null,
"extraHosts": null,
"logConfiguration": null,
"ulimits": null,
"dockerLabels": null,
"dependsOn": null,
"repositoryCredentials": {
"credentialsParameter": ""
}
}
],
"volumes": [],
"networkMode": "awsvpc",
"memory": "1024",
"cpu": "512",
"executionRoleArn": "arn:aws:iam::070528468658:role/static-staging-TaskRole",
"family": "static-staging-taskdefinition",
"taskRoleArn": "arn:aws:iam::070528468658:role/static-staging-TaskRole",
"runtimePlatform": {
"operatingSystemFamily": "LINUX"
},
"tags": [
{
"key": "Role",
"value": "frontend-application"
},
{
"key": "Environment",
"value": "staging"
},
{
"key": "Service",
"value": "static-staging"
},
{
"key": "Host",
"value": "AWS"
},
{
"key": "IAC",
"value": "terraform-aws-test-applications-eu-west-1-apps-static-staging-polygon-technology"
},
{
"key": "Team",
"value": "product-apps"
},
{
"key": "Name",
"value": "static-staging-taskdefinition"
}
]
}

0 comments on commit 4b7761b

Please sign in to comment.