tapglue / snaas

Tapglue Social Network as a Service (SNaaS)
https://www.tapglue.com
Apache License 2.0
67 stars 22 forks source link

Start up - tutorial #35

Open Abacaxi-Nelson opened 7 years ago

Abacaxi-Nelson commented 7 years ago

Hi,

Thanks for your work, it looks awesome. is there any tutorial to start with ? how to build the platform..

Thanks, Nelson

xla commented 7 years ago

Hej,

Are you interested in learning how to use the platform or how to operate it. Unfortunately the docs are lacking in that area at the moment. Happy to get input of what is essential for somebody to understand the internals. In the meantime there is infrastructure description with terraform and docker/build scripts that show how the binaries are created, orchestrated and monitored.

oxnr commented 7 years ago

@tugal If you're interested in the usage our wiki has a lot of docs: https://github.com/tapglue/snaas/wiki

Abacaxi-Nelson commented 7 years ago

Hi,

Sorry for the delay. At the moment, i'm only insterested in building the platform.

@xla : i will take a look at docker's script @onurakpolat : Yes usage is well documented; build process is not :)

thanks,

alibitek commented 7 years ago

Indeed, would be nice to have a guide on how to self host SNAAS on your own server. Does it work outside of AWS cloud? As from the architecture diagram I see that it has some references to it.

xla commented 7 years ago

@mnemonicflow Hej, it works partially outside of AWS. The API itself has dependencies on Postgres and Redis and therefore can be operated outside of Amazon. If you desire to have notifications working that is currently relying heavily on SQS and SNS.

alibitek commented 7 years ago

As I'm still learning the codebase, can you provide a summary of the components?

For example, what is the purpose of SIMS ? What's the usecase? When it is used? By whom?

xla commented 7 years ago

dataz

Is for simple data export/import, usually when somebody needs a dump of their dataset.

gateway-http

Is the main API at the core of the system.

sims

Listens to state changes in the domain and sends out notifications (push only for now) to registered user devices.

terraformer

Is a wrapper to help with the single-command/out-of-the-box experience of the overall setup. It manages remote state and enforces the understanding of zones, our way of isolating installations.

alibitek commented 7 years ago

Thanks. I've managed to build and run locally the two binaries (gateway-http and sims) in a Docker container using the scripts from the infrastructure directory.

Now I need to figure out how to use the service from the TapGlue Android SDK, i.e.

Configuration configuration = new Configuration("https://api.mytapglueserver.com", "myapikey");
configuration.setLogging(true);
final RxTapglue tapglue = new RxTapglue(configuration, this);
User user = new User("user", "pass");
tapglue.createUser(user).subscribeOn(Schedulers.io()).subscribe(new Observer<User>() {
    @Override
    public void onCompleted() {
        tapglue.loginWithUsername("user", "pass").subscribe();
    }

    @Override
    public void onError(Throwable e) {

    }

    @Override
    public void onNext(User user) {

    }
});

Not sure yet how to generate the different API keys/access tokens required for authentication. Any hints?

alibitek commented 7 years ago

Got it working :+1: by creating a data/apps.json file:

{
    "backend_token": "78a62cac15972206e2b2da4f5a42c5c4",
    "description": "xxx",
    "enabled": true,
    "-": 1,
    "in_production": false,
    "name": "xxx",
    "token": "2da2d79336c2773c630ce46f5d24cb76",
    "url": "https://www.myapp.com",
    "created_at": "2017-03-17T08:44:13.213Z",
    "updated_at": "2017-03-17T08:44:13.213Z"
}

and importing it using ./dataz -data.dir=data -postgres.url='host= user= password= dbname= sslmode=disable connect_timeout=5' import

Then I could use that app token to create a user and get back a session token as per: https://github.com/tapglue/snaas/wiki/users-create-user

alibitek commented 7 years ago

I see that the console component provides a /api/apps API endpoint. What is the use case / goal for this component? Managing apps and accounts for clients of the SNAAS service? Some parts being written in Elm, the goal is also to provide a dashboard similar to TapGlue web dashboard?

LE: I think PR #25 gives some answers to what I've asked above.

xla commented 7 years ago

@mnemonicflow #25 is exactly the place to look at. In essence it will be the component to manage stack including, setting up apps and other domain entities. Beyond that it will serve as tool for community management and general management UI. Happy to hear about specific requirements/use-cases that it should cover in the PR.

