Skip to content

ncmd/jidoka-go-iris

Repository files navigation

Fullstack: Docker + Golang + Iris + API + React + Redux + Heroku + Firestore

This project is not maintained

What is jidoka-go-iris?

* A Fullstack 🐳 Dockerized React App deployable to Heroku
* Uses Iris Web Framework - https://github.com/kataras/iris
* Premade Iris MVC API
* Uses 'dep' - Go Package manager
* Uses Node.js for easy deployment scripts ❤️
* Uses go-bindata to convert React App build to readable go source
* Deployable to Heroku (Supports Free Teir) - heroku.com
* Uses Multi-Stage Builds to create a ~50MB Alpine Linux Image! (Trying to get it Smaller)
* Able to deploy Docker Image to Dockerhub
* Uses Firestore to for queryable JSON style database
* Progressive Web App Rating (On Heroku):
-- 100 Portable Web Application
-- 99 Performance
-- 100 Accessibility
-- 88 Best Practices (Heroku does not support HTTP/2 yet...)

Getting Started

  • If you want to run this for dev mode follow steps 1, 2, and 10
  • If you want to just run the Docker Image follow step 13
  • If you want to deploy this to git/github, dockerhub, heroku, follow all steps
  1. Install Node.js
$ brew update && brew upgrade && brew install node
  1. Manually configure "servername","githubusername","githubprojectname","dockerusername","root-package" variables in 'package.json' & Gopkg.toml files

    • <project_dir>/package.json
    • "servername":"<custom_server_name>" ; ie. jidoka-go-iris
    • root-package = "github.com/<github_username>/<this_github_project>" ; ie. github.com/ncmd/jidoka-go-iris
  2. Setup your github account if you want to deploy it to Github

  3. Run Dev Workspace Setup Script (Only for Brew OSX)

    • Brew Update & Upgrade
    • Installs go
    • Installs dep
    • Installs git
    • Updates npm
    • Setups up env PATH
$ npm run dev-latest
  1. Initialize Github Project (Only if you're signed-in to Github via Github App/Git)
$ npm run dev-github
  1. Install go-bindata. Note to add $GOPATH/bin to your 'env' PATH
$ export PATH=$PATH:/Users/<username>/go/bin
$ go get -u github.com/jteeuwen/go-bindata/...
  1. Install Docker 🐳 Stable (Edge not tested)

  2. Generate a Firestore Service Account Private Key

    • Go to Firebase Console > ⚙️ > Project Settings > Service Accounts > Generate New Private Key
    • Save in the root directory: jidoka-go-iris/firestore.json
  3. Login to Heroku

$ heroku container:login
  1. Login to DockerHub - https://hub.docker.com/
$ docker login --username=yourhubusername
  1. Run Locally (Without Heroku) Listens on port 8000
$ npm run dev
  1. Build/Rebuild and Deploy/Redeploy App to Heroku (Requires Steps 1 - 10)
$ npm run deploy
  1. Run just Docker Image
    • Pull Docker Image form Docker Hub
$ npm run docker-run-image

Details

* Docker Image Size: ~50.0MB
* Fully loads client and server in ~200ms
* Dockerfile - File required for building docker image
* package.json - Node.js deployments scripts
* Gopkg.toml & Gopkg.lock - created by 'dep' (package manager)
* Procfile - Used to run go apps in heroku
* app.go - The App
* client/ - Generated by $ create-react-app
* API Dev Demo: localhost:3000/api/
* API Heroku Demo: <servername>.herokuapp.com/api/

Developer Notes & Tips - DevOps

* Use the 'docker-clean' Node.js Script to stop and delete all old docker images
* Again, the whole 'client' directory was genereated by create-react-app (included when installing react):
-- $ create-preact-app <project-name>
* Always make sure the $GOPATH/bin is added to PATH on local machine (Otherwise will have problems with generating bindata.go)
-- $ export PATH=$PATH:/Users/<username>/go/bin
* Always confirm Docker is RUNNING
* In the .dockerignore file ALWAYS have node_modules folder included (All regenerated when client is built)
* There should ALWAYS be a bindata.go file before building docker image
* Rename a go build executable (Optional):
-- $ go build -o apple *.go
* If you do rename the app name, be sure to update the 'Procfile' and 'Dockerfile'
* When managing dependencies use 'dep' - https://golang.github.io/dep/docs/introduction.html
-- $ dep ensure -add github.com/foo/bar
-- $ dep ensure -update github.com/foo/bar
* When making changes to React App Client, always regenerate bindata.go file (Already done in package.json script)
-- $ go-bindata ./client/build/...

Developer Notes & Tips - Front-End

* Local Proxy is managed by the client/package.json file
-- Adjust the 'path' and 'target' if you have a custom back-end uri or port
* React-Redux Notes:
-- 1. Provider is from 'react-redux'
-- 2. 'react-redux' must be installed for redux to work
-- 3. ALWAYS use promises (async,await) in Actions to confirm data is received
-- 4. To create a new Action:
---- Create a 'Type' in client/src/actions/types.js
---- Import the 'Type' into client/src/actions/index.js
---- Include the 'Type' in dispatch
---- Create a reducer in client/src/reducers/name.js
---- Add that reducer to CombinedReducers in client/src/reducers/index.js
-- 6. If you are using redux, always use {connect} from 'react-redux'

Developer Notes & Tips - Back-End

* All Code is in app.go
* Always separate functions
* func newApp():
-- Uses bindata.go
-- Maps to front-end build
-- Controls '/' Get Path to point to index.html
-- Creates an MVC to point to 'APIController' MVC Controller Type
-- Creates a Static Asset Handler to use all assets from ./client/build path
-- Defines app as a Single Page Application

Scripts

* dev - Runs both client and server without compiling/building supports hot changes
* lambda - Build for AWS Lambda Function
* commit - Commit code, does not Push to Prod/Github
* deploy - Deploys to Heroku and Push to Github
* docker-test - Test Docker Build and Run
* docker-run-image - Runs downloaded Dockerhub Image
* docker-run - Runs docker image
* heroku-deploy - Build + Destroys existing Heroku Server + Recreate Server
* heroku-replace - Destroys existing Heroku Server + Recreate Server
* dockerhub-login - Login to Dockerhub
* docker-tag - Tags Docker Image with Latest
* dockerhub-push - Deploys Docker Image to Dockerhub
* docker-build - Builds Docker image
* docker-clean - Stops all Docker Containers + Deletes all Docker Containers + Existing Deletes Docker Images
* build-client - Runs build script in client directory
* dev-latests - Updates brew, dep, and npm to latest versions
* dev-env - Configures $GOPATH and $GOPATH/bin path in environment variables + creates github project
* dev-github - Creates New Github Project (Must manually set the "githubprojectname" variable)

Notes - Depricated Changes

* Switched back to react from preact because of several incompatible issues ; also performance was about the same
* Preact client is still preserved in 'client-preact' directory

About

Fullstack: Docker + Golang + Iris + API + Preact-App + Node.js + Heroku (deprecated)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors