<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ben Tran on Medium]]></title>
        <description><![CDATA[Stories by Ben Tran on Medium]]></description>
        <link>https://medium.com/@bentranz?source=rss-210d602123ae------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OErcLTZ-8z8aTqQCzi_Gfw.jpeg</url>
            <title>Stories by Ben Tran on Medium</title>
            <link>https://medium.com/@bentranz?source=rss-210d602123ae------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 13:47:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bentranz/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Setup Continuous Deployment Pipeline For AWS Elastic Beanstalk]]></title>
            <link>https://bentranz.medium.com/setup-continuous-deployment-pipeline-for-aws-elastic-beanstalk-5f8edb38d872?source=rss-210d602123ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f8edb38d872</guid>
            <category><![CDATA[aws-codepipeline]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[aws-elastic-beanstalk]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <dc:creator><![CDATA[Ben Tran]]></dc:creator>
            <pubDate>Thu, 14 Dec 2023 08:33:36 GMT</pubDate>
            <atom:updated>2024-06-13T17:06:15.205Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*l1PmM0zo2Za4ZP3sTOmfSg.png" /></figure><p>In <a href="https://bentranz.medium.com/deploy-dockerized-application-to-aws-elastic-beanstalk-f8a3cf2944a7">Part 1: Deploy the application to AWS EB using Docker platform</a>, we already covered the steps to deploy the dockerized application manually — run awsebcli’s commands manually each time when you want to trigger new deployment.</p><p>In this tutorial, we will setup automated deployment the AWS Elastic Beanstalk environment using AWS CodePipeline or GitHub Actions.</p><h4><strong>Scenario 1: Use AWS CodePipeline</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yHVI7zYM9pQpX54sVQIf2w.png" /></figure><p><strong>Manage IAM user permissions:</strong></p><p>Before using CodePipeline, ensure that your IAM user have necessary permissions — it is recommended to assign these permissions within an user group:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U2qZUJLKuTeC2JBqJy67dg.png" /></figure><p>AWSCodeStarConnectionsFullAccess custom inline policy content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bfe1d1eb92b5323deef89a2417b5061e/href">https://medium.com/media/bfe1d1eb92b5323deef89a2417b5061e/href</a></iframe><p>CodeBuildServiceRoleManagement custom inline policy content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f3bbbb4b27d02d0d1a0c34550c25cf0/href">https://medium.com/media/9f3bbbb4b27d02d0d1a0c34550c25cf0/href</a></iframe><p>Additionally, ensure that your IAM user have ServiceRoleManagement permission which already created in <a href="https://bentranz.medium.com/deploy-dockerized-application-to-aws-elastic-beanstalk-f8a3cf2944a7">previous guide</a>.</p><p><strong>Define build steps:</strong></p><p>Create buildspec.yml file in the root directory with the following content — This file is used to define the build phases and commands that AWS CodeBuild will execute when building your project:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73986b1092604a97c4c551dafcd6bffd/href">https://medium.com/media/73986b1092604a97c4c551dafcd6bffd/href</a></iframe><p>Notes:</p><ul><li>CODEBUILD_RESOLVED_SOURCE_VERSION value from AWS CodeBuild (<a href="https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html">ref doc</a>).</li><li>AWS_DEFAULT_REGION, AWS_ACCOUNT_ID, IMAGE_REPOSITORY are required to set in AWS CodeBuild environment variables configuration.</li><li>IMAGE_TAG is generated from the commit hash.</li></ul><p><strong>Setup AWS CodePipeline</strong></p><p>Open <a href="http://console.aws.amazon.com/codesuite/codepipeline/home">CodePipeline Console</a>, choose Create pipeline:</p><ol><li>Choose pipeline settings</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-46OZDOyNZae-m7zNDRKqw.png" /></figure><p>2. Add source stage: Choose source provider — support Github, Gitlab, Bitbucket, … In case you don&#39;t have any source provider connection, you can create a new one — click Connect to Github/Gitlab/Bitbucket button, then authorize provider access. Finally, choose the repository and branch name utilized within the pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GV1omfUtJGkR0AYLM8DR4Q.png" /></figure><p>3. Add build stage: Choose AWS CodeBuild as build provider, then create new CodeBuild project — which run commands defined in buildspec.yml we created in previous step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j8UBwVIxQY9gS3zZ6nsc2A.png" /></figure><p>Create a new AWS CodeBuild project: remember to set required environment variables’ value — In our case, we need to set value for AWS_DEFAULT_REGION, AWS_ACCOUNT_ID, IMAGE_REPOSITORY.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6vEyjlztITzMfbF2LX1KIg.png" /></figure><p>After creating CodeBuild project successfully, you need to add AmazonEC2ContainerRegistryPowerUser permission to the associated service role — In our case, it is named codebuild-crewcall-production-service-role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rSqtZUKfXvxoRMDMAFqs9Q.png" /></figure><p>4. Add deploy stage: Choose the target AWS Elastic Beanstalk environment that you wanna deploy to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0OC-sidbdRtgaQLnYcKkyw.png" /></figure><p>Finally, review all configurations again then Create pipeline. Once the pipeline is created, it will automatically execute. You can View logs to see the job progress and identify potential errors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-HfPuDtSs2zYeeZ2c-bsXA.png" /></figure><p>That’s all for creating AWS CodePipeline project to automate AWS Elastic Beanstalk environment deployment. Try to push a new commit to the source code repository to initiate another the pipeline workflow test.</p><h4>Scenario 2: Use GitHub Actions</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dPVmsDxy5RgVS4dyqBV95A.png" /></figure><p>It’s much easier to go with Github Actions, first you need to define the deployment workflow in .github/workflows/cd.yml like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee3a43d3c162a58314d98912545dba02/href">https://medium.com/media/ee3a43d3c162a58314d98912545dba02/href</a></iframe><p>With the GitHub Actions workflow provided above, your GitHub repository’s settings must set value for these environment secrets and variables.</p><p><strong>Notes:</strong> With above settings, GitHub Actions uses production environment when the workflow runs for main branch, otherwise it uses the staging environment. Therefore, it is necessary to configure the appropriate value for each environment.</p><ul><li>Environment secrets:</li></ul><pre>AWS_ACCESS_KEY_ID<br>AWS_SECRET_ACCESS_KEY<br>AWS_REGION</pre><ul><li>Environment variables:</li></ul><pre>EB_APP: crewcall-api<br>EB_ENV: crewcall-api-production<br>EB_BUCKET: elasticbeanstalk-[AWS_REGION]-[AWS_ACCOUNT_ID]<br>ECR_REGISTRY: [AWS_ACCOUNT_ID].dkr.ecr.[AWS_REGION].amazonaws.com<br>ECR_REPOSITORY: crewcall-api-production</pre><p>After adding correct values for environment secrets and variables, commit changes with GitHub Actions workflow definition, then push it to the target branch (main or develop) to trigger GitHub Actions workflow.</p><h4>Other Scenario</h4><p>If you’re using alternative CI/CD methods like GitlabCI, Jenkins, … You should be able to define the workflow easily by following these steps:</p><ul><li>Checkout source code.</li><li>Install awscli and config aws credentials.</li><li>Build Docker image and push it to AWS ECR.</li><li>Compress the needed application files/directories (.ebextensions directory, docker-compose.yml and nginx.conf file) with a unique version label, then upload it to elastic beanstalk S3 bucket.</li><li>Create new application version with S3 key of the uploaded file.</li><li>Trigger the deployment with new created application version.</li></ul><p>That&#39;s all for second part of this series. For the <a href="#">next part</a>, we will talk about SSL &amp; DNS configuration.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f8edb38d872" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Dockerized Application To AWS Elastic Beanstalk]]></title>
            <link>https://bentranz.medium.com/deploy-dockerized-application-to-aws-elastic-beanstalk-f8a3cf2944a7?source=rss-210d602123ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8a3cf2944a7</guid>
            <category><![CDATA[aws-elastic-beanstalk]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[nestjs]]></category>
            <dc:creator><![CDATA[Ben Tran]]></dc:creator>
            <pubDate>Wed, 01 Nov 2023 10:20:15 GMT</pubDate>
            <atom:updated>2024-01-17T10:25:57.429Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*30_MZgrhFDVEywuZma6GHQ.jpeg" /></figure><p>In this tutorial, I will provide a step-by-step walkthrough on deploying a dockerized application (NestJS API + PostgreSQL database) to AWS Elastic Beanstalk (AWS EB).</p><p>Don’t have much deep explanation of related services, so you should have fundamental understanding of IAM, EC2 (Load Balancing, Auto Scaling), RDS, S3, CloudWatch, CodePipeline, Route53, Certificate Manager, …</p><p>This guide includes 3 parts:</p><ul><li><a href="https://medium.com/@bentranz/deploy-dockerized-application-to-aws-elastic-beanstalk-f8a3cf2944a7">Part 1: Deploy Dockerized Application To AWS Elastic Beanstalk</a></li><li><a href="https://bentranz.medium.com/setup-continuous-deployment-pipeline-for-aws-elastic-beanstalk-5f8edb38d872">Part 2: Setup Continuous Deployment For AWS Elastic Beanstalk</a></li><li><a href="#">Part 3: Setup Custom Domain For AWS Elastic Beanstalk</a> (Coming soon)</li></ul><p>You can read more about AWS Elastic Beanstalk infrastructure here:</p><ul><li><a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/GettingStarted.html">Getting started</a></li><li><a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts.html">Concepts</a></li><li><a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker.html">AWS EB using Docker container</a></li><li><a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.managing.html">Managing AWS EB environment</a></li><li><a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html">Configuring AWS EB environment</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*9U4hh8QrVnv7kdyZbo3dIA.png" /><figcaption>Image from docs.aws.amazon.com</figcaption></figure><h4><strong>Manage </strong>IAM user <strong>permissions</strong></h4><p>Open <a href="https://console.aws.amazon.com/iam/home#/users">IAM — Users Console</a> (use root or iam user have sufficient permissions), then Create User with following permissions — it is recommended to assign these permissions within a user group:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0mj6DdpMWzTJ8QRdfyvHZg.png" /></figure><p>IAMOwnedView custom inline policy content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef8700168ccc582f3518eda43c44e67a/href">https://medium.com/media/ef8700168ccc582f3518eda43c44e67a/href</a></iframe><p>ServiceRoleManagement custom inline policy content (<a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-service.html">ref document</a>):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69133d7085a2e79f68a6e79799b8e132/href">https://medium.com/media/69133d7085a2e79f68a6e79799b8e132/href</a></iframe><h4>Manage<strong> AWS EB instance profiles (</strong><a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/iam-instanceprofile.html"><strong>r</strong>ef document</a><strong>)</strong></h4><p>Open <a href="https://console.aws.amazon.com/iam/home#/roles">IAM — Roles Console</a>, choose Create Role:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1-cRB7NU87YYP2TgdG8hcA.png" /></figure><p>Add permissions policies:</p><ul><li>AmazonEC2ContainerRegistryReadOnly</li><li>AWSElasticBeanstalkMulticontainerDocker</li><li>AWSElasticBeanstalkWebTier</li><li>AWSElasticBeanstalkWorkerTier</li></ul><p>Set the role name aws-elasticbeanstalk-ec2-role , then save it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qZ7HuFBZtJ3P3YqU2036vA.png" /></figure><h4>Manage AWS EB service roles (<a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/iam-servicerole.html">ref document</a>)</h4><p>Open <a href="https://console.aws.amazon.com/iam/home#/roles">IAM— Roles Console</a>, choose Create Role:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eiyfjc6BS1fgfKvyW3p4Rg.png" /></figure><p>Add permissions policies:</p><ul><li>AWSElasticBeanstalkEnhancedHealth</li><li>AWSElasticBeanstalkManagedUpdatesCustomerRolePolicy</li><li>AWSElasticBeanstalkService</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kIe8ms7LGOTFDk3QEMTq4g.png" /></figure><p>Set the role name to aws-elasticbeanstalk-service-role, then save it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9jFfsfVShKmQYDgoiXMQ7g.png" /></figure><h4>Setup CLIs &amp; AWS profiles</h4><p>Install awscli, awsebcli in macos:</p><pre>brew update<br><br># install awscli<br>brew install awscli<br>aws --version<br><br># install awsebcli<br>brew install awsebcli<br>eb --version</pre><p>Add aws profile to your awscli:</p><pre># Use: aws configure --profile AWS_PROFILE<br>aws configure --profile crewcall</pre><p>Then, fill in your Access key ID, Secret access key, Region— use the IAM account we already created in previous steps.</p><p><strong>Suggestion:</strong> I recommend using the project name for your AWS profile. This approach simplifies the management of multiple AWS profiles on your local machine, you won’t have to memorize which profile is used for each project.</p><p><strong>FYI:</strong> aws profiles are stored in ~/.aws/credentials and ~/.aws/config. This makes it easy to update your profile by modifying these files.</p><h4>Build Docker image</h4><p>In project root path, add Dockerfile file with the following content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/647959fd83fc02d8f6da1ac87caa71f9/href">https://medium.com/media/647959fd83fc02d8f6da1ac87caa71f9/href</a></iframe><p>Add .dockerignore file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/109eb39197d48bd756e30bafbf65892f/href">https://medium.com/media/109eb39197d48bd756e30bafbf65892f/href</a></iframe><p>Ensure your docker image is successfully built before proceeding to the next step:</p><pre>docker build --target production -t crewcall-api-production:latest .</pre><h4>Create AWS ECR R<strong>epository</strong></h4><p>Open ECR dashboard, create new private repository:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vf3HeXGpU8bcQsBIoxA1EA.png" /></figure><p>After creating, on the repository page you can find the push commands under View push commands. Moreover, you have the ability to view all the images that have been pushed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7wAyz8ouq65XO3ZyIHeB8A.png" /></figure><h4>Push your Docker image to ECR Repository</h4><p>Retrieve an authentication token and authenticate your docker client to your registry:</p><pre>aws ecr get-login-password --profile crewcall --region ap-southeast-1 | docker login --username AWS --password-stdin xxxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com</pre><p>Build your docker image using the following command. You can skip this step if your image is already built:</p><pre>docker build --target production -t crewcall-api-production:latest .</pre><p>After the build completes, create new tag for your image:</p><pre>docker tag crewcall-api-production:latest xxxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/crewcall-api-production:latest</pre><p>Push this image to your newly created AWS repository:</p><pre>docker push xxxxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/crewcall-api-production:latest</pre><p><strong>Suggestion: </strong>To reduce costs on ECR storage, you should configure a Lifecycle Policy that automatically deletes previous images. Let’s establish the rules that remove all untagged images &amp; keep only the most recent 5 images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0oyNkk5-5TU0sP7B0sCZgQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eSDM409uUK5dWbXJ-X_dAA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8M-BS5_RhPjRygiyhTPkaw.png" /></figure><h4>Build docker-compose.yml</h4><p>AWS Elastic Beanstalk with Docker environment require to have docker-compose.yml to run containers base on defined services. By default, EB will forward all requests to the machine directly to PORT 80. Therefore, your docker-compose.yml must include a mapping to port 80 on the host.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88ea7e0eb8f8a347e69f94b00c016ebf/href">https://medium.com/media/88ea7e0eb8f8a347e69f94b00c016ebf/href</a></iframe><p>In my scenario, there are two services:</p><ul><li>api<strong>: </strong>primary NestJS application.</li><li>nginx<strong>: </strong>reverse proxy support to serve public static files.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e80ff066c1c268b0e664398008b29051/href">https://medium.com/media/e80ff066c1c268b0e664398008b29051/href</a></iframe><p>Finally, ensure that your docker-compose.yml can execute without any issues on your local system: set environment variables, then run docker-compose up.</p><h4>Setup PostgreSQL database with AWS RDS</h4><p>Although EB does have integrated functionality to create an RDS instance, I believe it’s more straightforward if you set it up manually.</p><p>Follow the official document to create PostgreSQL database instance <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CreateDBInstance.html">here</a>. While creating, you need to pay attention to these settings:</p><ul><li><strong>Availability and durability</strong>: Depending on your application requirements, you can choose Multi-AZ DB instance (with one primary database instance) or Multi-AZ DB Cluster (with one primary database instance + 2 readable standby database instances).</li><li><strong>Credentials Settings: </strong>Provide the username and password for the database.</li><li><strong>DB instance class: </strong>Choose the database instance class. You can view the available classes in the list provided here: <a href="https://aws.amazon.com/rds/instance-types">https://aws.amazon.com/rds/instance-types</a>.</li><li><strong>Virtual private cloud (VPC):</strong> Choose Default VPC. Alternatively, you can use your own VPC if you have one.</li><li><strong>Public access: </strong>Choose No. Only Amazon EC2 instances and other resources inside the VPC can connect to your cluster.</li><li><strong>VPC security group (firewall): </strong>Choose Create New then provide the security group name.</li><li><strong>Additional configuration: </strong>Set Initial database name to ask RDS create it automatically. If not specified, you will need to create the database manually.</li></ul><p>After completed, you can get the connection endpoint and port in the main page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ft7rMIu9daX6rpS_Ri8JvQ.png" /></figure><h4>Init EB environment with sample application</h4><p>Go to AWS EB dashboard, create new environment with Docker platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J3yVREnKuQyyEghVBfPNXw.png" /></figure><p><strong>Configure service access:</strong> Select AWSEB service role and instance profile we already created before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t5c5ZS-yfNDNfCH889HxIw.png" /></figure><p><strong>Set up networking, database, and tags:</strong></p><ul><li>Use default VPC (you can use your own VPC if you have one).</li><li>Select all instance subnets &amp; active public IP address.</li><li>Regarding the database, you can ignore it as we have already configured it previously.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yyab97xoxlZ5clbRUgEyjA.png" /></figure><p><strong>Configure instance traffic and scaling:</strong></p><ul><li><strong>EC2 security groups:</strong> Leave it blank, EB will generate default security groups for the environment.</li><li><strong>Auto scaling group:</strong> Choose Load balanced environment type; Set Min — Max instances (set Min == Max should disable auto scaling trigger); Select instance types based on your application requirements (sufficient vCPUs and memory); Setup scaling trigger (metric on average CPUUtilization, ≥ 70% will trigger to add 1 more instance, ≤ 30% will trigger to remove 1 instance).</li><li><strong>Load balancer network settings: </strong>Set visibility to Public, select all available load balancer subnets.</li><li><strong>Load Balancer Type: </strong>Choose<strong> </strong>Application load balancer.</li><li><strong>Health Check Process:</strong> Default is / path.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EBlyyFuuKlC4FWSBV35ASw.png" /></figure><p><strong>Configure updates, monitoring and logging:</strong></p><ul><li><strong>Deployment Policy:</strong> Use Rolling policy for zero downtime deployment. Read more about deployment policies <a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.rolling-version-deploy.html">in this document</a>.</li><li><strong>Proxy server:</strong> Choose none . We already have nginx setup in docker compose.</li><li><strong>Instance log streaming to CloudWatch logs:</strong> Activated, select retention and lifecycle method.</li><li><strong>Environment properties:</strong> Skip for sample application, we can make changes later.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gjeLwowb5RxvnAoNkxTXzQ.png" /></figure><p>Then, double-check the configurations before proceeding to create and submit.</p><p>After creation is finished, you will have an environment dashboard similar to this one. You can visit the environment domain to see if the sample application can run successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HPYhdoDaBBIp3w5X-8VhDA.png" /></figure><p><strong>Viewing logs:</strong> You can check all deploy process, application run logs in CloudWatch — Log groups, mostly should focus on:</p><ul><li>/var/log/eb-engine.log — aws eb activity logs.</li><li>/var/log/eb-docker/containers/eb-current-app/stdouterr.log — all docker container logs.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iVCltf4jHJcQ14emCLvUIw.png" /></figure><p>Stream the logs in local machine:</p><pre>aws logs tail /aws/elasticbeanstalk/crewcall-api-production/var/log/eb-docker/containers/eb-current-app/stdouterr.log --follow --profile crewcall</pre><p>You can read more about viewing logs of EB environment in from <a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.logging.html">aws offical document</a>.</p><p><strong>Environment configuration: </strong>You can find or change any EB environment settings here.</p><p>Get main security group name of instances in the environment. Any resources used in the application (like RDS PostgreSQL, ElasticCache — Redis, …) need to have Inbound traffic rules with source to this security group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*byb2rry2R3qSy3opvVswdg.png" /></figure><h4>Deploy your application to created EB environment</h4><p>Edit RDS database security group Inbound rules: Choose Custom source, then add EC2 Security Groups of the EB environment to allowed list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BNGk1So5Ht1hUFRlrWzi0A.png" /></figure><p>Add required application ENVs to EB environment:</p><ul><li>Open environment Configuration</li><li>Edit Updates, monitoring, and logging</li><li>In Environment properties section, set all required environment variables, then Apply.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*JY6vAR1AFwth55V6PKrxUA.png" /></figure><p>Run eb init in your project directory to initialize an awsebcli repository: Choose the appropriate region and application to use, and disable CodeCommit.</p><pre>eb init --profile crewcall</pre><p><strong>Notes:</strong> This command generate changes the .gitignore. Please ensure to commit your changes.</p><p>Begin deploying your application to the EB environment:</p><pre># eb deploy EB_ENVIRONMENT --profile AWS_PROFILE<br>eb deploy crewcall-api-production --profile crewcall</pre><p>Wait until the deployment process is fully completed, and then recheck. If have any errors during deployment, you can investigate them using CloudWatch — Log groups.</p><p><strong>SSH access to EC2 instances — required to enable public IP Address in instance settings:</strong></p><pre># Setup keypair to instances<br>eb ssh crewcall-api-production --profile crewcall --setup<br><br># Connect to EC2 instances with created keypair<br>eb ssh crewcall-api-production --profile crewcall<br><br># Give root permission if you want to use docker commands<br>sudo su<br>docker ps<br>docker exec -it container_id_or_name sh<br><br># Most of service logs can be found in the /var/log directory.<br>cd /var/log<br><br># View docker container logs<br>tail -f /var/log/eb-docker/containers/eb-current-app/eb-stdouterr.log<br><br># View eb activity logs<br>tail -f /var/log/eb-engine.log</pre><p><strong>Smaller bundle zip file — optional:</strong></p><p>Normally, awsebcli use git archive to create bundle zip file — it excludes files specified in .gitignore and .git directory. However, with Docker platform, we need only docker-compose.yml and its related configuration files. To manage this, add .ebignore file with the following content.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3d6513750e08cbc5a62e1555b175f68/href">https://medium.com/media/b3d6513750e08cbc5a62e1555b175f68/href</a></iframe><p>Commit changes, then redeploy the application.</p><p><strong>Set application version lifecycle — optional:</strong> When you deploy code, EB creates a new application version in zip format and saves it in S3. To reduce S3 storage costs, we should restrict number of stored versions. Like ECR lifecycle policy, I keep only the latest 5 versions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3q1y2lUqCFKtwuWQ9FPUYg.png" /></figure><p>We already completed all necessary steps to deploy dockerized application to AWS EB environment. If there are changes in the source code, please follow these steps to redeploy the application:</p><ul><li>If you have introduced new ENVs, add them in both docker-compose.yml and EB environment settings.</li><li>Build and push new docker image to ECR.</li><li>Update docker-compose.yml file to use the newly created docker image.</li><li>Initiate the deployment by executing the command eb deploy EB_ENVIRONMENT --profile AWS_PROFILE.</li><li>Wait until the deployment is completed, then recheck to new code is working as expected.</li></ul><p>That&#39;s all for first part of this series, mostly all the steps are done manually using commands from local machine. For <a href="https://bentranz.medium.com/setup-continuous-deployment-pipeline-for-aws-elastic-beanstalk-5f8edb38d872">next part</a>, we will setup CI/CD for automated deployment using AWS CodePipeline or GitHub Actions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8a3cf2944a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[CopyCoder] Rails CI/CD With GitHub Actions]]></title>
            <link>https://bentranz.medium.com/copycoder-rails-ci-cd-with-github-actions-d43a73577a35?source=rss-210d602123ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/d43a73577a35</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[continuous-delivery]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[Ben Tran]]></dc:creator>
            <pubDate>Wed, 30 Nov 2022 08:44:17 GMT</pubDate>
            <atom:updated>2022-11-30T08:44:17.286Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*tbljcUKMLaQSpKol11fXKQ.png" /></figure><p>Typically, we have two workflows: Test &amp; Deploy.</p><p>The Test workflow will be triggered when you create a pull request or push directly to the main or develop branch. It will run these checks:</p><ul><li>Rubocop</li><li>Brakeman</li><li>ESlint</li><li>RSpec</li></ul><p>The Deploy workflow will be triggered only after the Test workflow run completed successfully in the main or develop branch.</p><p><em>Note: Currently, the </em><em>Deploy workflow only prints out some dummy text, based on your infrastructure you can replace it with the correct scripts to deploy your application.</em></p><p>Add .github/workflows/test.yml file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/514a9f96b9f9293e2527adde3ebea915/href">https://medium.com/media/514a9f96b9f9293e2527adde3ebea915/href</a></iframe><p>Add .github/workflows/deploy.yml file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6eb7cc3f6d0c949ff4397cbdddd804c/href">https://medium.com/media/d6eb7cc3f6d0c949ff4397cbdddd804c/href</a></iframe><p>Add RAILS_MASTER_KEY (or any other needed environment variables) secrets to GitHub repo. Go to Settings / Secrets / Actions , then New repository secret (Ref: <a href="https://docs.github.com/en/actions/security-guides/encrypted-secrets">https://docs.github.com/en/actions/security-guides/encrypted-secrets</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hbXWscEvSl81QmKhqqackg.png" /></figure><p>For setting secrets based on different environments (useful for deployment jobs), you can refer <a href="https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment">https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment</a></p><p>Finally, commit and push to GitHub, then see how it works!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d43a73577a35" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[CopyCoder] Running NestJS Test With GitHub Actions]]></title>
            <link>https://bentranz.medium.com/copycoder-running-nestjs-test-with-github-actions-c777c87f503d?source=rss-210d602123ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/c777c87f503d</guid>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[Ben Tran]]></dc:creator>
            <pubDate>Tue, 29 Nov 2022 09:41:08 GMT</pubDate>
            <atom:updated>2022-11-29T09:41:08.873Z</atom:updated>
            <content:encoded><![CDATA[<p>Our configuration trigger CI when you have a pull request or push directly to the main or develop branches. The CI will run these jobs:</p><ul><li>Lint</li><li>Build</li><li>Unit Test</li><li>E2E Test</li></ul><p>Add .github/workflows/ci.yml have the following content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8834dfa0d6d9323312bd6c8a0bf4941/href">https://medium.com/media/e8834dfa0d6d9323312bd6c8a0bf4941/href</a></iframe><p>Commit and push to github, then see how it works!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c777c87f503d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GitLab CI/CD Setup For Ruby On Rails Project]]></title>
            <link>https://bentranz.medium.com/gitlab-ci-cd-setup-for-ruby-on-rails-project-83dcda1b611b?source=rss-210d602123ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/83dcda1b611b</guid>
            <category><![CDATA[gitlab-ci]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Ben Tran]]></dc:creator>
            <pubDate>Wed, 29 Jun 2022 03:45:51 GMT</pubDate>
            <atom:updated>2022-11-29T09:41:57.688Z</atom:updated>
            <content:encoded><![CDATA[<h3>[CopyCoder] GitLab CI/CD Setup For Ruby On Rails Project</h3><p>Gitlab CI/CD for Rails project which allows running:</p><ul><li>Rubocop</li><li>ESlint (only used if Rails project has Javascript )</li><li>Brakeman</li><li>RSpec</li><li>Deploy</li></ul><p>Add .gitlab-ci.yml at project root path follow these content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc9fd426356b6ec4c3b512c51fce52e6/href">https://medium.com/media/dc9fd426356b6ec4c3b512c51fce52e6/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83dcda1b611b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create REST API with Ruby On Rails (Part 2)]]></title>
            <link>https://bentranz.medium.com/create-rest-api-with-ruby-on-rails-part-2-429ecc62d32?source=rss-210d602123ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/429ecc62d32</guid>
            <category><![CDATA[fast-json-api]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Ben Tran]]></dc:creator>
            <pubDate>Fri, 24 Jun 2022 10:59:26 GMT</pubDate>
            <atom:updated>2023-09-16T05:55:51.284Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xi-pZrcm0dLbsVFQYQII9w.png" /></figure><p>We already completed building a simple REST API in <a href="https://bentranz.medium.com/create-rest-api-with-ruby-on-rails-a97d42352c69">Part 1</a>. In this part, we will implement JSONAPI Render Module, which makes the process of rendering serialized json considerably quicker and simpler.</p><h4>JSONAPI Render Module</h4><p>Each time you serialize a single resource or resource collection, you must choose the appropriate serializer class for expected output json. We do like this a lot:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6aa3bc75ea21dcd2c5103b20b5242a46/href">https://medium.com/media/6aa3bc75ea21dcd2c5103b20b5242a46/href</a></iframe><p>To make rendering serialized json process easier, we should have a module that automatically choose the right serializer class base on the resource type, then response the serialized json to client.</p><p>Ok, Let’s do it!</p><p>Create file app/controllers/concerns/json_api_render.rb, app/controllers/concerns/pagination.rb with following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb56a24311e315083cee5701ea4b82ed/href">https://medium.com/media/eb56a24311e315083cee5701ea4b82ed/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d24e501eed528a6d4fcd591376821c0/href">https://medium.com/media/1d24e501eed528a6d4fcd591376821c0/href</a></iframe><p>Include JsonApiRender to ApplicationController, modify app/controllers/application_controller.rb to:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/782ab97bbe51600cec1763a4516f0fa4/href">https://medium.com/media/782ab97bbe51600cec1763a4516f0fa4/href</a></iframe><p>I won’t go into too much detail here because I believe you can comprehend the code above!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*Es3dqW-RFpDuepvUg641Dw.jpeg" /></figure><p>Using the functions of the JsonApiRender module</p><ul><li>Render resource collection:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dca63c9e3046d5d140c9189096853c93/href">https://medium.com/media/dca63c9e3046d5d140c9189096853c93/href</a></iframe><ul><li>Render resource collection with pagination:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbbed4b480e64b578f2e562de536470a/href">https://medium.com/media/fbbed4b480e64b578f2e562de536470a/href</a></iframe><ul><li>Render single resource:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/482924c1f82015df96d7183c0c29074b/href">https://medium.com/media/482924c1f82015df96d7183c0c29074b/href</a></iframe><p>Both render_resource_collection, render_resource methods support meta, links, include, params options also. These options are passed directly to the serializer class. You can learn more about serializer options from <a href="https://github.com/jsonapi-serializer/jsonapi-serializer">jsonapi-serializer gem documentation</a>. So, you can do something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abfbbe1eab707fe658f6c3ae6fcfe7ee/href">https://medium.com/media/abfbbe1eab707fe658f6c3ae6fcfe7ee/href</a></iframe><ul><li>Render resource errors (ActiveModel::Errors)</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8cfce5604dc2faf136d328cf7c4a73f7/href">https://medium.com/media/8cfce5604dc2faf136d328cf7c4a73f7/href</a></iframe><p>Apply the functions in JsonApiRender module to Api::V1::IdeasController</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee8eda05a2bf54ad060d7ba7497c5401/href">https://medium.com/media/ee8eda05a2bf54ad060d7ba7497c5401/href</a></iframe><p>Restart rails server and test your apis again.</p><p>Done!</p><p>You can clone final source code of part 2 from here:</p><p><a href="https://gitlab.com/tranquangvu/ideas-api/-/commits/part-2">Commits · part-2 · tranquangvu / ideas-api · GitLab</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=429ecc62d32" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create REST API with Ruby On Rails (Part 1)]]></title>
            <link>https://bentranz.medium.com/create-rest-api-with-ruby-on-rails-a97d42352c69?source=rss-210d602123ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/a97d42352c69</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[rest-api]]></category>
            <dc:creator><![CDATA[Ben Tran]]></dc:creator>
            <pubDate>Fri, 03 Jun 2022 10:01:11 GMT</pubDate>
            <atom:updated>2022-06-03T17:54:56.088Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*6UmdeUFpxiFNNDewvwO40w.png" /></figure><h4>What Is REST?</h4><p>Read this post <a href="https://www.codecademy.com/article/what-is-rest">https://www.codecademy.com/article/what-is-rest</a></p><h4>Init Rails API Only Project</h4><pre>rails new ideas-api --api --database=postgresql</pre><h4><em>Handle Cross-Origin Resource Sharing (CORS)</em></h4><p>Rails use rack-cors to avoid CORS issues when API is called from the frontend app (Read more: <a href="https://github.com/cyu/rack-cors">https://github.com/cyu/rack-cors</a>).</p><p>Add the following line to Gemfile, then run bundle install:</p><pre>gem &#39;rack-cors&#39;</pre><p>Insert rack CORS middleware to rails app. Create a file config/initializers/cors.rb with following content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8329035684328ca9560cceed95b85f3d/href">https://medium.com/media/8329035684328ca9560cceed95b85f3d/href</a></iframe><h4>Create Idea Resource</h4><p>Generate Idea model with these attributes: id, title, description, created_at, updated_at.</p><pre>rails g model Idea title:string description:text</pre><pre>rails db:migrate</pre><p>Add validations for Idea model, modify file app/models/idea.rb with following content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91c2c2113bd39b8701f36124a4761b5d/href">https://medium.com/media/91c2c2113bd39b8701f36124a4761b5d/href</a></iframe><p>Let&#39;s add some sample data, modify file db/seed.rb with below code then run rails db:seed (Note: I use <a href="https://github.com/faker-ruby/faker">faker</a> gem to generate dummy text):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/321d678601591f519aac4b8bf56ffddd/href">https://medium.com/media/321d678601591f519aac4b8bf56ffddd/href</a></iframe><h4>Build Idea APIs</h4><p>Config api routes, modify file config/routes.rb with following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9238cba04d02aeeec9556f2552a2e81/href">https://medium.com/media/d9238cba04d02aeeec9556f2552a2e81/href</a></iframe><p>Define Idea controller, create files app/controllers/api/v1/base_controller.rb , app/controllers/api/v1/ideas_controller.rb with following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f6b02c3a91cce8207cef81108eccfd4/href">https://medium.com/media/9f6b02c3a91cce8207cef81108eccfd4/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e5718f53492247ef659d7edec843777/href">https://medium.com/media/1e5718f53492247ef659d7edec843777/href</a></iframe><p>After this step, it&#39;s done for super basic REST API, you can boot up your server rails s and start to test your apis (I suggest to use <a href="https://www.postman.com/">Postman</a> app).</p><h4>Using JSONAPI Serializer To Render JSON</h4><p>Sometimes you want more control in what be in JSON response. This might be required for:</p><ul><li>Adding some custom (virtual) attributes to resource</li><li>Generating relationships between resources</li><li>Having standard formats like <a href="https://jsonapi.org/">JSONAPI</a></li></ul><p>It’s time for <a href="https://github.com/jsonapi-serializer/jsonapi-serializer">jsonapi-serializer</a>, <a href="https://github.com/stas/jsonapi.rb">jsonapi.rb</a> gems.</p><p>Add the following line to Gemfile, then run bundle install:</p><pre>gem &#39;jsonapi-serializer&#39;</pre><pre>gem &#39;jsonapi.rb&#39;</pre><p>Install jsonapi.rb for rails app, create a file config/initializers/jsonapi.rb with following lines:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65c7f175499f8dc8b7d8cbd6cc52ab78/href">https://medium.com/media/65c7f175499f8dc8b7d8cbd6cc52ab78/href</a></iframe><p>Define IdealSerializer by creating new files app/serializers/base_serializer.rb, app/serializers/idea_serializer.rb with following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/050796581660ba667e45e751b547e154/href">https://medium.com/media/050796581660ba667e45e751b547e154/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/705fcb4e039a621a932a45204a3308c3/href">https://medium.com/media/705fcb4e039a621a932a45204a3308c3/href</a></iframe><p>To apply serializer to json response, modify file app/controllers/api/v1/ideas_controller.rb like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14ddbc8488b36b12c5f5a91962417dd0/href">https://medium.com/media/14ddbc8488b36b12c5f5a91962417dd0/href</a></iframe><h4>Paginate Resource List Whenever You Can</h4><p>I strongly recommend you use <a href="https://github.com/ddnexus/pagy">pagy</a> gem to handle pagination. It has great performance, you can visit <a href="https://github.com/ddnexus/pagy">https://github.com/ddnexus/pagy</a> to see performance comparison with other gems.</p><p>Add the following line to Gemfile, then run bundle install:</p><pre>gem &#39;pagy&#39;</pre><p>Config your pagy, create a file config/initializers/pagy.rb with following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c112c81b3a68505cdbb7a88e417f96e8/href">https://medium.com/media/c112c81b3a68505cdbb7a88e417f96e8/href</a></iframe><p>Include Pagy::Backend to Api::V1::BaseController and add page_number, page_size methods to get pagination params.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec838b415e74b5ff7cf90fc1fffe46ff/href">https://medium.com/media/ec838b415e74b5ff7cf90fc1fffe46ff/href</a></iframe><p>Modify index method in app/controllers/api/v1/ideas_controller.rb:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0966e3fcd15487f37d46e4c7baba0bc2/href">https://medium.com/media/0966e3fcd15487f37d46e4c7baba0bc2/href</a></iframe><p>Restart rails server and test your apis again.</p><p>You can clone final source code of part 1 from here <a href="https://gitlab.com/tranquangvu/ideas-api/-/tree/part-1/">https://gitlab.com/tranquangvu/ideas-api/-/tree/part-1</a></p><p>Done!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a97d42352c69" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup ESLint & Prettier For Javascript Code In Ruby On Rails Project]]></title>
            <link>https://bentranz.medium.com/setup-eslint-prettier-for-javascript-code-in-ruby-on-rails-project-3f876b79fd4?source=rss-210d602123ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f876b79fd4</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[prettier]]></category>
            <category><![CDATA[eslint]]></category>
            <dc:creator><![CDATA[Ben Tran]]></dc:creator>
            <pubDate>Tue, 24 May 2022 10:31:31 GMT</pubDate>
            <atom:updated>2022-06-29T03:35:59.430Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*En9Y2JeFN-0PqqEnskX7QQ.png" /></figure><p>This guide helps you to set up ESLint &amp; Prettier for Javascript code in Ruby On Rails (≥ v5.0) project— Which has NodeJS + Webpack inside.</p><h4>What is ESLint &amp; Prettier?</h4><p>Please read the official sites to understand exactly what is ESLint &amp; Prettier :)))</p><ul><li><a href="https://eslint.org/">https://eslint.org</a></li><li><a href="https://prettier.io/">https://prettier.io</a></li></ul><h4><strong>1. Install Dependencies</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3e9522abe89407c60a61fa268fd8ca1/href">https://medium.com/media/e3e9522abe89407c60a61fa268fd8ca1/href</a></iframe><h4><strong>2. Add ESLint Configurations</strong></h4><p>Add .eslintrc at root of project &amp; give below content</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ca133224580b874c6f3baa44babb10e/href">https://medium.com/media/1ca133224580b874c6f3baa44babb10e/href</a></iframe><h4>3. Add Prettier Configurations</h4><p>Add .prettierrc at root of project &amp; give below content</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d74f84fa598c5d47bf0d333d127e2d7/href">https://medium.com/media/4d74f84fa598c5d47bf0d333d127e2d7/href</a></iframe><h4><strong>4. </strong>Execution <strong>Scripts</strong></h4><p>Add these scripts to package.json</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8556def28202b299b7508129e05fc802/href">https://medium.com/media/8556def28202b299b7508129e05fc802/href</a></iframe><p>Run linting by</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb5a2a05a92afe8a2a7f4d7996e26c80/href">https://medium.com/media/fb5a2a05a92afe8a2a7f4d7996e26c80/href</a></iframe><h4><strong>4. VSCode Integration</strong></h4><p>In case you’re using VSCode for code editor, you can install following extensions to see error messages from ESLint or beautifully format the source code with Prettier.</p><ul><li>​<a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint">https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint</a></li><li>​<a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode">https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode</a>​</li></ul><p>Done!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f876b79fd4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CodeClimate Setup For Ruby On Rails Project]]></title>
            <link>https://bentranz.medium.com/codeclimate-setup-for-ruby-on-rails-project-b8ccf1fe390?source=rss-210d602123ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8ccf1fe390</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[code-climate]]></category>
            <dc:creator><![CDATA[Ben Tran]]></dc:creator>
            <pubDate>Mon, 23 May 2022 09:02:51 GMT</pubDate>
            <atom:updated>2022-05-23T09:11:30.573Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ltJTzRX1kSJk0sFjjZhPBg.jpeg" /></figure><h4>Why should we use Code Climate?</h4><p><a href="http://codeclimate.com/">Code Climate</a> is a static quality analysis tool for your code. What it does is nothing more than scanning all your code looking for duplication problems, code smells and other assorted problems. Serving of a mini code review of your code and improving the quality of the code.</p><p>Code Climate supports many languages: Ruby, JavaScript, Typescript, Python, PHP, GoLang, Swift, …</p><h4>Add Code Climate to your project</h4><p>In project root path, add configurations file .codeclimate.yml</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d24c04b41ae68d199bb3fd62a71d010/href">https://medium.com/media/9d24c04b41ae68d199bb3fd62a71d010/href</a></iframe><p><em>Notes: Make sure you choose correct channel for each plugins, they must be matched with versions used your project.</em></p><p>Sign up for the Code Climate Quality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MSfNK5OR6w2Am9F6D9_kKg.png" /></figure><p>Add your repository to the Code Climate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JHIuds7b5Kb2OyHm7Jx6pQ.gif" /></figure><p>Soon after the code climate will run its process checking all your code, depending on the size of the code can take a while.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YMigi5jVN2zK4PI-W7DMWg.png" /></figure><p>After reading all your code it will go to main screen where it will say that your code has code smells, duplicates and problems of various types. It will also give you a note F, E, D, C, B, A, where F is a lot bad (Give up that area), and A (You’re hero!).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WK-hHPayDbU3DGNF5g_T3w.png" /></figure><p>A more detailed example of code smells problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aNOL28Qpk-1qwhGGQ__qnA.png" /></figure><p>With these details you will know where you have a problem in your code, then just do fixing or refactoring, then commit &amp; push the source code again.</p><h4><strong>Setup Code Climate features on Github</strong></h4><p>In Code Climate project dashboard, go to Repo Settings -&gt; Github, you should install these features:</p><ul><li>Pull request comments</li><li>Pull request status updates</li><li>Webhook on GitHub</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wr_6k7AKw_LJwikCwhRMhA.gif" /></figure><h4><strong>Setup CodeClimate Test Coverage (Optional)</strong></h4><p>Go to Repo Settings -&gt; Test Coverage, then get TEST REPORTER ID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lzlxc-8apSqc7OhexWtPgQ.png" /></figure><p>We use CircleCI to upload test coverage result to Code Climate (<a href="https://bentranz.medium.com/circleci-config-for-ruby-on-rails-application-41a65f056e39">Read this post if you don&#39;t know how to config CircleCI</a>).</p><p>To enable uploading test coverage result to Code Climate, please make sure you have these configurations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ip4HmW9AKGjJITx73dreEw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YTsHbE_BJAhDQojQElC5Lw.png" /></figure><p><strong><em>Important: Don&#39;t forget to add </em></strong><strong><em>CC_TEST_REPORTER_IDENV to your CircleCI project settings.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l9DzfP1r0VmwQYEl21QxEw.png" /></figure><h4>Require Code Climate status checks to pass before merging</h4><p>Go to Github project settings, add rules for your branches.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ExamZrzqa5UVBBqw98cLg.png" /></figure><p>Input correct branch matching pattern, add codeclimate, codeclimate/diff-coverage, codeclimate/total-coverage status checks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*68NdRUCYFIQ6JKlzOGZMfg.png" /></figure><p>Done!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8ccf1fe390" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CircleCI Setup For Ruby On Rails Project]]></title>
            <link>https://bentranz.medium.com/circleci-config-for-ruby-on-rails-application-41a65f056e39?source=rss-210d602123ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/41a65f056e39</guid>
            <category><![CDATA[circleci]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Ben Tran]]></dc:creator>
            <pubDate>Fri, 20 May 2022 09:11:51 GMT</pubDate>
            <atom:updated>2022-05-23T09:41:46.196Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*yjWuJOgWMt1BROPJvc2WBw.png" /></figure><p>This is the ultimate guide for your next Ruby on Rails project setup on Github with CircleCI for continuous integration.</p><h3><strong>Why </strong>should we <strong>use CircleCI for Ruby on Rails app?</strong></h3><ul><li><a href="https://circleci.com/">CircleCI</a> is a Continuous Integration and Delivery cloud provider.</li><li>It integrates with Github, so using both of them together is as simple as creating your accounts and setting up the Ruby on Rails project.</li><li>No custom servers maintenance, just going through some web forms and you are all set.</li><li>No credit card information required, a perfect combination to start small with your project and pay for what you use as you grow.</li><li>CircleCI provides an intuitive, well-organized UI with all the information required to establish the problem that occurs when the new code was integrated into the Github hosted codebase.</li><li>It is crucial to set up the Continuous Integration system for any project, let alone Ruby on Rails, from the first day of the development.</li><li>This is a great way to avoid a lot of technical debt, protect yourself from common mistakes and enforce certain standards that make working with Ruby on Rails codebase pleasing and its maintenance much, much easier.</li></ul><h3>Get Started</h3><p>Before you start, please visit CircleCI document to understand all configurations: <a href="https://circleci.com/docs/2.0/config-intro/?section=configuration">https://circleci.com/docs/2.0/config-intro/?section=configuration</a></p><p><strong>1. Add CircleCI Config To Rails</strong></p><p>Add .circleci/config.yml file with below content to your project root path.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ae529c622c7e0d219e300dca55a8c50/href">https://medium.com/media/7ae529c622c7e0d219e300dca55a8c50/href</a></iframe><p><em>Note: Please make sure that you have installed enough gems to able to run above commands (rubocop, brakeman, rspec, </em>simplecov<em>, …). You can also remove useless steps in your case.</em></p><p><strong>2. Connect &amp; Setup Github Project On CircleCI</strong></p><p>Follow the instructions below to create your CircleCI account linked to your Github account, and to set up the Ruby on Rails project continuous integration.</p><ul><li>Sign up with Github</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*72KnbKrC2gdd9bIh444zIA.png" /></figure><ul><li>After register account successfully, go to Projects from left side menu, then on your target project select a Set Up Project</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IGtJOYHaq9Eisbroy0EXvQ.png" /></figure><ul><li>Select a config.yml file for the project — We have already added it so please use the 2nd option, remember to input correct branch name.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CAxEFg7KHvSQCOgluJW8bQ.png" /></figure><ul><li>If everything goes well, you will have success build screen like this</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UvnAlZtGcAVIyc2XmfvOdg.png" /></figure><p><strong>3. Require CircleCI status check to pass before merging</strong></p><ul><li>Go to Github project settings, add new rule for your branch</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ExamZrzqa5UVBBqw98cLg.png" /></figure><ul><li>Input correct branch matching pattern, add ci:circleci build status check</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*68NdRUCYFIQ6JKlzOGZMfg.png" /></figure><p>Done!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41a65f056e39" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>