<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shen Lu</title>
    <description>The latest articles on DEV Community by Shen Lu (@shenlu89).</description>
    <link>https://dev.to/shenlu89</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1393292%2Fdb063b76-244f-40be-a82b-a2f3b647a244.jpeg</url>
      <title>DEV Community: Shen Lu</title>
      <link>https://dev.to/shenlu89</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shenlu89"/>
    <language>en</language>
    <item>
      <title>Building and Pushing Docker Image to Docker Hub using GitHub Actions</title>
      <dc:creator>Shen Lu</dc:creator>
      <pubDate>Tue, 30 Sep 2025 06:30:45 +0000</pubDate>
      <link>https://dev.to/shenlu89/building-and-pushing-docker-image-to-docker-hub-using-github-actions-594l</link>
      <guid>https://dev.to/shenlu89/building-and-pushing-docker-image-to-docker-hub-using-github-actions-594l</guid>
      <description>&lt;p&gt;Recently, I wanted to implement a feature on &lt;a href="https://mathcheap.xyz" rel="noopener noreferrer"&gt;Mathcheap&lt;/a&gt; that allows exporting LaTeX to DOCX format. Unfortunately, I couldn’t find a suitable JS library to achieve this. The tool that works very well for this task is &lt;strong&gt;Pandoc&lt;/strong&gt;. The only drawback is that Pandoc is written in Haskell and cannot run natively in Node environments or on edge servers.&lt;/p&gt;

&lt;p&gt;To overcome this limitation, I compiled Pandoc to WebAssembly. Last week, I open-sourced &lt;a href="https://github.com/shenlu89/pandoc-wasm" rel="noopener noreferrer"&gt;&lt;code&gt;pandoc-wasm&lt;/code&gt;&lt;/a&gt;, which provides this compilation workflow. I also published it on &lt;a href="https://hub.docker.com/r/shenlu89/pandoc-wasm" rel="noopener noreferrer"&gt;Docker Hub&lt;/a&gt; via Docker images.&lt;/p&gt;

&lt;p&gt;During this process, I explored how to leverage GitHub Actions to automatically build and publish Docker images, which greatly improved the integration and deployment efficiency of my open-source project.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Why Automate Docker Image Publishing?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;While migrating the Pandoc runtime environment to Node servers, I designed a reliable &lt;code&gt;pandoc-wasm&lt;/code&gt; compilation workflow. Since Mathcheap depends on the build artifacts from this workflow, I decided to open-source it and maintain it long-term.&lt;/p&gt;

&lt;p&gt;Docker turned out to be the perfect solution, as it can package the application and all its dependencies into a standardized container. However, manually building images, tagging them, and pushing them to Docker Hub each time is tedious and error-prone.&lt;/p&gt;

&lt;p&gt;In fast-iterating open-source projects, automating this workflow is essential. It not only saves time but also ensures that each code merge results in a reliable Docker image. GitHub Actions is the ideal tool to achieve this.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Prerequisites&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Before getting started, make sure you have the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;A GitHub repository&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A Docker Hub account&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A Dockerfile&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;code&gt;Dockerfile&lt;/code&gt; is a plain text file containing a series of instructions to assemble an image.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Configure Docker Hub Credentials&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To allow GitHub Actions to log in to your Docker Hub account and push images, you need to securely store your username and access token in GitHub.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Generate a Docker Hub access token&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Log in to Docker Hub.&lt;/li&gt;
&lt;li&gt;Go to &lt;strong&gt;Settings → Personal access tokens&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Generate new token&lt;/strong&gt;, create one with read/write/delete permissions, and &lt;strong&gt;copy it immediately&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Add Secrets in GitHub&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Go to your GitHub repository → &lt;strong&gt;Settings → Secrets and variables → Actions&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click &lt;strong&gt;New repository secret&lt;/strong&gt;, and add:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;DOCKERHUB_USERNAME&lt;/code&gt;: your Docker Hub username.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;DOCKERHUB_TOKEN&lt;/code&gt;: the access token you just generated.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;This way, the workflow can securely use these credentials without hardcoding them into your code.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Create a GitHub Actions Workflow&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Next, create a YAML file in your project to define the automation.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the repository root, create the &lt;code&gt;.github/workflows/&lt;/code&gt; folder.&lt;/li&gt;
&lt;li&gt;Inside it, create a new YAML file, e.g., &lt;code&gt;docker-publish.yml&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Build and Publish Docker image&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;v*"&lt;/span&gt;
  &lt;span class="na"&gt;workflow_dispatch&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

&lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;IMAGE_NAME&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;build-and-push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;

    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Checkout code&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Login to Docker Hub&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;docker/login-action@v3&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.DOCKERHUB_USERNAME }}&lt;/span&gt;
          &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.DOCKERHUB_TOKEN }}&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Build and push Docker image&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;docker/build-push-action@v5&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./docker&lt;/span&gt;
          &lt;span class="na"&gt;file&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./docker/Dockerfile&lt;/span&gt;
          &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
          &lt;span class="na"&gt;tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
            &lt;span class="s"&gt;${{ env.IMAGE_NAME }}:${{ github.ref_name }}&lt;/span&gt;
            &lt;span class="s"&gt;${{ env.IMAGE_NAME }}:latest&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Update Docker Hub description&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;peter-evans/dockerhub-description@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.DOCKERHUB_USERNAME }}&lt;/span&gt;
          &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.DOCKERHUB_TOKEN }}&lt;/span&gt;
          &lt;span class="na"&gt;repository&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ env.IMAGE_NAME }}&lt;/span&gt;
          &lt;span class="na"&gt;short-description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ github.event.repository.description }}&lt;/span&gt;
          &lt;span class="na"&gt;readme-filepath&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./docker/README.md&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Breaking Down the Workflow&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Here’s a closer look at the key parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Trigger conditions &lt;code&gt;on&lt;/code&gt;&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;push.tags&lt;/code&gt;: runs when pushing tags starting with &lt;code&gt;v&lt;/code&gt; (e.g., &lt;code&gt;v1.0.0&lt;/code&gt;), aligning Docker image versions with project versions.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;workflow_dispatch&lt;/code&gt;: allows manual triggers from the GitHub UI.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;env.IMAGE_NAME&lt;/code&gt;&lt;/strong&gt;: defines the image name as &lt;code&gt;shenlu89/pandoc-wasm&lt;/code&gt; (&lt;code&gt;shenlu89&lt;/code&gt; is my Docker Hub username).&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;docker/build-push-action@v5&lt;/code&gt;&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;context&lt;/code&gt;: points to the &lt;code&gt;./docker&lt;/code&gt; folder.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;file&lt;/code&gt;: specifies the Dockerfile path.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;push: true&lt;/code&gt;: pushes the built image to Docker Hub.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;tags&lt;/code&gt;: pushes both the version tag and &lt;code&gt;latest&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;peter-evans/dockerhub-description@v4&lt;/code&gt;&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automatically updates the Docker Hub description with repository metadata and &lt;code&gt;./docker/README.md&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Triggering GitHub Actions&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You can trigger the workflow by pushing a version tag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s1"&gt;'feat: xxx'&lt;/span&gt;
git tag v1.0.0
git push origin v1.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or manually via the &lt;strong&gt;Run workflow&lt;/strong&gt; tab in GitHub.&lt;/p&gt;

&lt;p&gt;Once triggered, GitHub Actions will automatically build the Docker image and push it to Docker Hub.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>githubactions</category>
      <category>pandoc</category>
      <category>webassembly</category>
    </item>
    <item>
      <title>Amazing Endemic Species (AES) Release on World Environment Day</title>
      <dc:creator>Shen Lu</dc:creator>
      <pubDate>Wed, 05 Jun 2024 06:24:15 +0000</pubDate>
      <link>https://dev.to/shenlu89/amazing-endemic-species-aes-release-on-world-environment-day-4425</link>
      <guid>https://dev.to/shenlu89/amazing-endemic-species-aes-release-on-world-environment-day-4425</guid>
      <description>&lt;p&gt;Hello everyone!&lt;/p&gt;

&lt;p&gt;In celebration of World Environment Day, I'm excited to announce the release of &lt;strong&gt;Amazing Endemic Species&lt;/strong&gt; (AES), an open-source, community-driven SaaS (Species-as-a-Service) application.&lt;/p&gt;

&lt;p&gt;Website: &lt;a href="https://aes.shenlu.me/"&gt;https://aes.shenlu.me/&lt;/a&gt;&lt;br&gt;
GitHub: &lt;a href="https://github.com/shenlu89/amazing-endemic-species"&gt;https://github.com/shenlu89/amazing-endemic-species&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🌍 &lt;strong&gt;3D Dynamic Globe&lt;/strong&gt;: Explore and visualize endemic species across the globe using our interactive 3D dynamic globe.&lt;/li&gt;
&lt;li&gt;🦎 &lt;strong&gt;User-Friendly API Services&lt;/strong&gt;: Seamlessly access AES data for scientific research or secondary development projects with our easy-to-use API, such as 404 page.&lt;/li&gt;
&lt;li&gt;🔍 &lt;strong&gt;Open-Source &amp;amp; Community-Driven&lt;/strong&gt;: Contribute to our ever-growing database to ensure that the information is always accurate and up-to-date.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How You Can Contribute:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⭐️ Star us on GitHub: Show your support for the project!&lt;/li&gt;
&lt;li&gt;📢 Share AES: Spread the word to your network and raise awareness.&lt;/li&gt;
&lt;li&gt;💻 Contribute Code and Data: Help improve and expand AES by contributing code or new species data.&lt;/li&gt;
&lt;li&gt;🐛 Submit Issues: Report bugs or suggest new features to enhance AES.&lt;/li&gt;
&lt;li&gt;🌐 Explore Our Website: Every visit helps support our mission.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tech Stack:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AES is built with Next.js, Tailwind CSS, D3.js, Headless UI, Drizzle, Turso, and SQLite3.&lt;/p&gt;

&lt;p&gt;Whether you’re giving a star, sharing with social media, contributing data, using the API for your research or building something like a 404 page, or simply exploring the globe, every little bit helps raise environmental awareness.&lt;/p&gt;

&lt;p&gt;Happy World Environment Day! 🌿&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>opensource</category>
      <category>news</category>
    </item>
  </channel>
</rss>
