Search code examples
dnsgithub-actionssubdomaingithub-pagesaws-route53

Github Pages Repository with custom subdomain in route 53


I have recently created a repository and I've been deploying it to github pages using the standard .yaml file from github actions, so far so good, I can access it through .github.io/repo-name however, I am trying to set up a custom subdomain to redirect it do the github paage. I have got the oneexample.com hosted zone in AWS Route 53 and I want to have the domain repo-name.oneexample.com to redirect it to gh pages but I cannot get it to work. Most of the posts in the internet are using subdomains to route to base user pages, which Is not what I need. I have also read that I should need to wait for up to 24 hrs for the Route 53 DNS to propagate, but I also don't believe that is the case as Route53 should propagate the DNS configs within 1 minute. What I have tried so far:

Scenario 1:

  • Setting A record on route53 from oneexample.com to the 4 IP's mentioned on the github pages doc
  • Setting CNAME from repo-name.oneexample.com to .github.io
  • Adding repo-name.oneexample.com on the github page configuration on the repo settings.

Scenario 2:

  • Setting CNAME from repo-name.oneexample.com to .github.io
  • Adding repo-name.oneexample.com on the github page configuration on the repo settings.
  • Creating CNAME file in the root of the repo with repo-name.oneexample.com on it.

Scenario 3:

  • Setting A AND AAAA records on route53 from oneexample.com to the 4 IP's mentioned on the github pages doc
  • Adding oneexample.com on the github page configuration on the repo settings.

None of these worked, the thing is that I need a SUBDOMAIN (.oneexample.com) to resolve to a REPO GITHUB PAGE (.github.io/) and where my apex domain is oneexample.com.

I think the issue COULD BE the github actions, which is something I don't quite have understanding on how it works but as the github page was deployed correctly at .github.io I presumed it might not interfere in the whole DNS resolving thing.

I have tried several configurations just like mentioned above.

Edit1 The default github actions file is as follows:

# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
  # Runs on pushes targeting the default branch
  push:
    branches: ["Develop"]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
  group: "pages"
  cancel-in-progress: false

jobs:
  # Single deploy job since we're just deploying
  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Setup Pages
        uses: actions/configure-pages@v5
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3
        with:
          # Upload entire repository
          path: '.'
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4

Could it be the ${{ steps.deployment.outputs.page_url }} is trying to use the custom domain configuration on the repo settings and therefore not deploying in the correct .github.io/ path?


Solution

  • Turns out that out of all things that could go wrong, I have bought the domain, it was still not up so I basically had the Hosted Zone DNS configuration but not the domain. For anyone checking this, if you need any help, the only steps you need to follow are:

    • Confirm that your domain was successfully bought and its up and running - Do not skip this step :D
    • Create a hosted zone with CNAME from subdomain.domain.extension to .github.io
    • Add CNAME file in the root of the repo with subdomain.domain.extension and configure the same subdomain in repo settings -> pages.
    • The DNS might show error, but its due to DNS Propagation, it could take some time.