DEV Community

Cover image for Hosting Apps For Free With Github Actions 🤯🚀
Jonas Scholz
Jonas Scholz

Posted on

Hosting Apps For Free With Github Actions 🤯🚀

When I first found out that I could host my Apps for free on GitHub actions my mind was completely blown 🤯

Let's learn how scheduled workflows can reduce your cloud hosting bill to $0

funny gif haher

Setup

I don't want to waste your time - this only works if your app does not need to run 24/7, but rather on a fixed schedule. If your app is based on data that you need to scrape daily, or if you want to send an automated good morning message to your girlfriend, this would work perfectly! Not that I recommend automating your relationship 🫠

For this example, we are going to automate an old tool of mine that scrapes data from a news site. In the repository you will find a very simple NodeJS (v18) script that has a few dependencies and a single build step. If you want to run it, you run npm install, npm run build, and finally npm run start. It will then scrape data, summarize it, send me a message on telegram, and finally stop. Since this script is summarizing news for me I want it to run every morning. With these requirements, we can build our GitHub Action workflow:


name: Daily Report

on:
  schedule:
    - cron: "0 6 * * *" # Use a tool like www.cronmaker.com
  workflow_dispatch: # Enable manual trigger

jobs:
  build-and-start:
    runs-on: ubuntu-latest # Base Image
    steps:
      - uses: actions/checkout@v3 # Get code from repo
      - uses: actions/setup-node@v3 # Install Node.JS
        with:
          node-version: 18.x # Use any major version 18
      - run: npm install # Install dependencies
      - run: npm run build # Compile Code

      - run: npm run start # Start Code
        env: # Runtime secrets are defined in Repository Settings
          GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
          GOOGLE_PROJECT_ID: ${{ secrets.GOOGLE_PROJECT_ID }}
          TELEGRAM_API_KEY: ${{ secrets.TELEGRAM_API_KEY }}
          TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
Enter fullscreen mode Exit fullscreen mode

If you have done everything correctly, GitHub will now execute this workflow every day. You will see the results and logs in your repository here

My workflow has been running for over 314 at this point!
GitHub Actions Result

Conclusion

That was pretty awesome, right? You can of course do this for your own programs and even use completely different languages or setups. If you need any help with setting it up for yourself, please let me know in the comments! Always happy to help :)

PS: Do you want to host your long running Docker apps for cheap? Check out Sliplane! (I'm the Co-Founder 🤫)

Top comments (0)