Skip to content

Commit

Permalink
Added Our Modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Guhan-SenSam committed Jun 16, 2024
1 parent 2763591 commit fb81c7d
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 4 deletions.
105 changes: 105 additions & 0 deletions .github/workflows/prod-deploy-task.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"taskDefinitionArn": "arn:aws:ecs:ap-south-1:732163342771:task-definition/EMS-Prod:47",
"containerDefinitions": [
{
"name": "HRMS",
"image": "732163342771.dkr.ecr.ap-south-1.amazonaws.com/ems-horilla-prod:d67723699f7ec03e48621578222c4533ba55a655",
"cpu": 0,
"portMappings": [
{
"name": "primary-port",
"containerPort": 8000,
"hostPort": 8000,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"environmentFiles": [
{
"value": "arn:aws:s3:::ems-env-prod/.env",
"type": "s3"
}
],
"mountPoints": [
{
"sourceVolume": "ems-media",
"containerPath": "/ems/media",
"readOnly": false
}
],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/EMS-Prod",
"awslogs-region": "ap-south-1",
"awslogs-stream-prefix": "ecs"
},
"secretOptions": []
}
}
],
"family": "EMS-Prod",
"executionRoleArn": "arn:aws:iam::732163342771:role/ecsTaskExecutionRole",
"networkMode": "bridge",
"revision": 47,
"volumes": [
{
"name": "ems-media",
"dockerVolumeConfiguration": {
"scope": "shared",
"autoprovision": false,
"driver": "local"
}
}
],
"status": "ACTIVE",
"requiresAttributes": [
{
"name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
},
{
"name": "ecs.capability.execution-role-awslogs"
},
{
"name": "com.amazonaws.ecs.capability.ecr-auth"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
},
{
"name": "ecs.capability.env-files.s3"
},
{
"name": "ecs.capability.docker-plugin.local"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.25"
},
{
"name": "ecs.capability.execution-role-ecr-pull"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.29"
}
],
"placementConstraints": [],
"compatibilities": [
"EC2"
],
"requiresCompatibilities": [
"EC2"
],
"cpu": "256",
"memory": "256",
"runtimePlatform": {
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
},
"registeredAt": "2024-02-27T05:13:10.313Z",
"registeredBy": "arn:aws:iam::732163342771:root",
"tags": []
}
58 changes: 58 additions & 0 deletions .github/workflows/prod-deploy-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Deploy to Production Network

on:
push:
branches:
- Production
workflow_dispatch:

jobs:
Deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- 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: ap-south-1

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

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
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: Update New Image ID in ECS Task Definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ./.github/workflows/prod-deploy-task.json
container-name: HRMS
image: ${{ steps.build-image.outputs.image }}

- name: Stop All tasks on ECS Cluster
continue-on-error: true
run: aws ecs stop-task --cluster "EmsProd" --task $(aws ecs list-tasks --cluster "EmsProd" --service "HRMS-Prod" --output text --query taskArns[0])

- 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: HRMS-Prod
cluster: EmsProd
wait-for-service-stability: false
force-new-deployment: true
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ WORKDIR /app/

COPY . .

RUN chmod +x /app/entrypoint.sh

RUN pip install -r requirements.txt

EXPOSE 8000
COPY media/ /media
RUN rm -rf ./media

CMD ["python3", "manage.py", "runserver"]
EXPOSE 8000
RUN chmod +x /app/entrypoint.sh
CMD ["/app/entrypoint.sh"]
Binary file removed TestDB_Horilla.sqlite3
Binary file not shown.
1 change: 1 addition & 0 deletions horilla/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"payroll",
"widget_tweaks",
"django_apscheduler",
"webhook_handler"
]
APSCHEDULER_DATETIME_FORMAT = "N j, Y, f:s a"

Expand Down
2 changes: 2 additions & 0 deletions webhook_handler/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import handlers
default_app_config = 'webhook_handler.apps.WebhookHandlerConfig'
3 changes: 3 additions & 0 deletions webhook_handler/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
9 changes: 9 additions & 0 deletions webhook_handler/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# webhook_handler/apps.py
from django.apps import AppConfig

class WebhookHandlerConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'webhook_handler'

def ready(self):
import webhook_handler.handlers # noqa
31 changes: 31 additions & 0 deletions webhook_handler/handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# webhook_handler/handlers.py
from django.dispatch import receiver
from django.db.models.signals import post_save
import requests
import json
import os

@receiver(post_save)
# Webhook triggered when a new candidate is created
def handle_model_update(sender, created, instance, **kwargs):
if sender.__name__ == 'Candidate' and created:
# send a request to the webhook
url = os.environ.get("WEBHOOK_URL_NEW_CANDIDATE")
data = {
"username": 'Oxlac HRMS',
"avatar_url": "https://oxlac.com/favicon.png",
"embeds": [
{
"author": {
"name": "Oxlac HRMS",
"url": "https://oxlac.com",
"icon_url": "https://oxlac.com/favicon.png"
},
"title": "New Candidate has applied for position " + str(instance.job_position_id),
"url": "https://employee.oxlac.com/candidate-view/" + str(instance.recruitment_id)+"/",
"description": "Candidate Name: " + instance.name + "\n" + "Email: " + instance.email,
}
]
}
# send the request
requests.post(url, data=json.dumps(data), headers={"Content-Type": "application/json"})
Empty file.
3 changes: 3 additions & 0 deletions webhook_handler/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions webhook_handler/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions webhook_handler/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.

0 comments on commit fb81c7d

Please sign in to comment.