Beautifully simple single author blog in Go - derived from Bear Blog.

Overview

Polar Bear Blog 🐻‍❄️

Go Report Card GoDoc GitHub Actions status Coverage Status

Lightweight blogging system for a single author. Written in Go and deploys to your own GCP project with a few commands. It's a derivative of the beautifully simple Bear Blog 🐻 . The data storage and session storage are stored in Google Cloud Storage as objects. Depending on the traffic and blog size, it should (not guaranteed) cost less than $1 USD per month (compute and storage) to host this blog because it will be deployed to Google Cloud Run which bills to the nearest 100 millisecond. You can also map your own domain name and Google will provide a free SSL certificate. This project uses make to simplify the deployment process.

You can see an active website using this stack here. You can read the blog post on this project here.

Quickstart on Local

  • Clone the repository: [email protected]:josephspurrier/polarbearblog.git
  • Create a new file called .env in the root of the repository with this content:
# App Configuration
## Session key to encrypt the cookie store. Generate with: make privatekey
PBB_SESSION_KEY=
## Password hash that is base64 encoded. Generate with: make passhash passwordhere
PBB_PASSWORD_HASH=
## Username to use to login to the platform at: https://example.run.app/login/admin
PBB_USERNAME=admin
## Enable use of HTML in markdown editors.
PBB_ALLOW_HTML=false
## GCP bucket name (this can be one that doesn't exist yet).
PBB_GCP_BUCKET_NAME=sample-bucket
## Optional: enable MFA (TOTP) that works with apps like Google Authenticator. Generate with: make mfa
# PBB_MFA_KEY=
## Optional: set the time zone from here:
## https://golang.org/src/time/zoneinfo_abbrs_windows.go
# PBB_TIMEZONE=America/New_York

# GCP Deployment
## GCP project ID.
PBB_GCP_PROJECT_ID=my-sample-project-191923
## Name of the docker image that will be created and stored in GCP Repository.
PBB_GCP_IMAGE_NAME=sample-image
## Name of the Cloud Run service to create.
PBB_GCP_CLOUDRUN_NAME=sample-service
## Region (not zone) where the Cloud Run service will be created:
## https://cloud.google.com/compute/docs/regions-zones#available
PBB_GCP_REGION=us-central1

# MFA Configuration
## Friendly identifier when you generate the MFA string.
PBB_ISSUER=www.example.com

# Local Development
## Set this to any value to allow you to do testing locally without GCP access.
## See 'Local Development Flag' section below for more information.
PBB_LOCAL=true
  • To generate the PBB_SESSION_KEY variable for .env, run: make privatekey. Overwrite the line in the .env file.
  • To generate the PBB_PASSWORD_HASH variable for .env, run: make passhash passwordhere. Replace with your password. Overwrite the line in the .env file.
  • To create the session and site files in the storage folder, run: make local-init
  • To start the webserver on port 8080, run: make local-run

The login page is located at: http://localhost:8080/login/admin.

To login, you'll need:

  • the username from the .env file for variable PBB_USERNAME - the default is: admin
  • the password from the .env file for which the PBB_PASSWORD_HASH was derived

Once you are logged in, you should see a new menu option call Dashboard. From this screen, you'll be able to make changes to the site as we as the home page. To add new posts, click on Posts and add the posts or pages from there.

Quickstart on GCP

By following these instructions, you can get a blog public easily:

  • Create a Google GCP project
  • Update the .env file with your information - see section above for content
  • Run this command to initialize the store by creating the GCP bucket, enabling versioning, and then copying 2 blank files to the bucket: make gcp-init. You will need to have the Google Cloud SDK installed. You will also need a service account key downloaded on your system with an environment variable set to the JSON file like this: GOOGLE_APPLICATION_CREDENTIALS=~/gcp-cloud-key.json.
  • Run this command to build the docker image, push to the Google repository, and then create a Cloud Run job: make.

Once the process completes in a few minutes, you should get a URL to access the website. The login page is located at (replace with your real URL): https://example.run.app/login/admin.

Development

If you would like to make changes to the code, I recommend these tools to help streamline your workflow.

# Install air to allow hot reloading so you can make changes quickly.
curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s

# Install direnv and hook into your shell. This allows you to manage 
# https://direnv.net/docs/installation.html

Once you have direnv installed, create .envrc file. Update the GOOGLE_APPLICATION_CREDENTIALS variable to the correct location on your hard drive of the app credentials. You can generate and download a service account key from: https://console.cloud.google.com/apis/credentials/serviceaccountkey.

# Load the shared environment variables (shared with Makefile).
# Export the vars in .env into the shell.
export $(egrep -v '^#' .env | xargs)

export PATH=$PATH:$(pwd)/bin
export GOOGLE_APPLICATION_CREDENTIALS=~/gcp-cloud-key.json

You can then use this commands to test and then to deploy.

# Start hot reload. The web application should be available at: http://localhost:8080
air

# Upload new version of the application to Google Cloud Run.
make

Local Development Flag

When PBB_LOCAL is set, the following things will happen:

  • data storage will be the local filesystem instead of in Google Cloud Storage
  • redirects will no be attempted so you can use localhost:8080
  • MFA, if enable will accept any number and will always pass validation
  • Google Analytics will be disabled if set
  • Disqus will be disabled if set

Screenshots

Home Page

Home

Dashboard

Dashboard

Custom Styles

Styles

Create a Post

Create a Post

View a Post

View a Post

StackEdit

StackEdit

You might also like...
Everything a semantic desktop search engine combined with a single-user document management system

