Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to scaffold, run, debug, test, and deploy a LoopBack 4 application using Appsody CLI #4215

Merged
merged 1 commit into from
Dec 3, 2019

Conversation

emonddr
Copy link
Contributor

@emonddr emonddr commented Nov 26, 2019

How to use the nodejs-loopback stack and the Appsody CLI
to scaffold, run, debug, and test a LoopBack 4 application locally,
and how to deploy this application to the IBM Cloud.

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

@emonddr
Copy link
Contributor Author

emonddr commented Nov 26, 2019

This is where I'm thinking we should place this document:

image

Copy link
Member

@dhmlau dhmlau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together!
Besides the comment, I have one more question: would we be showing up how to connect with other databases in a LB4 application as well? I thought you were looking into it.

The template application is only a starting point. Let's build a proper, basic
LoopBack 4 application.

Let's build the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we need this section because it's the same as the todo tutorial.
I can see the advantage of having all the instructions in one place without clicking other docs. However, my concern of having duplicating the content here is if there's any change in the prompts, we need to update it in 2 places. Personally, I'd like to see this tutorial to be more focus on the specific things we need to do when deploying Apposody.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo also talks about the geoservice. We don't need that. Also. The todo doc is out of date in terms of prompts. We can replace this Building your application section with `follow the Todo tutorial starting with 'Add model' and do not do 'Adding geo-service'.

I was trying to avoid any relational database stuff because I wanted to avoid talking about setting up a database on IBM Cloud.

Raymond's changes to the structure/documentation of the shopping cart application was geared to show how to deploy an app docker container, a mongo container, and a redis container to a kubernetes cluster. So I figured this was sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With Appsody, using the nodejs-loopback stack ( a template of a loopback app), it is very simple to run/debug/test/stop and app locally. And very simple to deploy to kubernetes. Before deploying to kubernetes, we would need to change the db url in the datasource json.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhmlau , we can start with this, and then provide a follow-up in the future for dealing with a relational database

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. as the first step, I'm fine with just using the in-memory database.

@emonddr
Copy link
Contributor Author

emonddr commented Nov 26, 2019

As I was preparing this document, I came across these issues : #4216 .

I also came across other issues that @raymondfeng fixed in this PR : appsody/stacks#488 .
Particularly : https://github.com/appsody/stacks/blob/master/incubator/nodejs-loopback/image/project/src/index.ts#L21 . We needed this line because the LB4 appsody application could not find the project/data/db.json file for the in memory database.

@dhmlau dhmlau added this to the Dec 2019 milestone Nov 27, 2019
@dhmlau dhmlau added CloudNative Cloud native enablement Docs labels Nov 29, 2019
@dhmlau
Copy link
Member

dhmlau commented Nov 29, 2019

@mhdawson, this might be a good candidate for QuickLab for the upcoming conferences.

Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 👏

docs/site/Appsody-LoopBack.md Outdated Show resolved Hide resolved
@mhdawson
Copy link
Contributor

@joesepi, what do you think in terms of quicklab. Probably too late for NodeJSInteractive since it's only a couple week away (correct me if I'm wrong on this front), but could be a good option for the standard set we use for next year.

@emonddr
Copy link
Contributor Author

emonddr commented Dec 2, 2019

A fix was provided for #4216 by @raymondfeng . Thanks, Raymond :)

@@ -0,0 +1,990 @@
---
lang: en
title: 'Deploying to Cloud with Appsody'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The title should be Developing and Deploying LoopBack Applications with Appsody.

permalink: /doc/en/lb4/Appsody-LoopBack.html
---

## LoopBack 4 & Appsody
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The header can be ## Introduction or ## Overview.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choosing Overview.


[Appsody](https://appsody.dev/docs#welcome-to-appsody) is designed to help
develop containerized applications for the cloud.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention https://kabanero.io/?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention https://kabanero.io/?

@raymondfeng , how do we want to mention it? I downloaded and used the appsody CLI with homebrew. I didn't use kabanero.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial thought was to make our users aware that Kabanero is a broader offering that uses Appsody for cloud native app dev/dep.


We're going to show you how to scaffold, run, stop, debug, and test a LoopBack 4
application locally. Then we're going to show you how to build and deploy this
application to the [IBM Cloud](https://www.ibm.com/cloud).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing We're going to show you twice. Can we use a different phrase?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're going to show you how to scaffold, run, stop, debug, and test a LoopBack 4 application locally. Then, you'll learn how to build and deploy this application to the [IBM Cloud](https://www.ibm.com/cloud).

7. Now that all the dependencies have been installed, it is a perfect time to
open your favourite IDE editor on this project.

In my case, I using VS Code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using -> use.

npm install
```

7. Now that all the dependencies have been installed, it is a perfect time to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is a perfect time to -> it's ready to or let's?

The template application is only a starting point. Let's build a proper, basic
LoopBack 4 application.

Let's build the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing let's build twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"
The template application is only a starting point.

Let's build a proper, basic LoopBack 4 application.

We'll use the todo list application from the Todo Tutorial as an example.
"

![lb4appsody_template_files_2.png](./imgs/lb4appsody_template_files_2.png)

10. This basic application only defines one API endpoint `'/ping'` in the file
**src/controllers/ping.controller.ts**
Copy link
Contributor

@raymondfeng raymondfeng Dec 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can mention the initial application is very much similar as the one generated by lb4 app command but it's going to be a loaded by a facade that sets up health/metrics for cloud native observability.

We will run, test, debug, and stop this application **locally** in the next
section.

## Running/Testing/Debugging/Stopping a LoopBack 4 Application Locally using Appsody
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should mention the watch capability - as we make changes to the project locally, the application can be redeployed to a docker container as we go.

Copy link
Contributor Author

@emonddr emonddr Dec 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should mention the watch capability - as we make changes to the project locally, the application can be redeployed to a docker container as we go.

@raymondfeng , I mention this in the sentence: By default, 'File watching' is **enabled** when you run the command 'appsody run'. This means you can change a file in your project, and then Appsody builds/runs a new Docker container for you automatically.

@@ -187,6 +187,11 @@ children:
url: deploying-with-pm2-and-nginx.html
output: 'web, pdf'

- title: 'Deploying to Cloud with Appsody'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating title as well

@raymondfeng
Copy link
Contributor

Let's somehow use or add a new diagram for https://appsody.dev/static/2f908188a17e5e471158534326fc5665/0a44b/appsody_flow.png?

@emonddr
Copy link
Contributor Author

emonddr commented Dec 2, 2019

It is best to view the commit

image

with this option in github:

image

It will show that one-liners were added here and there by the editor.

Viewing it the normal way makes it look like big sections went missing (not sure why)

@raymondfeng
Copy link
Contributor

@emonddr Please fix the formatting - see https://travis-ci.com/strongloop/loopback-next/jobs/262349584

@@ -10,799 +10,766 @@
title: LoopBack 4
url: index.html
children:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the formatting changes and only leave your addition using the current format.

@emonddr
Copy link
Contributor Author

emonddr commented Dec 3, 2019

@emonddr Please fix the formatting

Ok I will revert. I spoke to @jannyHou about this yesterday. How my editor automatically wants to reformat the YML. Not sure why that is. But I will revert.

@emonddr emonddr force-pushed the dremond_appsody_lb4_doc branch from 28ef135 to 957c0d2 Compare December 3, 2019 14:29
… cli

Use the 'nodejs-loopback' stack and the  Appsody CLI
to scaffold, run, debug, and test a LoopBack 4 application locally,
and how to deploy this application to Kubernetes on the IBM Cloud.
@emonddr emonddr force-pushed the dremond_appsody_lb4_doc branch from 957c0d2 to 7c84404 Compare December 3, 2019 14:30
### Stopping a LoopBack 4 Application Locally using Appsody

If your application is currently running under Appsody control, you can stop it
with `Ctrl+C`, or by running the command `'appsody stop'` from another terminal.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if I have multiple apps started by appsody run, would this command stop all of them? Is it possible to provide a container name as argument to specify which one to stop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if I have multiple apps started by appsody run, would this command stop all of them? Is it possible to provide a container name as argument to specify which one to stop?

Good question. But out of scope for this article. More for Appsody FAQ.

But from what I understand and observe, the .appsody-config.yaml file in your project directory (e.g. appsodyLB4Todo) has a project-name value:

project-name: appsodylb4todo
stack: appsody/nodejs-loopback:0.1

When appsody run is executed (from inside directory appsodylb4todo), it starts a docker container named

appsodylb4todo-dev

To do: appsody stop, you must also be inside the directory appsodylb4todo .

Then it stops and removes this container.

So, if you have multiple apps started from separate project directories, and they have unique project directory names, you should be fine.

Copy link
Contributor

@jannyHou jannyHou Dec 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to do: appsody stop, you must also be inside the directory appsodylb4todo .

Magic! Now I understand how the run and stop cmd finds the app. thanks for explanation!

@emonddr emonddr merged commit a869184 into master Dec 3, 2019
@emonddr emonddr deleted the dremond_appsody_lb4_doc branch December 3, 2019 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CloudNative Cloud native enablement Docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants