Skip to content

Instantly share code, notes, and snippets.

@davenicoll
Last active March 7, 2024 21:49
Show Gist options
  • Save davenicoll/b3e4f37b2ed4cf9876386ae26898a5bd to your computer and use it in GitHub Desktop.
Save davenicoll/b3e4f37b2ed4cf9876386ae26898a5bd to your computer and use it in GitHub Desktop.
Publish Ghost CMS from a private GitHub repo to a public Github Pages repo
name: Run Ghost, generate static content, and publish to github pages
on:
push:
branches: [main]
jobs:
deploy:
concurrency: ci-${{ github.ref }}
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2
with:
submodules: true
- name: Run Ghost 👻
run: docker run -d -p 2368:2368 -e NODE_ENV=development -e database__connection__filename='/var/lib/ghost/content/data/ghost.db' --name "ghost" -v ${{ github.workspace }}/content:/var/lib/ghost/content ghost:latest
# - name: Debug
# run: |
# echo "Debug..."
# sleep 10
# docker container ls -a
# ID=$(docker inspect --format="{{.Id}}" ghost)
# echo "Logs ($ID)..."
# docker logs "$ID"
- name: Sleep for 10 seconds 💤
uses: jakejarvis/wait-action@master
with:
time: "10s"
- name: Install ghost-static-site-generator ✨
run: npm install -g ghost-static-site-generator
- name: Generate Static Site 🛠️
run: gssg --url https://your-domain.com
- name: Deploy to Github Pages 🚀
uses: JamesIves/[email protected]
with:
branch: main #gh-pages
folder: static
token: ${{ secrets.DEPLOY_PAT }}
repository-name: your-github-username/your-github-username.github.io
@davenicoll
Copy link
Author

davenicoll commented Mar 7, 2024

Instructions -

  1. create two repositories:
    1. yoursite - this is the private repository you'll store your site in, containing ghost, themes, etc.
    2. your-site.github.io - this is the repo we'll publish from ghost to
  2. goto https://github.com/your-username/your-site.github.io/settings/pages and enable github pages
  3. create a personal access token in GitHub and add it as a secret called DEPLOY_PAT to the your-site repo (https://github.com/your-github-username/your-site/settings/secrets/actions)
  4. add a file called CNAME to the root of your-site.github.io, containing your domain name to enable github pages to server content for your domain (see here for help)
  5. update your DNS (this is my terraform to use route 53, but you can set this any way you prefer) -
resource "aws_route53_record" "A" {
  name    = "your-site.com"
  records = ["185.199.108.153", "185.199.109.153", "185.199.110.153", "185.199.111.153"]
  ttl     = "300"
  type    = "A"
  zone_id = aws_route53_zone.zone.zone_id
}

resource "aws_route53_record" "www" {
  name    = "www.your-site.com"
  records = ["your-site.github.io"]
  ttl     = "300"
  type    = "CNAME"
  zone_id = aws_route53_zone.zone.zone_id
}
  1. add this workflow to .github/workflows in the yoursite repo
  2. using docker, pull dockerhub.com/ghost/ghost:latest, and mount /content within the yoursite repo to /var/lib/ghost/content
  3. make your updates locally, and when you're done, git push the yoursite repo. The github action will publish your changes to your-site.github.io, and after a few minutes, you'll be able to see the changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment