Skip to content

Latest commit

 

History

History
66 lines (47 loc) · 1.52 KB

deploy-swarm.md

File metadata and controls

66 lines (47 loc) · 1.52 KB

Deploy to Digital Ocean via Docker Swarm

Get $10 in Digital Ocean credit here.

This guide looks at how to deploy a Serverless API to Digital Ocean with OpenFaaS and Docker Swarm mode.

Check out the video here!

Steps

Create droplet:

$ docker-machine create \
  --driver digitalocean \
  --digitalocean-access-token ADD_YOUR_KEY \
  node;

$ docker-machine env node
$ eval $(docker-machine env node)

Build the Docker images for the functions:

$ sh build.sh

Spin up and deploy OpenFaas:

$ docker-machine ssh node \
    -- docker swarm init \
    --advertise-addr $(docker-machine ip node)

$ docker stack deploy func --compose-file docker-compose.yml --prune

Create database and movie table:

$ PG_CONTAINER_ID=$(docker ps --filter name=movies-db --format "{{.ID}}")
$ docker exec -ti $PG_CONTAINER_ID psql -U postgres -W
# CREATE DATABASE movies;
# \c movies
# CREATE TABLE movie(id SERIAL, name varchar);
# \q

Test:

$ curl -X POST \
    $(echo http://$(docker-machine ip node):8080)/function/func_api-create -d \
    '{"name":"NeverEnding Story"}'

$ curl $(echo http://$(docker-machine ip node):8080)/function/func_api-read

$ curl -X POST \
    $(echo http://$(docker-machine ip node):8080)/function/func_api-update -d \
    '{"name":"NeverEnding Story 2", "id": "1"}'

$ curl -X POST \
    $(echo http://$(docker-machine ip node):8080)/function/func_api-delete -d \
    '{"id":"1"}'