enisgurkann / pngr

dockerized (postgres + nginx + golang + react)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New in September 2021

I've finally upstreamed various upgrades I made on forked projects:

  1. Auto-generated database code and mocks with the amazing sqlc and gomock packages πŸ™‡β€β™‚οΈ
  2. Vastly simplified routing on front-end and back-end... thanks httprouter!
  3. Functional-style components throughout, including some helpful custom hooks to simplify building forms
  4. Added password reset functionality (and stubbed out a transactional email interface)
  5. Standardized handler type for the API, with improved default middlewares
  6. Simplified migrations and postgres helper scripts
  7. Upgraded the Semantic UI integration to allow altering theme variables
  8. Various other improvements/tweaks/bugfixes
  9. Added a ping-pong emoji to calcify my preferred pronunciation πŸ˜…

PNGR Stack πŸ“

Dockerized (postgres + nginx + golang + react) starter kit

Only implements users, sessions, and a toy post type to demonstrate basic CRUD. PNGR is not a CMS.

Features

  • Hot-reload, front and back, including a test-runner for golang changes
  • golang-migrate already configured for easy migrations
  • sqlc for auto-generated sql bindings and mocks (also rigged with hot-reload!)
  • jwt-go cookies with automatic refresh: ready for horizontal scaling
  • A golang worker container stubbed out for async (non-API) tasks
  • Unejected Create React App as the basis for the front-end
  • React Router for simple front-end routing
  • React Context for global state
  • Semantic UI React for component library
  • Feature development is up to you!

Requirements

Install docker && docker-compose

Quick Start

# clone the repo
git clone https://github.com/karlkeefer/pngr.git my_project_name

# copy the .env template for your local version
cp .env.example .env

# build and start the containers
docker-compose up
  1. Visit https://localhost (note https)
  2. Approve the self-signed cert
  3. Make changes to go, sql, or react code, and enjoy hot-reload goodness!

Database Helpers

Migrations

Migrations are created and run using simple wrappers around go-migrate.

# create files for a new migration
postgres/new my_migration_name

# execute any new migrations (this is also run automatically the container is created)
postgres/migrate up

# go down 1 migration
postgres/migrate down 1

Open a psql client

# remember to use \q to exit
postgres/psql

Rebuild everything, including database(!), from scratch

Maybe your postgres went sideways from a wonky migration and it's easier to restart from scratch.

docker-compose down -v && docker-compose up --build --force-recreate

Deploy to Production

Warning: Run in production at your own risk!

docker-compose.prod.yml is designed for a setup where postgresql is not dockerized. Pulling images from a registry and/or using CI/CD is up to you.

Don't forget to copy .env.example -> .env and setup your secrets/passwords for the new environment! At minimum you'll need to change ENV, APP_ROOT, and TOKEN_SECRET!

# build production images, and run them in a detached state
docker-compose -f docker-compose.prod.yml up --build -d

About

dockerized (postgres + nginx + golang + react)

License:MIT License


Languages

Language:Go 57.1%Language:JavaScript 37.3%Language:Dockerfile 2.7%Language:Shell 1.9%Language:HTML 0.6%Language:CSS 0.5%