Giter VIP home page Giter VIP logo

freyr's Introduction

Build Status Go Report Card GoDoc blog

asdf

What?

A pet project to design a simple garden sensor and custom server for aggregating data and providing a simple user interface.

  • Nginx gateway for scaling, static file hosting, and SSL termination
  • Golang API backend
  • ReactJS single page web app
  • Postgres database
  • Docker driven integration tests and deployment
  • More buzzwords as I can add them in, sorry no Haskell in the foreseeable future

Why?

The intent is to merge my interests in sustainability, backend system software development, embedded programming, and electronics tinkering while providing the opportunity to practice with programming techniques I may not get to use as much as I like during my day-job.

Where?

Running @ https://freyr.erdmanczyk.com

![login](repo_files/Screenshot 2016-05-09 23.17.39.png "Freyr") ![latest](repo_files/Screenshot 2016-05-09 23.17.48.png "Freyr") ![chart](repo_files/Screenshot 2016-05-09 23.18.04.png "Freyr")

How?

Want to run this on your own machine? There's a bit of setup; follow the steps below:

Install prerequisites

You will first need to install the prerequisite tools:

  1. Go
  2. Docker
  3. Docker-Compose
  4. Webpack (optional, see below)

When possible, I highly reccomend installing using a package manager such as homebrew for mac.

Generate a Google Oauth Id/Secret

These are necessary for Google oauth login within the app to work. Generating these and configuring Google oauth is beyond the scope of this how-to, but this guide is a good comprehensive walk-through.

You don't need to worry about updating any code in the repo, you just need to worry about:

  • Creating your Google 'app'
  • Generating your id/secret
  • Adding your allowed callbacks
    • The Golang server tells Google where to redirect users when they've authorized, Google rejects url's you haven't configured as allowed.
    • For running locally you will need a url with localhost or <docker_vm_ip> (if running docker in a VM) as the domain name
    • For production, of course, you will need a url with your server's domain name.

Generate configuration

This app uses environment variables for configuration in containers. Docker-Compose loads these from .env files. I didn't include these with the repo because I didn't want to encourage cloning, running, and then forgetting you're running with potentially insecure values.

Instead, I created a tool to manage config.

After you've setup your $GOPATH, etc. take the following steps:

  1. Clone this repo to $GOPATH/src/github.com/serdmanczyk/freyr
  2. cd to cmd/init_freyr/ in the project and run go build
  3. ./init_freyr takes some flags for config values, run with -h to see them. With the flags provided it will automatically generate needed config files, including the nginx configuration.

Generate a server key/certificate

  1. Run ./gencert.sh in cmd/init_freyr/ to generate a key/certificate. It uses openssl, so you will need that installed.

OpenSSL will prompt you for some values, you can goof around on these if you want. For good practice make sure Common Name (e.g. server FQDN or YOUR name) matches the domain name and/or ip (e.g. docker VM ip) you will use to connect to your server.

These are just for local testing, and modern browsers such as chrome will warn it can't verify its authenticity. Once you're in production I highly reccomend using something such as letsencrypt to obtain a verified CA signed certificate.

A note on 'make'

From this point forth I'll be using a Makefile in the repo with common commands for convenience (especially for me, not just other users). If you're not in an environment with make available you can reference the file for the convenienced commands.

Build ReactJS frontend with webpack (optional)

If you plan to make modifications to the frontend, you will need webpack to run this step. If you just want to get up and running you can skip this step as there is a pre-generated bundle.js in the repo.

  1. From project root run make webpack. This will build a 'production' bundle.js file from the React .jsx files.

Run tests

  1. From project root run make buildgo then make test, this will run several commands building go executables and containers as well as running integration and acceptance tests.

If tests pass this verifies that all systems are compiling and functioning correctly together. We are ready to run the app!

Run the app!

There are two ways to run the app: production and dev mode. Production builds all dependencies into the container so it can be shipped to separate machines. Dev mounts in local directories for things such as static web files to enable live reloading and speed up container spin-up/spin-down.

Note if you are running docker in a VM (e.g. mac), you will need to use your docker VM ip:<port> to access the app.

Development

  1. Run make rundev
  2. Navigate to https://<localhost/docker_vm_ip>:8443 in your browser!

Bonus: Because this mounts in directories for static files, if you are editing React files you can run webpack --watch in the nginx/static directory and it will hot reload any changes you make. This was you don't have to constantly rebuild the containers.

Note: dev nginx is configured to listen on 8080/8443 (HTTP/HTTPS). Because of this http->https redirects will fail, because https will by default redirect to 443.

'Production'

  1. Run make buildstatic then make runstatic
  2. Navigate to https://<localhost/docker_vm_ip> in your browser!

To deploy to a server, you will need to run the generate conf steps again but with your server's hostname.

Etymology

Freyr (Fray-ur), the Norse god associated with fertility, sunshine, and fair weather. The CLI testing tool is named after Surtr, the fire giant who battles Freyr to his death at Ragnarök.

The symbol is the Futhark ᚠ (Fehu) (Norse 'F') imposed on a leaf, resembling the leaf's veins. Seen above, it takes the place of the 'F' in Freyr.

freyr's People

Contributors

serdmanczyk avatar serdmanczykatdisney avatar

Stargazers

Phan Quang Huy avatar  avatar Nico avatar Denis Yakimov avatar  avatar Arthur avatar vulcangz avatar  avatar Nikita Puzanenko avatar Ye Myint Oo avatar  avatar Khai Nguyen avatar shanmugharaj avatar  avatar Shammi Shailaj avatar Michael Bøcker-Larsen avatar meission avatar Thomas Shallenberger avatar Milos avatar Justin Shattuck avatar Ege Ozgirin avatar Tyler Gaw avatar Shirish Goyal avatar Chau avatar Pere avatar Victor Pongnian avatar Rob Wright avatar imxiaohui avatar Vasiliy Bukharev avatar Maximilian Szengel avatar Aleksei Melnik avatar Akila Wickey avatar Nuri avatar  avatar Marcos avatar Will Richardson avatar Audrius Sadauskas avatar Suraj Patil avatar Fredrik Steen avatar gaoxiang avatar Gergely Brautigam avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

freyr's Issues

Travis CI build is failing

The command "sudo apt-get -o Dpkg::Options::="--force-confnew" install -y docker-engine=${DOCKER_VERSION}" failed and exited with 100 during .

It appears the command to install docker is outdated; need to research and update.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.