Elqul commented 7 years ago

@mnemonicflow how did you manage to build the project ? Could you please explain ?

alibitek commented 7 years ago

@Elqul

There are multiple ways to build:

  1. If you have a Golang environment already, you can build it locally on your host system
  2. If you have Docker installed you can use the Dockerfile from the infrastructure/scripts/build-container dir to create a Docker image from the source code, from which you can create a container inside which you build and run snaas.
  3. If you have Docker installed you can pull the Docker image hosted on Docker Hub: https://hub.docker.com/r/tapglue/snaas/
  4. You can use the cmd/terraformer binary and Terraform if you want to build and deploy it to an AWS infrastructure
Abacaxi-Nelson commented 7 years ago

Hi

I'm trying to run

sudo docker run -it --rm --net=host 411a61b03b81 sh -c "/tapglue/gateway-http -aws.id='' -aws.secret='' -aws.region='eu-west-1 -source=sqs' -postgres.url='host=localhost user=tapglue password=tapglue dbname=tapglue sslmode=disable connect_timeout=5'"

It returns

{"caller":"gateway-http.go:115","component":"gateway-http","duration":397162,"host":"moby","lifecycle":"start","listen":":9000","revision":"f1af978","sub":"telemetry"}
{"caller":"gateway-http.go:193","component":"gateway-http","err":"dial tcp [::1]:5432: getsockopt: connection refused","host":"moby","lifecycle":"abort","revision":"f1af978"}

Which means that Postgres is not reachable..but does a container is supposed to access to my postgres throught 'localhost' ?

Thanks v

Abacaxi-Nelson commented 7 years ago

Grr, my postgres was buggy. it works now. sorry

Abacaxi-Nelson commented 7 years ago

With @mnemonicflow help, everything works now. I just add citext extension to tapglue database.

Abacaxi-Nelson commented 7 years ago

Thanks @mnemonicflow Have you try Console component ?

noblegeorge commented 7 years ago

@tugal : How did you manage to import the apps.JSON file (As @MCRrAMKkE4 mentioned) into the docker image that you ran. I managed to successfully pull the docker image and ran it. But at the API endpoint, it's giving a 404, what could possibly be the issue? (I'm new to docker.) Can someone please help me with successfully running it? @xla

xla commented 7 years ago

@noblegeorge What api endpoint did you try to call? If you have only a couple of apps to import you can try to run the Console compenent and create the apps in the UI.

noblegeorge commented 7 years ago

@xla Sorry. I'm new to Tapglue & Docker. These are the steps I followed so far,

1, Pulled the available docker image into my EC2 Ubuntu instance.

2, Created an AWS RDS Postgres instance.

3, Tried running the container as,

sudo docker run -it -p 80:8083 cee4ad3baded sh -c "/tapglue/gateway-http -aws.id='' -aws.secret='' -aws.region='eu-west-1 -source=sqs' -postgres.url='host=tapglue.****.ap-southeast-1.rds.amazonaws.com port=5432 user=***** password=***** dbname=***** sslmode=disable connect_timeout=50'"

Looks like it's running successfully.

{"caller":"gateway-http.go:117","component":"gateway-http","duration":3076601,"host":"aecb5a639365","lifecycle":"start","listen":":9000","revision":"4347b6b","sub":"telemetry"} {"caller":"gateway-http.go:944","component":"gateway-http","duration":83851005,"host":"aecb5a639365","lifecycle":"start","listen":":8083","revision":"4347b6b","sub":"api"}

4, But as I try to access it via the hostname: http://ec2-13-229-118-6.ap-southeast-1.compute.amazonaws.com it's returning me with a custom 404 error.

Maybe I'll sound noob. Please bear with me.

xla commented 7 years ago

@noblegeorge Root or / has no handler attached and the muxer therefore returns a 404. Your binary runs properly but a quick look at http://ec2-13-229-118-6.ap-southeast-1.compute.amazonaws.com/health-45016490610398192 which is the health endpoint shows that it's not healthy as redis is not configured or reachable.

You can refer to this section for the related redis setup: https://github.com/tapglue/snaas/blob/master/infrastructure/terraform/template/storage.tf#L147-L172