Giter Site home page Giter Site logo

openfaas-vagrant's Introduction

openfaas-vagrant

OpenFaaS in your local environment.

Prerequisites

  • Virtualbox - A a free and open-source hosted hypervisor for x86 virtualization.
  • Vagrant - A tool for building and distributing development environments.
  • faas-cli - Official CLI for OpenFaaS.

Overview

The Vagrantfile will create a virtual machine running Ubuntu 18.04 LTS (Bionic Beaver) in Virtualbox. It will install OpenFaaS using the faasd provider for a single node.

Usage

Run the following command to deploy openfaas:

$ vagrant up

You will be prompted with a message asking to select a Docker container registry (optional):

Choose a Container Registry Server:
1) Docker (docker.io)
2) GitHub (ghcr.io)
3) Quay   (quay.io)
4) Other registry # <- provide your own url
5) Skip # <- skip if you want to keep your docker images locally
0) Quit # <- exit the script, you will have to destroy the VM afterwards
Enter selection [0-5]: 

If you haven't selected Skip or Quit, you will be asked for your credentials:

Virtual machine needs your credentials for the container registry ghcr.io
Username: dysonfrost
Password:

When the VM is ready, vagrant will display some information:

### Vagrant Box provisioned! ###
------------------------------------------------------
Local OpenFaas is ready

URLS:
 * OpenFaaS - http://192.168.50.2:8080

OpenFaaS credentials:
 * username: admin
 * password: <generated_password>

Login with faas-cli:
 $ export OPENFAAS_URL=http://192.168.50.2:8080 # From Host
 $ faas-cli login -u admin --password <generated_password>

------------------------------------------------------

If somehow you need to retrieve your generated password:

$ vagrant ssh
vagrant@openfaas:~$ sudo cat /var/lib/faasd/secrets/basic-auth-password

CLI

OpenFaas can be accessed from both the host and the guest VM, once logged in (see information above) you can build a new function.

List templates from store

$ faas-cli template store ls

Pull templates from store

# faas-cli template store pull <template>
$ faas-cli template store pull dockerfile

Download templates from specified git repo

$ faas-cli template pull <repository_url>

Create a new function

# faas-cli new <function> --lang=<template>
$ faas-cli new hello-world --lang=dockerfile

Checkout the YAML file

version: 1.0
provider:
  name: openfaas
  gateway: http://192.168.50.2:8080
functions:
  hello-world:
    lang: dockerfile
    handler: ./hello-world
    image: hello-world:latest
  • gateway - URL of the gateway (set to localhost if running from VM guest)
  • lang - Template associated with the function
  • handler - The folder / path to your handler / Dockerfile and any other source code you need
  • image - The Docker image name. If you are going to push to a container registry change the prefix of your image - i.e. ghcr.io/dysonfrost/hello-world:latest

Build a function

# faas-cli build -f <function>.yml
$ faas-cli build -f hello-world.yml

Skip the following steps if you do not intend to use a remote registery to invoke a function.

Push a function

# faas-cli push -f <function>.yml
$ faas-cli push -f hello-world.yml

Deploy a function

# faas-cli deploy -f <function>.yml
$ faas-cli deploy -f hello-world.yml

Build, push and deploy a function

# faas-cli up -f <function>.yml
$ faas-cli up -f hello-world.yml

Invoke a function

# faas-cli invoke <function>
$ faas-cli invoke hello-world

# Using cURL
curl http://192.168.50.2:8080/function/hello-world

Invoke a function with some data

# echo "<some-data>" | faas-cli invoke <function>
$ echo "Hi there!" | faas-cli invoke hello-world

# Using cURL
curl http://192.168.50.2:8080/function/hello-world -d "Hi there!"

UI

A user interface is available at http://192.168.50.2:8080/ui/
You can Deploy and Invoke new functions from there.

Uninstall

To delete the virtual machine, run the following command:

$ vagrant destroy -f

References

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.