dockerized (postgres + nginx + golang + react)

Related tags

Miscellaneous pngr

PNGR Stack

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

Only implements basic user signup, session management, and a toy post type to demonstrate basic CRUD. PNGR is not a CMS.


  • Hot-reload, front and back, including a test-runner for golang changes
  • JSON Web-Token cookies with automatic refresh: ready for horizontal scaling
  • Uses multi-stage builds for small production images
  • Feature development is up to you!


  • Install docker && docker-compose

Quick Start

  1. docker-compose up
  2. Visit https://localhost (note https)
  3. Approve the self-signed cert
  4. Make changes to either golang or react code, and enjoy hot-reload goodness!

Preview of the app:

Screenshot of the app

Rebuilding your dev environment

Maybe your postgres went sideways from a wonky migration and you don't want to muck with fixing it.

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

Deploying to Production

Warning: Run in production at your own risk - this code is not security hardened!

You should install postgresql on the host. Then you can use to build lean images to use in production. Don't forget to copy .env.example -> .env and setup your secrets/passwords.


Some tips for working with your postgres docker instance

Creating and running migrations

Migrations are run using go-migrate.

I put together little bash scripts to help you get stuff done.

  • postgres/ my_migration_name will create a template for the next migration
  • postgres/ will execute any new migrations (this is used when the container is created)
  • postgres/ makes it easy to run arbitrary go-migrate commands (e.g. postgres/ down 1)

You can do more advanced migrate commands

Opening a psql client

docker-compose exec postgres psql -U postgres Remember to use \q to exit.


Nginx is simply used to route requests to the front-end and back-end based on path. It also terminates SSL so that we don't have to deal with certs in our app layer.


Almost-vanilla golang api:

  • Makes use of go modules for dependencies
  • jwt-go for JSON Web Tokens
  • sqlx for better postgres interface


The basic building blocks of the front-end are:

  • Docker virtual network

    Docker virtual network

    Make the production independent of host system

    • Removed host network from
    • Removed exposed ports
    • Added container references in
    opened by Lebski 4
  • Using Docker cache mechanism in Dockerfile

    Using Docker cache mechanism in Dockerfile

    If you change your source code without changing the dependencies, Docker will use it's caching mechanism. Will result in faster build time.

    Step 6/13 : COPY ./package.json ./package.json
     ---> Using cache
     ---> 4fcc47d4c72d
    Step 7/13 : RUN npm install
     ---> Using cache
     ---> c0671131e8ed
    opened by Lebski 3
  • GitHub Actions for CI

    GitHub Actions for CI

    I'd like the ability to clone this repo, start hacking, push code to my repository and have a GitHub Actions pipeline run. The pipeline could be really simple, like just running my backend tests.

    Being able to edit an existing GitHub Actions config file is way easier than trying to set everything up from scratch.

    opened by veeral-patel 3
  • reduce image size

    reduce image size

    Hello just a minor optimization, as the Docker Document says, when you clean up the apt cache by removing /var/lib/apt/lists it reduces the image size, since the apt cache is not stored in a layer.

    so I add this line into the Dockerfile to reduce the image size

    could it really reduce the image size?

    my company network environment is not good. When I get off work, I will prove it, wait a minute!

    opened by brownchow 2
  • faster react container startup

    faster react container startup

    npm install makes it take forever for the react dev server to start.

    Had to do it this way to avoid requiring container rebuild anytime you added a package... not sure if there's a better way.

    Related issue: Probably should have helpers or documentation for running NPM commands in the container(!) for folks that don't have local npm setup and configured

    opened by karlkeefer 2
  • Docker build error

    Docker build error

    root/go/src/ undefined: errors.As root/go/src/ undefined: errors.Is

    root/go/src/ undefined: errors.As ERROR: Service 'postgres' failed to build: The command '/bin/sh -c go get -tags 'postgres' -u && cp /root/go/bin/migrate /bin/migrate' returned a non-zero code: 2

    opened by nyousefzai 1
  • Add startup logs to react

    Add startup logs to react

    Possible solution to .

    I thought the app was broken when I first started it, as the docker-compose logs don't indicate anything is still happening in the react app until after a long (> 1 minute) NPM install process finishes.

    Another alternative would be to npm install --loglevel info.

    opened by DylanNWatt 1
  • Postgres image will not build from new Debian base image

    Postgres image will not build from new Debian base image

    It appears that the Postgres Dockerfile was switched to use debian base instead of alpine, but the alpine apk package management was left in, so the image no longer builds.


    opened by DylanNWatt 1
  • Reset Password

    Reset Password

    This PR is a good example of "feature development" - though it does include various unrelated small fixes that I encountered while working...

    New DB tables, new (generated) db binding code, new API handlers, and new front-end views.

    It also adds a mailer interface for integrating a transactional email service

    opened by karlkeefer 0
  • Sqlc, cleaner migrations, etc.

    Sqlc, cleaner migrations, etc.

    Addressing #30

    • [x] use gomock to generate database mocks for use in testing
    • [x] use modd to generate sqlc bindings and mocks on-save
    • [x] exclude json fields we don't want to send via API e.g. User.verification
    opened by karlkeefer 0
  • Less boilerplate using sqlc

    Less boilerplate using sqlc

    I think we could dramatically increase dev velocity by auto-generating our models/repos with sqlc!

    Use this opportunity to fix/improve the migration file formats and helper scripts.

    opened by karlkeefer 0
  • Configuration files for deploying to the cloud

    Configuration files for deploying to the cloud

    Hi! I just saw your HN post. You're right -- being able to just run docker-compose up makes me a lot more inclined to start developing something new.

    However, I'm reluctant to deploy my application to production using Docker. For the frontend I'd like to use something like Netlify for caching/web UI and for the backend I'd like to use something like App Engine for monitoring/scaling/etc

    I feel like if you added an App Engine and Netlify configuration file, so you could clone the project and deploy to "production" in 2 commands, that would move this project to the next level :)

    opened by veeral-patel 2
Karl Keefer
Full Stack Software Engineer
Karl Keefer
React + Golang boilerplate

React + Golang boilerplate Note: Optimized for running Docker in Linux where you can use port 80 without running docker-compose as root unless you mes

Mikael Grön 0 Feb 14, 2022
A reproducible example for an issue I'm encoutering when deploying my gunicorn app to nginx

Ngnix Issue This is a minimum, reproducible example for an issue I'm encoutering when deploying my gunicorn app to nginx. Installation (Linux) Webserv

Space Simulation Services of Canada Corporation 1 May 29, 2022
Boilerplate for building a monolighic Go and React application

Monolithic Go and React Application Boilerplate This repository provides a simple and monolithic service with a server written in Go and frontend with

Shin'ya Ueoka 18 Sep 17, 2022
Onboarding exercise to create todo list using golang and postgres

Todo List API Description A RESTful API that allows a user to create, update, view, filter, and delete todos API Documentation Copy the contents of th

null 0 Dec 1, 2021
Web app built with Go/Golang and Buffalo, deployed on Heroku, using Heroku Postgres

hundred-go-buffalo Background Read Go Read Buffalo Read Getting Started on Heroku with Go Recommended Tools PowerShell terminal Chocolatey Windows pac

Denise Case 0 Dec 18, 2021
Golang CS:GO external base. Development currently halted due to compiler/runtime Golang bugs.

gogo Golang CS:GO External cheat/base. Also, my first Golang project. Wait! Development momentarily halted due to compiler/runtime bugs. Disclaimer Th

cristei 2 Jun 25, 2022
Belajar Golang Install Golang

Golang belajar Golang Install Golang = download di = pilih yg Zip = extract file zipnya = buka foldernya - copy folder go = pas

Arif Fadilah 1 Nov 15, 2021
Golang-module-references - A reference for how to setup a Golang project with modules - Task Management + Math Examples

Golang Module Project The purpose of this project is to act as a reference for setting up future Golang projects using modules. This project has a mat

Bob Bass 0 Jan 2, 2022
Golang-echo-sample - Make an out-of-the-box backend based on golang-echo

Golang-echo-sample - Make an out-of-the-box backend based on golang-echo

Haitwang 0 Dec 31, 2021
Minimalistic, pluggable Golang evloop/timer handler with dependency-injection

Anagent Minimalistic, pluggable Golang evloop/timer handler with dependency-injection - based on codegangsta/inject - go-macaron/inject and chuckpresl

Ettore Di Giacinto 14 Jan 26, 2022
GoLang Library for Browser Capabilities Project

Browser Capabilities GoLang Project PHP has get_browser() function which tells what the user's browser is capable of. You can check original documenta

Maksim N. 43 Sep 27, 2022
Golang counters for readers/writers

Datacounter Golang counters for readers/writers. Examples ReaderCounter buf := bytes.Buffer{} buf.Write(data) counter := datacounter.NewReaderCounter(

Artem Andreenko 42 Sep 27, 2022
Golang beautify data display for Humans

Golang beautify data display for Humans English 简体中文 Install # Stable version go get -u -v # Latest version go get -u -v

ffmt 280 Sep 27, 2022
a generic object pool for golang

Go Commons Pool The Go Commons Pool is a generic object pool for Golang, direct rewrite from Apache Commons Pool. Features Support custom PooledObject

jolestar 1.1k Sep 27, 2022
Resiliency patterns for golang

go-resiliency Resiliency patterns for golang. Based in part on Hystrix, Semian, and others. Currently implemented patterns include: circuit-breaker (i

Evan Huus 1.6k Sep 15, 2022
psutil for golang

gopsutil: psutil for golang This is a port of psutil ( The challenge is porting all psutil functions on some arch

shirou 8.2k Sep 25, 2022
Type-safe Prometheus metrics builder library for golang

gotoprom A Prometheus metrics builder gotoprom offers an easy to use declarative API with type-safe labels for building and using Prometheus metrics.

Cabify 94 Sep 27, 2022
Simple licensing library for golang.

license-key A simple licensing library in Golang, that generates license files containing arbitrary data. Note that this implementation is quite basic

Hyperboloide 252 Sep 18, 2022
Some utilities for Persian language in Go (Golang)

persian Some utilities for Persian language in Go (Golang). Installation go get API .ToPersianDigits Converts all English d

هلو | آموزش زبان با بازی 65 Sep 2, 2022