Coder Social home page Coder Social logo

wanjikumac / twinklymaha Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sparrell/obe-twinklymaha

0.0 1.0 0.0 1.16 MB

Digital Twin of BlinkyMaHa (ie in cloud instead of on Raspberry Pi, LiveView graphics instead of LEDs)

License: MIT License

Elixir 81.60% Shell 0.64% Dockerfile 1.24% Makefile 3.37% SCSS 1.73% CSS 8.70% JavaScript 2.52% HTML 0.19%

twinklymaha's Introduction

TwinklyMaHa

Twinkly is the digital twin of blinky (ie in cloud instead of on Raspberry Pi, LiveView graphics instead of LEDs).

Blinky looks like: blinky

Twinkly looks like: twinklygif

Setup guide

First ensure you have the following set up in your computer

  • elixir 1.10.4
  • nodejs > 12 LTS
  • Postgresql > 11

You can use the phoenix installation guide to ensure you have everything set up as expected

To start the server:

  • Install dependencies with mix deps.get
  • Create and migrate your database with mix ecto.setup
  • Install Node.js dependencies with npm install inside the assets directory
  • Start Phoenix endpoint with mix phx.server

Now you can visit localhost:4000 from your browser.

Convenience make tasks

This project includes a couple of convenience make tasks. To get the full list of the tasks run the command make targets to see a list of current tasks. For example

Targets
---------------------------------------------------------------
compile                compile the project
format                 Run formatting tools on the code
lint-compile           check for warnings in functions used in the project
lint-credo             Use credo to ensure formatting styles
lint-format            Check if the project is well formated using elixir formatter
lint                   Check if the project follows set conventions such as formatting
test                   Run the test suite

Deployment to GCP

The deployment is done using docker images with the help of make tasks. We can create a docker image, push it to container registry on gcp and then launch an instance using this docker image

The docker image is automatically tagged with the application version from your mix file

Deployment from local machine

Before you begin:

  • Make sure you have write access to the docker registry
  • You will need the necessary permissions to create an instance
  • Docker should be installed in your computer and running
  • GCloud should be well set up, authenticated and initialised to use docker
  • access to production secrets in the prod.secrets.exs file (look at config/prod.sample.exs to see an example)

creating an image for use in your laptop

If you want to create a docker image for use in your laptop then you can use the command

make docker-image

Creating an image and pushing to GCP

You can optionally create an image on your laptop and push it up to GCP container registry using the following command

make push-image-gcp

This will create the image and tag it with the current application version then push the created image to GCP

creating an image and lauching an instance on GCP

You can also run a server on GCP using the docker image by running the following command

make push-and-serve-gcp instance-name=<give-the-instance-a-unique-name>

If you had created an image before and would like to create a running server using the image run:

make deploy-existing-image instance-name=<give-the-instance-a-unique-name>

The instance name you provide above should be unique and should not be existing on GCP already otherwise you will get an error

updating a running instance

If you want to update an already running instance with a different version of the application, you need to ensure that the image is created and pushed to gcr.io using make push-image-gcp after which you can update an instance to use the image.

This is done by specifying the tag to the image you want to use (image-tag) and the running instance you want to update (instance-name)

make update-instance instance-name=<existing-instance-name> image-tag=<existing-tag-on-gcr>

An example would be:

make update-instance instance-name=testinstance image-tag=0.5.0

Custom environment variables

You can set the following custom environment variables when building the image or launching a vm instance

  • CLIENT_ID
  • MQTT_HOST
  • MQTT_PORT
  • USER_NAME
  • PASSWORD

When running the make commands above you can add any of the variables above that you want to customise for example:

make deploy-existing-image instance-name=<a-unique-name> CLIENT_ID=<your_new_id> USER_NAME=<prefered_name>

Accessing twinklymaha

The above procedures create an instance of twinklymaha on GCP with the name you gave it. Using console.cloud.google.compute, go to your virtual machine instances, and look up the external ip (a.b.c.d5) of the instance you just created (if you used one of the make commands then the ip address will be listed upon successful startup of the instance). Note the phoenix webserver is running on port 4000 and the home page is twinkly. Go to http://a.b.c.d:4000/twinkly Note it is http not https

twinklymaha's People

Contributors

sigu avatar sparrell avatar

Watchers

 avatar

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.