<?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 Muhammad Habibullah on Medium]]></title>
        <description><![CDATA[Stories by Muhammad Habibullah on Medium]]></description>
        <link>https://medium.com/@muhammadhabibullah?source=rss-d812db9f7570------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3mBaqDlDLfsRLwZ1gFxLLQ.png</url>
            <title>Stories by Muhammad Habibullah on Medium</title>
            <link>https://medium.com/@muhammadhabibullah?source=rss-d812db9f7570------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 22:51:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@muhammadhabibullah/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[Git Commands Cheatsheet: A Quick Reference Guide⚡]]></title>
            <link>https://medium.com/@muhammadhabibullah/git-commands-cheatsheet-a-quick-reference-guide-b80817af9162?source=rss-d812db9f7570------2</link>
            <guid isPermaLink="false">https://medium.com/p/b80817af9162</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[version-control-system]]></category>
            <dc:creator><![CDATA[Muhammad Habibullah]]></dc:creator>
            <pubDate>Tue, 21 Feb 2023 12:51:25 GMT</pubDate>
            <atom:updated>2023-02-21T12:51:25.695Z</atom:updated>
            <content:encoded><![CDATA[<h3>I. Introduction</h3><p>Git is a powerful version control system that enables software developers to collaborate on projects efficiently and effectively. With Git, developers can track changes made to code, merge changes made by different contributors, and restore previous versions of a project with ease. To accomplish these tasks, developers need to use a variety of Git commands. While some of these commands are straightforward, others can be complex and difficult to remember. That’s why having a Git commands cheatsheet can be invaluable for developers who want to work more efficiently and make the most of Git’s capabilities.</p><figure><img alt="Git Commands Cheatsheet: A Quick Reference Guide poster with various Git commands organized in a table format for easy reference." src="https://cdn-images-1.medium.com/max/950/1*VgIZljh9dEmfbyBwWCbUIA.png" /></figure><p>In this article, we’ll provide a comprehensive Git commands cheatsheet that covers both basic and advanced Git commands. We’ll also provide an overview of Git installation and setup, as well as the importance of Git commands in version control. Whether you’re a seasoned developer or just starting to learn Git, this guide will help you become more proficient with Git commands and streamline your development workflow.</p><h3>II. Installation &amp; Setup</h3><p>Before you can start using Git commands, you need to install Git on your local machine and set up your user details. Here are the steps to get started with Git:</p><ol><li>Download and Install Git</li></ol><p>The first step is to download and install Git on your local machine. You can download Git from the official Git website, and installation instructions are provided for Windows, Mac, and Linux.</p><p><a href="https://git-scm.com/downloads">Install</a></p><p>2. Verify Your Installation</p><p>To verify that Git has been installed correctly, you can run the following command in the terminal:</p><pre>$ git --version</pre><p>This should return the version of Git that you have installed on your local machine.</p><p>3. Configure Your User Details</p><p>Once you’ve installed Git, you’ll need to configure your user details. This will include your name and email address, which will be used to identify you as the author of commits. To configure your user details, run the following commands in the terminal:</p><pre>$ git config --global user.name &quot;Your Name&quot;1. <br>$ git config --global user.email &quot;your.email@example.com&quot;</pre><p>Make sure to replace “Your Name” and “<a href="/service/mailto:your.email@example.com">your.email@example.com</a>” with your actual name and email address.</p><p>With Git installed and your user details configured, you’re ready to start using Git commands to manage your projects. In the next sections, we’ll cover the most basic and advanced Git commands for version control.</p><h3>III. Basic Git Commands</h3><p>Git is a powerful tool for version control and collaboration on software projects. To use Git effectively, it’s important to learn some basic Git commands. In this section, we’ll cover the most common Git commands used for creating a new repository, adding files to a repository, committing changes, and pushing changes to a remote repository.</p><ol><li><strong>How to initialize a Git repo</strong></li></ol><p>To get started with Git, you’ll need to initialize a new Git repository. This creates a new project that Git will manage for you. To do this, simply navigate to your project’s root directory and run the following command:</p><pre>git init</pre><p><strong>2.</strong> <strong>How to add files to the staging area</strong></p><p>After you have initialized a Git repo, you can add files to the staging area to prepare for the next commit. To add a file to the staging area, run:</p><pre>git add [file]</pre><p>You can also add all changes in the current directory to the staging area with the following command:</p><pre>git add .</pre><p><strong>3.</strong> <strong>How to commit changes</strong></p><p>Once you have added files to the staging area, you can commit the changes. To commit changes, run:</p><pre>git commit -m &quot;Your commit message&quot;</pre><p><strong>4. How to add a remote repository</strong></p><p>If you want to collaborate with others on a project or store your code in a remote location, you’ll need to add a remote repository. To add a remote repository, run:</p><pre>git remote add [name] [url]</pre><p>This command will add a new remote repository with the specified name and URL. You can then push your changes to the remote repository using the git push command.</p><p><strong>5. How to push changes to a remote repository</strong></p><p>After you have committed changes to your local repository, you can push those changes to a remote repository. To push changes, run:</p><pre>git push &lt;remote&gt; &lt;branch&gt;</pre><p>For example, if you want to push changes to the main branch of the origin remote, run:</p><pre>git push origin main</pre><p><strong>6. How to pull changes from a remote repository</strong></p><p>To get the latest changes from a remote repository and update your local repository, run:</p><pre>git pull [remote] [branch]</pre><p>For example, to pull changes from the main branch of the origin remote, run:</p><pre>git pull origin main</pre><p><strong>7. How to check the status of your repository</strong></p><p>To see the status of your local repository, including which files have been modified and which files are staged for commit, run:</p><pre>git status</pre><p>This command is useful for keeping track of the changes you’ve made to your code and which files are ready to be committed.</p><p><strong>8. How to view the commit history</strong></p><p>To view the commit history of your local repository, including the commit message and the author, run:</p><pre>git log</pre><p>This command is useful for understanding the changes that have been made to your code over time and who made those changes.</p><p><strong>9. How to revert changes</strong></p><p>If you make a mistake or want to undo a change you’ve made, you can revert to a previous commit. To revert to a previous commit, run:</p><pre>git revert [commit-hash]</pre><p>This will create a new commit that undoes the changes made in the specified commit.</p><p><strong>10. How to discard changes</strong></p><p>If you haven’t yet committed your changes and want to discard them, you can use the following command to discard all changes in the current working directory:</p><pre>git reset --hard</pre><p>This will remove all changes since the last commit and revert your repository to the state it was in at the last commit.</p><p>These are the most basic Git commands you need to know to get started with version control. As you become more comfortable with Git, you can learn more advanced commands for branching, merging, rebasing, and resolving conflicts.</p><h3>IV. Advanced Git Commands</h3><p>Git is a powerful version control tool that allows for complex workflows and collaboration. Advanced Git commands are used for more complex version control tasks, such as branching, merging, rebasing, and resolving conflicts. In this section, we’ll cover some of the most commonly used advanced Git commands.</p><ol><li><strong>Branching</strong></li></ol><p>Branching is a fundamental concept in Git that allows you to work on multiple versions of your project simultaneously. A branch is essentially a snapshot of your code at a specific point in time. You might want to create a branch when you want to experiment with a new feature or work on a bug fix without affecting the main codebase. Some common branching commands include:</p><ul><li>git branch: This command shows you a list of all branches in your local repository, whereas to also include branches from your remote repository, you can use git branch -a.</li><li>git branch -d [branch-name] : This command deletes a branch, use -D if you want to force delete it.</li><li>git checkout [target-branch]: This command switches to an existing branch.</li><li>git checkout -b [branch-name]: This command creates a new branch and switches to it.</li><li>git merge [target-branch]: This command combines changes from one branch into another.</li></ul><p><strong>2. Merging</strong></p><p>Merging is the process of combining changes from one branch into another. When you merge a branch, Git automatically incorporates the changes made in the branch into the target branch. Some common merging commands include:</p><ul><li>git merge [target-branch]: This command combines changes from one branch into another.</li><li>git merge --no-ff [target-branch]: This command forces Git to create a merge commit even if it&#39;s not necessary.</li></ul><p><strong>3. Rebasing</strong></p><p>Rebasing is an alternative to merging that allows you to integrate changes from one branch into another by reapplying them on top of the target branch. This can make your commit history more linear and easier to understand. Some common rebasing commands include:</p><ul><li>git rebase [target-branch]: This command allows you to reapply changes from one branch onto another branch.</li><li>git rebase -i [target-branch]: This command allows you to interactively rebase a branch.</li></ul><p><strong>4. Resolving Conflicts</strong></p><p>Conflicts can occur when Git is unable to automatically merge changes made in different branches. Conflicts are a natural part of collaboration and can be resolved using various commands, such as:</p><ul><li>git diff: This command shows you the differences between conflicting versions of a file.</li><li>git mergetool: This command launches a graphical tool that can help you resolve conflicts.</li><li>git checkout --ours and git checkout --theirs: These commands allow you to choose which version of a conflicting file to keep.</li></ul><h3>V. Git Commands Cheatsheet</h3><p>Here is a comprehensive list of Git commands for easy reference. The commands are organized into categories for easier navigation and understanding.</p><h3>Repository Management</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*ntBfSCGQwbElAquymFaaXw.png" /><figcaption>Repository management commands cheatsheet</figcaption></figure><h3>Basic Workflow</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*z3t6s82MtGsFCysT8dutnw.png" /><figcaption>Basic workflow commands cheatsheet</figcaption></figure><h3>Branching</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*WuMC8bnL8R2CguLP35OAng.png" /><figcaption>Branching commands cheatsheet</figcaption></figure><h3>Merging, Rebasing &amp;Resolving Conflicts</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*SXfdoPbLTB38ZQsVM-Xh-g.png" /><figcaption>merging, rebasing &amp; resolving conflicts commands cheatsheet</figcaption></figure><p>It’s important to note that this list is not exhaustive and there are many more Git commands available. However, these are some of the most commonly used commands that cover the basic and advanced Git workflows.</p><h3>VI. Conclusion</h3><p>In this article, we provided a comprehensive Git commands cheatsheet for quickly referencing important Git commands used in version control. Mastering these commands can improve your development workflow and collaboration. Consistent use of Git will make you more proficient and efficient in managing code. We hope this cheatsheet is a useful resource for you.</p><p>Thank you for reading, and happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b80817af9162" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easy and Fast : Automating AWS EC2 Deployment with GitHub Actions and Docker Hub]]></title>
            <link>https://medium.com/@muhammadhabibullah/easy-and-fast-automating-aws-ec2-deployment-with-github-actions-and-docker-hub-154b83b5b602?source=rss-d812db9f7570------2</link>
            <guid isPermaLink="false">https://medium.com/p/154b83b5b602</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[Muhammad Habibullah]]></dc:creator>
            <pubDate>Sun, 19 Feb 2023 11:44:35 GMT</pubDate>
            <atom:updated>2023-02-19T11:44:35.251Z</atom:updated>
            <content:encoded><![CDATA[<h3>Easy and Fast : Automating AWS EC2 Deployment with GitHub Actions and Docker Hub</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*67il0eX-XxB89h_6I65TSg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@agk42">agk42 </a>on <a href="https://unsplash.com/">Unsplash</a></figcaption></figure><h3>Table of Contents</h3><ul><li><a href="#9271">Introduction</a></li><li><a href="#9d09">Prerequisites</a></li><li><a href="#461c">Make a Dockerfile</a></li><li><a href="#29a4">Setup GitHub Workflow</a></li><li><a href="#2807">Let’s Break it Down (GitHub Workflow)</a></li><li><a href="#1dc8">Setup Secret Variables</a></li><li><a href="#7946">Executing the Workflow</a></li><li><a href="#1533">Conclusion</a></li></ul><h3>Introduction</h3><p>As a developer, automating your deployment process can help you save time and effort in the long run. Instead of manually deploying your code changes to an Amazon Web Services (AWS) Elastic Compute Cloud (EC2) instance, you can automate the process using tools like Github Actions and Docker Hub.</p><p>In this guide, we’ll explore how you can use Github Actions and DockerHub to automate your deployment to an AWS EC2 instance. We’ll go through the steps of setting up an AWS EC2 instance, creating and pushing a Docker image to DockerHub, and setting up a Github Actions workflow to automate the deployment process. By the end of this guide, you’ll have a better understanding of how to streamline your deployment workflow and reduce the risk of human error.</p><h3>Prerequisites</h3><p>Before you start automating your AWS EC2 deployment with Github Actions and Docker Hub, there are a few prerequisites that you should have in place:</p><h4>1. Buildable code</h4><p>You should have buildable code that can be used to create a Docker image. If you’re not already familiar with Docker, it’s a platform for building, shipping, and running applications in containers. A Docker image is a lightweight, standalone, executable package that contains everything needed to run a piece of software, including the code, libraries, and dependencies.</p><h4>2. An AWS EC2 instance with .pem file and Docker installed</h4><p>You’ll need an AWS EC2 instance to deploy your application to. While it’s not mandatory to use Ubuntu, in this article we’ll use an Ubuntu AWS EC2 instance. If you don’t already have an AWS EC2 instance, you can follow the official <a href="https://docs.aws.amazon.com/quickstarts/latest/vmlaunch/step-1-launch-instance.html">AWS documentation</a> to set one up. Additionally, you’ll need the .pem file associated with the instance to allow SSH access. You should also have Docker installed on the AWS EC2 instance, which can be done by following the official <a href="https://docs.docker.com/engine/install/">Docker documentation</a>.</p><h4>3. Docker Hub account with access token</h4><p>Finally, you’ll need a Docker Hub account to host your Docker images. Docker Hub is a cloud-based registry service that allows you to store and share Docker images. If you don’t already have a Docker Hub account, you can sign up for one <a href="https://hub.docker.com/">here</a>. Once you’ve created your account, you’ll need to generate an access token that can be used to authenticate with Docker Hub in your Github Actions workflow. You can generate an access token by following the instructions in the official <a href="https://docs.docker.com/docker-hub/access-tokens/">Docker documentation</a>.</p><p>With these prerequisites in place, you’re ready to start automating your AWS EC2 deployment with Github Actions and Docker Hub.</p><h3>Make a Dockerfile</h3><p>Before we can start using Github Actions to automate our deployment, we need to create a Docker image of our application. To do this, we need to create a dockerfile that describes how our image should be built.</p><ol><li>In the root directory of your project, create a new file called dockerfile using a text editor of your choice.</li><li>In the dockerfile, start by specifying the base image you want to use. For example, if you&#39;re using a Go app, you can use the official Golang Docker image as your base image:</li></ol><pre>##specify the base image<br>FROM golang:1.19-alpine</pre><p>This line tells Docker to use the golang:1.19-alpine image as the starting point for our Docker image.</p><p>3. Next, specify the working directory for your application in the Docker image:</p><pre>##create folder APP<br>RUN mkdir /app</pre><pre>##set main directory<br>WORKDIR /app</pre><p>These lines tell Docker to create a new directory called app in the Docker image and set it as the working directory.</p><p>4. Copy the rest of your application code into the Docker image:</p><pre>##copy the whole file to app<br>ADD . /app</pre><p>This line tells Docker to copy the rest of your application code into the /app directory in the Docker image.</p><p>5. Create an executable file for your application:</p><pre>##create executeable<br>RUN go build -o main .</pre><p>This line tells Docker to run the go build command in the Docker image to create an executable file called main for your application.</p><p>6. Finally, specify the command to run when the Docker container starts up:</p><pre>##run executeable<br>CMD [&quot;/app/main&quot;]</pre><p>This line tells Docker to run the /app/main executable file when the Docker container starts up.</p><p>With your Dockerfile now complete, it should look like the example shown below :</p><pre>##use the official Golang image as the base image<br>FROM golang:1.19-alpine</pre><pre>##create folder APP<br>RUN mkdir /app</pre><pre>##set main directory<br>WORKDIR /app</pre><pre>##copy the whole file to app<br>ADD . /app</pre><pre>##create executeable<br>RUN go build -o main .</pre><pre>##run executeable<br>CMD [&quot;/app/main&quot;]</pre><p>With your dockerfile complete, you’re ready to build your Docker image and push it to Docker Hub.</p><h3>Setup GitHub Workflow</h3><p>Setting up a GitHub Workflow allows you to automate tasks such as testing, building, and deploying your code. By automating these tasks, you can ensure that your code is always tested and deployed in a consistent and reliable way.</p><p>To set up a GitHub Workflow, you need to create a YAML (example: main.yml) file in your repository’s .github/workflows directory. This YAML file defines the jobs that you want to run and the actions that you want to perform.</p><p>Each job consists of a series of steps, and each step runs a specific action. Actions are reusable units of code that perform specific tasks, such as checking out your code, building a Docker image, or deploying your code to a cloud provider.</p><p>Here’s an example of a simple YAML file that builds and pushes a Docker image to Docker Hub whenever a new push to branch main:</p><pre># Trigger the workflow when a push occurs on the main branch<br>on:<br>  push:<br>    branches:<br>      - main  </pre><pre>jobs:<br>  build:<br>    # Run the job on an Ubuntu machine<br>    name: Build<br>    runs-on: ubuntu-latest  </pre><pre>    steps:<br>      # Checkout the code from the repository<br>      - name: Checkout  <br>        uses: actions/checkout@v3</pre><pre>      # Log in to Docker Hub using secrets<br>      - name: Login to Docker Hub  <br>        uses: docker/login-action@v2<br>        with:<br>          username: ${{ secrets.DOCKER_USER }}  <br>          password: ${{ secrets.DOCKER_TOKEN }}<br>          <br>      # Set up the Docker Buildx builder<br>      - name: Set up Docker Buildx  <br>        uses: docker/setup-buildx-action@v2</pre><pre>      # Build the Docker image and push it to Docker Hub<br>      - name: Build and push  <br>        uses: docker/build-push-action@v3<br>        with:<br>          context: .  <br>          file: ./Dockerfile  <br>          push: true  <br>          tags: ${{ secrets.DOCKER_USER }}/${{ secrets.IMAGE }}:latest</pre><pre>      # Run remote commands on an EC2 instance using SSH<br>      - name: executing remote ssh commands using password  <br>        uses: appleboy/ssh-action@v0.1.7<br>        with:<br>          host: ${{ secrets.EC2_HOST }}  <br>          username: ${{ secrets.EC2_USERNAME }}  <br>          key: ${{ secrets.EC2_KEY }} <br>          port: ${{ secrets.EC2_PORT }} </pre><pre>          # The remote commands to execute on the EC2 instance<br>          script: | <br>            touch deploy.txt<br>            echo &quot;Great, it works! at $(TZ=&#39;Asia/Jakarta&#39; date &quot;+%A %d-%b-%Y %H:%M:%S %Z&quot;)&quot; &gt;&gt; deploy.txt<br>            sudo chmod 777 /var/run/docker.sock<br>            docker pull ${{ secrets.DOCKER_USER }}/${{ secrets.IMAGE }}:latest <br>            docker stop ${{ secrets.CONTAINER }}<br>            docker rm ${{ secrets.CONTAINER }} <br>            docker rmi ${{ secrets.DOCKER_USER }}/${{ secrets.IMAGE }} <br>            docker run --name ${{ secrets.CONTAINER }} -d -p 80:8000 ${{ secrets.DOCKER_USER }}/${{ secrets.IMAGE }}</pre><h3>Let’s Break it Down</h3><pre>on:<br>  push:<br>    branches:<br>      - main</pre><p>This defines the event that will trigger the workflow. In this case, the workflow will be triggered when a new push on branch main.</p><pre>jobs:<br>  build:<br>    name: Build<br>    runs-on: ubuntu-latest<br>    steps:</pre><p>This defines the job to be run in the workflow. It is called “build” and runs on the latest version of Ubuntu.</p><pre>- name: Checkout<br>        uses: actions/checkout@v3</pre><p>This step checks out the code from the repository to the runner.</p><pre>- name: Login to Docker Hub<br>        uses: docker/login-action@v2<br>        with:<br>          username: ${{ secrets.DOCKER_USER }}<br>          password: ${{ secrets.DOCKER_TOKEN }}</pre><p>This step logs in to Docker Hub using the Docker Hub username and token stored as secrets in the repository settings.</p><pre>- name: Set up Docker Buildx<br>        uses: docker/setup-buildx-action@v2</pre><p>This step sets up Docker Buildx, which is a Docker CLI plugin that extends the capabilities of the Docker command-line interface.</p><pre>- name: Build and push<br>        uses: docker/build-push-action@v3<br>        with:<br>          context: .<br>          file: ./Dockerfile<br>          push: true<br>          tags: ${{ secrets.DOCKER_USER }}/${{ secrets.IMAGE }}:latest</pre><p>This step builds the Docker image using the Dockerfile in the current directory, and pushes it to Docker Hub using the specified tags.</p><pre># Run remote commands on an EC2 instance using SSH<br>- name: executing remote ssh commands using password  <br>  uses: appleboy/ssh-action@v0.1.7<br>  with:<br>    host: ${{ secrets.EC2_HOST }}  <br>    username: ${{ secrets.EC2_USERNAME }}  <br>    key: ${{ secrets.EC2_KEY }} <br>    port: ${{ secrets.EC2_PORT }} </pre><pre>    # The remote commands to execute on the EC2 instance<br>    script: | <br>      touch deploy.txt<br>      echo &quot;Great, it works! at $(TZ=&#39;Asia/Jakarta&#39; date &quot;+%A %d-%b-%Y %H:%M:%S %Z&quot;)&quot; &gt;&gt; deploy.txt<br>      sudo chmod 777 /var/run/docker.sock<br>      docker pull ${{ secrets.DOCKER_USER }}/${{ secrets.IMAGE }}:latest <br>      docker stop ${{ secrets.CONTAINER }}<br>      docker rm ${{ secrets.CONTAINER }} <br>      docker rmi ${{ secrets.DOCKER_USER }}/${{ secrets.IMAGE }} <br>      docker run --name ${{ secrets.CONTAINER }} -d -p 80:8000 ${{ secrets.DOCKER_USER }}/${{ secrets.IMAGE }}</pre><ul><li>This code block is using the appleboy/ssh-action action to execute a remote SSH command on the server specified in the secrets file. The script to be executed is defined using the script parameter.</li><li>The script starts by creating a new file named deploy.txt and adding a line to it that says &quot;Great, it works!&quot; along with the current date and time in the Asia/Jakarta timezone or can be changed with a timezone you wish, see available timezones <a href="https://manpages.ubuntu.com/manpages/xenial/man3/DateTime::TimeZone::Catalog.3pm.html">here</a>.</li><li>The sudo chmod 777 /var/run/docker.sock command is then executed to change the permissions of the Docker socket file to allow the current user to access it.</li><li>The docker pull command is used to pull the latest version of the Docker image specified in the secrets file.</li><li>The docker stop, docker rm, and docker rmi commands are used to stop and remove any existing Docker container and image with the same name as specified in the secrets file.</li><li>Finally, the docker run command is used to start a new Docker container with the name specified in the secrets file, using the image specified in the secrets file.</li><li>The -d flag runs the container in the background as a daemon process</li><li>While the -p 80:8000 flag maps port 80 on the host to port 8000 on the container, allowing the container to be accessed via HTTP on port 80.</li><li>You can also use-e flag to set environment variables for the container, such as DB Host, DB Password, JWT Key, etc.</li></ul><p>Overall, this code block pulls the latest version of a Docker image, stops and removes any existing containers with the same name, starts a new container, and maps the container’s port 8000 to the host’s port 80.</p><h3>Setup Secret Variables</h3><p>In order to deploy your application to AWS EC2, you will need to set up several secret variables in your GitHub repository. These secrets are securely stored and encrypted by GitHub and can only be accessed by authorized users.</p><ol><li>Go to your GitHub repository.</li><li>Click on the “Settings” tab.</li><li>In the left sidebar, click on the “Secrets” option.</li><li>You will be taken to the “Actions secrets and variables” page for your repository. Here, you can create, edit, and delete secrets that can be used in your GitHub Actions workflows.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*1PUpMF0UNraNvBK2bBKp-Q.png" /><figcaption>Repository Secret Variables</figcaption></figure><p>Here is a list of the required secret variables, along with a brief explanation of what they are used for:</p><ul><li>DOCKER_USER: Your Docker Hub username</li><li>DOCKER_TOKEN: An access token with permission to push images to your Docker Hub repository</li><li>IMAGE: The name of your Docker image</li><li>CONTAINER: The name of the Docker container that will be running your application</li><li>EC2_HOST: The IP address or domain name of your EC2 instance (example: ec2–xx–xxx–xxx–xx.ap-southeast-1.compute.amazonaws.com)</li><li>EC2_USERNAME: The username used to log in to your EC2 instance (usually is ubuntu)</li><li>EC2_KEY: The private key used to log in to your EC2 instance</li><li>EC2_PORT: The SSH port used to connect to your EC2 instance (default is 22)</li></ul><p>Make sure to set up these secret variables in your GitHub repository before running the GitHub Workflow.</p><h3>Executing the Workflow</h3><p>Once the workflow is set up, it is time to execute it. To do so, commit the code changes to the main branch of the repository. This will trigger the workflow to run automatically.</p><p>To check the status of the workflow, go to the “Actions” tab in the GitHub repository. Here, you will see a list of all the workflows that have been executed, as well as their status. You can click on a specific workflow to see its details, including any errors or warnings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nc5P8YpFUYTqjpNazby3Gw.png" /><figcaption>failed to run the workflow</figcaption></figure><p>If the workflow runs successfully, you should see a message indicating that the deployment has been completed. You can also verify that the website is live and functioning as expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HnflqYeTyiDrkz8KjlNfpA.png" /><figcaption>succeeded to run the workflow</figcaption></figure><p>If the workflow fails, there may be an issue with the configuration or the code. Review the error messages in the workflow logs to identify the problem, and make any necessary changes to the workflow or code. Please also check if the secret variables are already matched.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*jynjeNHtvGqu3s8o1bzpUg.png" /><figcaption>deploy.txt logs</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H8fBIRQmulSyAnnx35u55A.png" /><figcaption>deployed image</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TWLwvaazAagn_Q1mqndsRg.png" /><figcaption>deployed container</figcaption></figure><p>Overall, executing a GitHub workflow is a simple process that can greatly streamline the development and deployment process. With the right setup and configuration, you can automate many of the tedious and time-consuming tasks involved in software development, and focus on building great products and services.</p><h3>Conclusion</h3><p>In conclusion, this tutorial walked you through the steps to set up a basic GitHub workflow to deploy a Dockerized web application. By leveraging the power of GitHub Actions, you can automate your application deployment process, freeing up your time to focus on other important tasks. We hope this tutorial has been helpful in understanding the basics of GitHub Actions, Docker, Docker Hub, and how they can work together to simplify your workflow.</p><p>As you continue to work on your projects, you can use the concepts you have learned here to create more complex and customized workflows that meet your specific needs. Remember that the possibilities are endless, and with a little creativity, you can create powerful workflows that help you achieve your goals faster and with less effort.</p><p>If you have any questions or feedback, feel free to comment below or you can also join the GitHub community to get help and connect with other developers. Thanks for reading! ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=154b83b5b602" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>