Skip to content

Commit

Permalink
fix cicd
Browse files Browse the repository at this point in the history
  • Loading branch information
piyush7833 committed Jun 10, 2024
1 parent 1db4e7c commit 7c03039
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- main

jobs:
lint:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # Checks project source code into the container
Expand Down
136 changes: 53 additions & 83 deletions .github/workflows/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- main

jobs:
build:
Test:
runs-on: ubuntu-latest
steps:
- name: Check out the code
Expand All @@ -32,6 +32,18 @@ jobs:
cd test
go test -run TestOrder
Build:
runs-on: ubuntu-latest
needs: Test
steps:
- name: Check out the code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.22.2

- name: Build and push Docker image
if: |
github.event_name == 'push' &&
Expand All @@ -45,87 +57,45 @@ jobs:
echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
docker build --build-arg JWT_SECRET=${JWT_SECRET} --build-arg DB_URI=${DB_URI} -t piyush7833/chat-api:latest .
docker push piyush7833/chat-api:latest
- name: Update ECS task definition and service
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
ECS_CLUSTER: ${{ secrets.ECS_CLUSTER }}
ECS_SERVICE: ${{ secrets.ECS_SERVICE }}
ECS_TASK_DEFINITION: ${{ secrets.ECS_TASK_DEFINITION }}
ECR_IMAGE_URI: ${{ secrets.AWS_ECR_IMAGE_URL }}
run: |
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_IMAGE_URI
docker tag piyush7833/chat-api:latest $ECR_IMAGE_URI/chat-api:latest
docker push $ECR_IMAGE_URI/chat-api:latest
echo "Fetching current task definition"
TASK_DEFINITION_JSON=$(aws ecs describe-task-definition --task-definition $ECS_TASK_DEFINITION)

echo "Updating task definition with new image"
NEW_TASK_DEF_JSON=$(echo $TASK_DEFINITION_JSON | jq --arg IMAGE_URI "$ECR_IMAGE_URI:latest" '.taskDefinition | .containerDefinitions[0].image=$IMAGE_URI')

echo "Registering new task definition"
NEW_TASK_DEF_FAMILY=$(echo $NEW_TASK_DEF_JSON | jq -r .family)
NEW_TASK_DEF=$(aws ecs register-task-definition \
--family $NEW_TASK_DEF_FAMILY \
--task-role-arn $(echo $NEW_TASK_DEF_JSON | jq -r .taskRoleArn) \
--execution-role-arn $(echo $NEW_TASK_DEF_JSON | jq -r .executionRoleArn) \
--network-mode $(echo $NEW_TASK_DEF_JSON | jq -r .networkMode) \
--container-definitions "$(echo $NEW_TASK_DEF_JSON | jq -r .containerDefinitions)" \
--requires-compatibilities "$(echo $NEW_TASK_DEF_JSON | jq -r .requiresCompatibilities)" \
--cpu $(echo $NEW_TASK_DEF_JSON | jq -r .cpu) \
--memory $(echo $NEW_TASK_DEF_JSON | jq -r .memory))

NEW_TASK_DEF_ARN=$(echo $NEW_TASK_DEF | jq -r .taskDefinition.taskDefinitionArn)

echo "Updating ECS service to use the new task definition"
aws ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --task-definition $NEW_TASK_DEF_ARN


# aws configure AWS-ACCESS-KEY-ID $AWS_ACCESS_KEY_ID set AWS-SECRET-ACCESS-KEY $AWS_SECRET_ACCESS_KEY set region $AWS_REGION
# deploy:
# runs-on: ubuntu-latest
# needs: build
# steps:
# - name: Update ECS task definition and service
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_REGION: ${{ secrets.AWS_REGION }}
# ECS_CLUSTER: ${{ secrets.ECS_CLUSTER }}
# ECS_SERVICE: ${{ secrets.ECS_SERVICE }}
# ECS_TASK_DEFINITION: ${{ secrets.ECS_TASK_DEFINITION }}
# ECR_IMAGE_URI: ${{ secrets.AWS_ECR_IMAGE_URL }}
# # IMAGE_URI: piyush7833/chat-api:latest
# run: |
# aws ecr get-login-password --region eu-north-1 | docker login --username AWS --password-stdin $ECR_IMAGE_URI
# docker tag piyush7833/chat-api:latest $ECR_IMAGE_URI:latest
# docker push $ECR_IMAGE_URI:latest

# echo "Fetching current task definition"
# TASK_DEFINITION_JSON=$(aws ecs describe-task-definition --task-definition $ECS_TASK_DEFINITION)

# echo "Updating task definition with new image"
# NEW_TASK_DEF_JSON=$(echo $TASK_DEFINITION_JSON | jq --arg IMAGE_URI "$ECR_IMAGE_URI" '.taskDefinition | .containerDefinitions[0].image=$ECR_IMAGE_URI')

# echo "Registering new task definition"
# NEW_TASK_DEF_FAMILY=$(echo $NEW_TASK_DEF_JSON | jq -r .family)
# NEW_TASK_DEF=$(aws ecs register-task-definition \
# --family $NEW_TASK_DEF_FAMILY \
# --task-role-arn $(echo $NEW_TASK_DEF_JSON | jq -r .taskRoleArn) \
# --execution-role-arn $(echo $NEW_TASK_DEF_JSON | jq -r .executionRoleArn) \
# --network-mode $(echo $NEW_TASK_DEF_JSON | jq -r .networkMode) \
# --container-definitions "$(echo $NEW_TASK_DEF_JSON | jq -r .containerDefinitions)" \
# --requires-compatibilities "$(echo $NEW_TASK_DEF_JSON | jq -r .requiresCompatibilities)" \
# --cpu $(echo $NEW_TASK_DEF_JSON | jq -r .cpu) \
# --memory $(echo $NEW_TASK_DEF_JSON | jq -r .memory))

# NEW_TASK_DEF_ARN=$(echo $NEW_TASK_DEF | jq -r .taskDefinition.taskDefinitionArn)
# echo "Updating ECS service to use the new task definition"
# aws ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --task-definition $NEW_TASK_DEF_ARN
# AWS INSTANCES ARE NOT FREE, SO I AM COMMENTING THIS CODE

# - name: Update ECS task definition and service
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_REGION: ${{ secrets.AWS_REGION }}
# ECS_CLUSTER: ${{ secrets.ECS_CLUSTER }}
# ECS_SERVICE: ${{ secrets.ECS_SERVICE }}
# ECS_TASK_DEFINITION: ${{ secrets.ECS_TASK_DEFINITION }}
# ECR_IMAGE_URI: ${{ secrets.AWS_ECR_IMAGE_URL }}
# run: |
# aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_IMAGE_URI
# docker tag piyush7833/chat-api:latest $ECR_IMAGE_URI/chat-api:latest
# docker push $ECR_IMAGE_URI/chat-api:latest

# echo "Fetching current task definition"
# TASK_DEFINITION_JSON=$(aws ecs describe-task-definition --task-definition $ECS_TASK_DEFINITION)

# echo "Updating task definition with new image"
# NEW_TASK_DEF_JSON=$(echo $TASK_DEFINITION_JSON | jq --arg IMAGE_URI "$ECR_IMAGE_URI:latest" '.taskDefinition | .containerDefinitions[0].image=$IMAGE_URI')

# echo "Registering new task definition"
# NEW_TASK_DEF_FAMILY=$(echo $NEW_TASK_DEF_JSON | jq -r .family)
# NEW_TASK_DEF=$(aws ecs register-task-definition \
# --family $NEW_TASK_DEF_FAMILY \
# --task-role-arn $(echo $NEW_TASK_DEF_JSON | jq -r .taskRoleArn) \
# --execution-role-arn $(echo $NEW_TASK_DEF_JSON | jq -r .executionRoleArn) \
# --network-mode $(echo $NEW_TASK_DEF_JSON | jq -r .networkMode) \
# --container-definitions "$(echo $NEW_TASK_DEF_JSON | jq -r .containerDefinitions)" \
# --requires-compatibilities "$(echo $NEW_TASK_DEF_JSON | jq -r .requiresCompatibilities)" \
# --cpu $(echo $NEW_TASK_DEF_JSON | jq -r .cpu) \
# --memory $(echo $NEW_TASK_DEF_JSON | jq -r .memory))

# NEW_TASK_DEF_ARN=$(echo $NEW_TASK_DEF | jq -r .taskDefinition.taskDefinitionArn)

# echo "Updating ECS service to use the new task definition"
# aws ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --task-definition $NEW_TASK_DEF_ARN

4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.0
hooks:
- id: go-fmt
- id: go-imports
- id: no-go-testing
- id: golangci-lint
- id: go-unit-tests
- id: go-unit-tests
Binary file modified README.md
Binary file not shown.
2 changes: 1 addition & 1 deletion models/alter_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ ALTER TABLE "Status" ADD CONSTRAINT "FK_Status_userId_User_id" FOREIGN KEY ("use

ALTER TABLE "Tag" ADD CONSTRAINT "FK_Tag_messageId_Message_id" FOREIGN KEY ("messageId") REFERENCES "Message" ("id") ON DELETE SET NULL;
ALTER TABLE "Tag" ADD CONSTRAINT "FK_Tag_mediaId_Media_id" FOREIGN KEY ("mediaId") REFERENCES "Media" ("id") ON DELETE SET NULL;
ALTER TABLE "Tag" ADD CONSTRAINT "FK_Tag_reminderId_Reminder_id" FOREIGN KEY ("reminderId") REFERENCES "Reminder" ("id") ON DELETE SET NULL;
ALTER TABLE "Tag" ADD CONSTRAINT "FK_Tag_reminderId_Reminder_id" FOREIGN KEY ("reminderId") REFERENCES "Reminder" ("id") ON DELETE SET NULL;
2 changes: 1 addition & 1 deletion models/block.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ CREATE TABLE IF NOT EXISTS "Block" (
"updatedAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT "unique_blocker_blocked_pair" UNIQUE ("blockerId", "blockedId"),
PRIMARY KEY ("id")
);
);
2 changes: 1 addition & 1 deletion models/call.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ CREATE TABLE IF NOT EXISTS "Call" (
"updatedAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT "unique_call_at_time_by_same_users" UNIQUE ("callerId", "receiverId", "createdAt"),
PRIMARY KEY ("id")
);
);
2 changes: 1 addition & 1 deletion models/friend_request.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ CREATE TABLE IF NOT EXISTS "FriendRequest" (
"updatedAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT "unique_sender_receiver_pair" UNIQUE ("senderId", "receiverId"),
PRIMARY KEY ("id")
);
);
2 changes: 1 addition & 1 deletion models/message.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ CREATE TABLE IF NOT EXISTS "Message" (
"createdAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
"updatedAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY ("id")
);
);
2 changes: 1 addition & 1 deletion models/reminder.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ CREATE TABLE IF NOT EXISTS "Reminder" (
"createdAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
"updatedAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY ("id")
);
);
2 changes: 1 addition & 1 deletion models/status.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ CREATE TABLE IF NOT EXISTS "Status" (
"createdAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
"updatedAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY ("id")
);
);
2 changes: 1 addition & 1 deletion models/user.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ CREATE TABLE IF NOT EXISTS "User" (
"createdAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
"updatedAt" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY ("id")
);
);

0 comments on commit 7c03039

Please sign in to comment.