Everything will be a semantic desktop search engine combined with a single-user document management system. It will apply ideas of the semantic web and knowledge graphs to organize your data, allowing you to maintain private knowledge graphs as well as make use of public knowledge graphs, such as Wikidata.

listmonk is a standalone high performance, self-hosted newsletter and mailing list manager with a modern dashboard. Single binary app.
listmonk is a standalone high performance, self-hosted newsletter and mailing list manager with a modern dashboard. Single binary app.

listmonk is a standalone, self-hosted, newsletter and mailing list manager. It is fast, feature-rich, and packed into a single binary. It uses a PostgreSQL database as its data store.

Gramaddict web UI interface for a single device

Gramaddict web UI interface for a single device allow you to see the logs in real time, start and stop the bot all from your browser.

A cross platform single binary tool to work with draw io files

SNIPO SNIPIO is a cross platform single binary tool to work with draw io files With snipio you can do the following operations: list all layers in a d

Simple Bank is a simple REST API that allows users to perform transferences with each other.

Simple Bank is a simple REST API that allows users to perform transferences with each other. 🔧 Technologies Golang Docker PostgreSQ

Consul Load-Balancing made simple
Consul Load-Balancing made simple

Notes From release 1.5.15 onward, fabio changes the default GOGC from 800 back to the golang default of 100. Apparently this made some sense back in t

goof is a woof written in go - share files via a simple httpd

#goof - share files through HTTP protocol goof (Go Offer One File) is a very simple tool to send and receive files on your local LAN. Features include

Simple bookmark manager built with Go
Simple bookmark manager built with Go

Shiori This project is now maintained by Dean Jackson (@deanishe). The awesome original author, @RadhiFadlillah, unfortunately no longer has the time

Remark42 is a self-hosted, lightweight, and simple comment engine
Remark42 is a self-hosted, lightweight, and simple comment engine

Remark42 is a self-hosted, lightweight, and simple (yet functional) comment engine, which doesn't spy on users. It can be embedded into blogs, articles or any other place where readers add comments.

Comments
  • Add S3 Bucket Support

    Add S3 Bucket Support

    By providing the following parameters, a user can enable the site to run off of S3 instead of GCP storage

    export PBB_AWS_BUCKET_NAME=polarbear
    export PBB_AWS_REGION=us-west-2
    export PBB_CLOUD_PROVIDER=aws
    

    Also make file updated for aws commands,

    Im new to Golang, so that that into consideration.

    opened by crhuber 0
  • Makefile improvements

    Makefile improvements

    1. Add "export " to .env example in README, as GNU make by default does not pass the environment variables to sub commands (go run) without "export".
    2. Add --project arg to gcloud commands.
    3. For gcp-init, change from session.json to session.bin as that's what's expected by the code.
    4. Add missing testdata/empty.[bin,json] files used by gcp-init.
    opened by fishy 0
Owner
Joseph Spurrier
Code by a technologist who specializes in web technologies and automation. Frequently looking for productivity improvements. Writings in the blog.
Joseph Spurrier
A simple blog based on gin framework

gin-blog 介绍 a simple blog based on gin framework 软件架构 MySQL/MariaDB as database 安装教程 基于Docker启动MySQL/MariaDB 使用说明 启动MySQL in Docker. 参与贡献 Fork 本仓库 新建

jimmyyem 0 Nov 15, 2021
Simple Go BE to serve blog posts

Simple Go BE to serve blog posts

Kevin Laborda 0 Jan 25, 2022
Hosting of the "Programming DIY / Программирование - это просто!" blog

This repository contains materials of the personal blog "Программирование - это просто / Programming DIY". How to use the blog engine A blog post abou

Alexander Demin 39 Jul 15, 2022
gin api blog

Gin项目 介绍 以下是基于gin开发的项目接口,将持续更新,有兴趣请star,本项目包含mysql,redis,elasticsearch,mongo,rabbitmq,kafka,jaeger,单机限流,分布式限流,sentry, jwt,请求参数验证,发送邮件,图片上传,httpclient用

Colin 17 May 10, 2022
Blog backend system based on GO

个人博客后端文档 简介 相关功能 v0.1 用户登录、注册 文章发布、查看、评论、点赞 粉丝相关(关注) v0.2 排行榜(文章发布数量、粉丝) v0.3 流量统计 技术栈 语言选用go 大致技术栈选用: kratos + redis + jwt + gorm 项目地址 todo 项目结构

Leslie Lau 0 Nov 26, 2021
Blog backend based on go implementation

个人博客后端文档 简介 相关功能 v0.1 用户登录、注册 文章发布、查看、评论、点赞 粉丝相关(关注) v0.2 排行榜(文章发布数量、粉丝) v0.3 流量统计 技术栈 语言选用go 大致技术栈选用: kratos + redis + jwt + gorm 项目地址 todo 项目结构

Leslie Lau 0 Dec 4, 2021
An implementation of a backend blog microservice written in go.

Blog This is an implementation of the backend of a blog service written in Go 1.17 created with a microservice architecture in mind. Currently impleme

Alan Parrish 1 Dec 9, 2021
A blog system implemented via golang.

goblog functions work as a blog site read/write blogs signup/signin/logout vote with stars 1~5 user admin: add ranks to users: bronze, silver, gold wo

彭 0 Jan 5, 2022
DCreater - Build your own blog system with golang

DCreater - Build your own blog system with golang

null 2 Aug 18, 2022
Blog - Exploring Domain Driven Design In Go

Exploring Domain Driven Design In Go

Sammi Aldhi Yanto 1 Jan 25, 2022