Skip to content

Commit

Permalink
Remove resources from blogs url
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sumi-k committed Sep 18, 2023
1 parent b387090 commit 50ab7eb
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 42 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: DeployDev

on:
repository_dispatch:
types: [deploy-blog-dev]
push:
branches:
- "master"

jobs:
deploy-dev:
Expand All @@ -30,7 +30,6 @@ jobs:
cd nginx
sed -i "s|WEBSITE_URL|dev-stack.canopas.com|g" conf.d/default.conf
sed -i "s|API_URL|dev-stack-api.canopas.com|g" conf.d/default.conf
sed -i "s|ARTICLES_URL|development.dzkjozipsd9ra.amplifyapp.com|g" conf.d/default.conf
bash ./../deploy/deploy-ecr-image.sh dev-nginx ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com/canopas-website-nginx
- name: Build frontend and push on ECR
Expand All @@ -51,6 +50,12 @@ jobs:
run: |
bash ./deploy/deploy-ecr-image.sh dev-backend ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com/canopas-website-backend
- name: Get latest blog image tag
id: get_blog_image_tag
run: |
aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-south-1.amazonaws.com
echo "::set-output name=blogImageTag::$(aws ecr describe-images --repository-name canopas-blog --output text --query 'sort_by(imageDetails,& imagePushedAt)[*].imageTags[*]' | grep -w 'dev' | tr '\t' '\n' | tail -1)"
- name: Deploy cloudformation stack
id: canopas-website-dev-ECS-EC2-stack
uses: aws-actions/aws-cloudformation-github-deploy@v1
Expand Down Expand Up @@ -84,4 +89,5 @@ jobs:
ClusterName=canopas-website-dev,
ImageTag=${{ github.sha }}-${{ github.run_attempt }}-dev-frontend,
BackendImageTag=${{ github.sha }}-${{ github.run_attempt }}-dev-backend,
NginxImageTag=${{ github.sha }}-${{ github.run_attempt }}-dev-nginx
NginxImageTag=${{ github.sha }}-${{ github.run_attempt }}-dev-nginx,
BlogImageTag=${{steps.get_blog_image_tag.outputs.blogImageTag}}
16 changes: 12 additions & 4 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: DeployProd
on:
repository_dispatch:
types: [deploy-blog-prod]
push:
branches:
- "master"

jobs:
deploy-prod:
runs-on: ubuntu-latest
Expand All @@ -29,7 +31,6 @@ jobs:
cd nginx
sed -i "s|WEBSITE_URL|canopas.com|g" conf.d/default.conf
sed -i "s|API_URL|prod-stack-api.canopas.com|g" conf.d/default.conf
sed -i "s|ARTICLES_URL|articles.canopas.com|g" conf.d/default.conf
bash ./../deploy/deploy-ecr-image.sh prod-nginx ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com/canopas-website-nginx
- name: Build frontend and push on ECR
Expand All @@ -39,7 +40,7 @@ jobs:
mv src/config.prod.js src/config.js
sh ./../deploy/generate-sitemap.sh https://canopas.com https://prod-stack-api.canopas.com
bash ./../deploy/deploy-ecr-image.sh prod-frontend ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com/canopas-website-frontend
- name: Checkout
uses: actions/[email protected]

Expand All @@ -51,6 +52,12 @@ jobs:
run: |
bash ./deploy/deploy-ecr-image.sh prod-backend ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com/canopas-website-backend
- name: Get latest blog image tag
id: get_blog_image_tag
run: |
aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-south-1.amazonaws.com
echo "::set-output name=blogImageTag::$(aws ecr describe-images --repository-name canopas-blog --output text --query 'sort_by(imageDetails,& imagePushedAt)[*].imageTags[*]' | grep -w 'prod' | tr '\t' '\n' | tail -1)"
- name: Deploy cloudformation stack
id: canopas-website-prod-ECS-EC2-stack
uses: aws-actions/aws-cloudformation-github-deploy@v1
Expand Down Expand Up @@ -84,4 +91,5 @@ jobs:
ClusterName=canopas-website-prod,
ImageTag=${{ github.sha }}-${{ github.run_attempt }}-prod-frontend,
BackendImageTag=${{ github.sha }}-${{ github.run_attempt }}-prod-backend,
NginxImageTag=${{ github.sha }}-${{ github.run_attempt }}-prod-nginx
NginxImageTag=${{ github.sha }}-${{ github.run_attempt }}-prod-nginx,
BlogImageTag=${{steps.get_blog_image_tag.outputs.blogImageTag}}
69 changes: 42 additions & 27 deletions infrastructure/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,17 @@ Parameters:
NginxImageTag:
Type: String
Description: NGINX Docker image tag
BlogImageTag:
Type: String
Description: Blog Docker image tag

Resources:
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family:
Family:
Fn::Sub: canopas-website-${EnvName}-full-stack-task-definition
ExecutionRoleArn:
ExecutionRoleArn:
Fn::Sub: arn:aws:iam::${AWS::AccountId}:role/ecsTaskExecutionRole
NetworkMode: "bridge"
ContainerDefinitions:
Expand All @@ -92,7 +95,7 @@ Resources:
Memory: 128
Cpu: 128
Essential: true
Image:
Image:
Fn::Sub: ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/canopas-website-nginx:${NginxImageTag}
PortMappings:
- ContainerPort: 80
Expand All @@ -101,12 +104,13 @@ Resources:
Links:
- canopas-website-frontend
- canopas-website-backend
- canopas-blog

- Name: "canopas-website-frontend"
Memory: 512
Cpu: 512
Essential: true
Image:
Image:
Fn::Sub: ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/canopas-website-frontend:${ImageTag}
PortMappings:
- ContainerPort: 3080
Expand All @@ -117,68 +121,68 @@ Resources:
Memory: 256
Cpu: 256
Essential: true
Image:
Image:
Fn::Sub: ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/canopas-website-backend:${BackendImageTag}
Environment:
- Name: ENV
Value:
Value:
Fn::Sub: ${EnvName}
- Name: SENDER
Value:
Value:
Fn::Sub: ${Sender}
- Name: CONTACT_SENDER
Value:
Value:
Fn::Sub: ${ContactSender}
- Name: JOBS_RECEIVER
Value:
Value:
Fn::Sub: ${JobsReceiver}
- Name: CONTACT_RECEIVER
Value:
Value:
Fn::Sub: ${ContactReceiver}
- Name: ACCESS_KEY_ID
Value:
Value:
Fn::Sub: ${AccessKeyId}
- Name: SECRET_ACCESS_KEY
Value:
Value:
Fn::Sub: ${SecretAccessKey}
- Name: REGION
Value:
Value:
Fn::Sub: ${Region}
- Name: DB_USERNAME
Value:
Value:
Fn::Sub: ${DbUsername}
- Name: DB_PASSWORD
Value:
Value:
Fn::Sub: ${DbPassword}
- Name: DB_HOST
Value:
Value:
Fn::Sub: ${DbHost}
- Name: DB_PORT
Value:
Value:
Fn::Sub: ${DbPort}
- Name: DB_NAME
Value:
Value:
Fn::Sub: ${DbName}
- Name: RECAPTCHA_CONFIG_JSON_BASE64
Value:
Value:
Fn::Sub: ${RecaptchaConfigJSONBase64}
- Name: RECAPTCHA_SITE_KEY
Value:
Value:
Fn::Sub: ${RecaptchaSiteKey}
- Name: RECAPTCHA_PROJECT_ID
Value:
Value:
Fn::Sub: ${RecaptchaProjectId}
- Name: JOBS_SPREADSHEET_ID
Value:
Value:
Fn::Sub: ${JobsSpreadsheetId}
- Name: JOBS_SHEET_ID
Value:
Value:
Fn::Sub: ${JobsSheetId}
- Name: PERSONAL_ACCESS_TOKEN_GITHUB
Value:
Value:
Fn::Sub: ${GithubAccessToken}
- Name: RESOURCES_URL
Value:
Value:
Fn::Sub: ${ResourcesURL}
- Name: TZ
Value: UTC
Expand All @@ -189,16 +193,27 @@ Resources:
HostPort: 8080
Protocol: tcp

- Name: "canopas-blog"
Memory: 512
Cpu: 512
Essential: true
Image:
Fn::Sub: ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/canopas-blog:${BlogImageTag}
PortMappings:
- ContainerPort: 3000
HostPort: 3000
Protocol: tcp

ECSService:
Type: AWS::ECS::Service
Properties:
ServiceName: "canopas-website-full-stack"
LaunchType: EC2
Cluster:
Cluster:
Fn::Sub: ${ClusterName}
DesiredCount: 1
TaskDefinition:
Ref: "TaskDefinition"
DeploymentConfiguration:
MaximumPercent: 100
MinimumHealthyPercent: 0
MinimumHealthyPercent: 0
9 changes: 6 additions & 3 deletions nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ server {
}

location /resources {
proxy_ssl_server_name on;
proxy_pass https://ARTICLES_URL;
proxy_set_header Host ARTICLES_URL;
proxy_pass http://canopas-blog:3000/resources;
proxy_set_header Host $host;
}

location ~ ^/resources/([a-zA-Z0-9-]+)$ {
rewrite ^/resources/([a-zA-Z0-9-]+)$ /$1 permanent;
}
}

Expand Down
8 changes: 4 additions & 4 deletions vue-frontend/src/components/home-new/BlogSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,17 @@ export default {
.then((blogs) => {
blogs = blogs.data;
for (let i = 0; i < blogs.length; i++) {
for (const element of blogs) {
/** replace - to / in date as safari is not supporting this date format.
* get date in MMM DD, YYYY format
*/
blogs[i].pubDate = new Date(
blogs[i].pubDate.replace(/-/g, "/"),
element.pubDate = new Date(
element.pubDate.replace(/-/g, "/"),
).toLocaleDateString("en-US", {
month: "long",
day: "2-digit",
});
blogs[i].pubDate = blogs[i].pubDate.split(" ", 2);
element.pubDate = element.pubDate.split(" ", 2);
}
this.activeBlog = blogs[0];
this.blogs = blogs;
Expand Down

0 comments on commit 50ab7eb

Please sign in to comment.