Skip to content

Commit

Permalink
Merge pull request #254 from garden-io/docs-simple-project
Browse files Browse the repository at this point in the history
Docs simple project
  • Loading branch information
eysi09 authored Sep 10, 2018
2 parents 019f984 + cc4de6d commit 734d252
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/examples/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Examples

The source code for the examples in this section can be found in our Github repository under the
[examples directory](https://github.com/garden-io/garden/examples/).
[examples directory](https://github.com/garden-io/garden/tree/master/examples).

* [Simple Project](./simple-project.md)
16 changes: 8 additions & 8 deletions docs/examples/simple-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This tutorial assumes that you have already have a running [installation of Gard

## Clone the example repo

The code for this tutorial can be found on Github in our [examples repo](https://github.com/garden-io/garden/examples). We'll use the [simple-project-start](https://github.com/garden-io/garden/examples/simple-project-start) example and work our way from there. The complete version is under [simple-project](https://github.com/garden-io/garden/examples/simple-project).
The code for this tutorial can be found in our Github repository under the [examples directory](https://github.com/garden-io/garden/tree/master/examples). We'll use the [simple-project-start](https://github.com/garden-io/garden/tree/master/examples/simple-project-start/) example and work our way from there. The complete version is under [simple-project](https://github.com/garden-io/garden/tree/master/examples/simple-project).

First, let's clone the examples repo, change into the directory, and take a look inside:
```sh
Expand Down Expand Up @@ -113,7 +113,7 @@ module:
- name: http
containerPort: 8080
endpoints:
- path: /
- path: /hello-node
port: http
```
The [services](../guides/configuration.md#Services) directive is specific to container modules, and defines the services exposed by the module. In this case, our containerized Node.js server. The sub-directives tell Garden how to start the service and which endpoints to expose.
Expand All @@ -132,11 +132,11 @@ Garden can now deploy our service to a local Kubernetes cluster:
$ garden deploy
```

To verify that everything is working, we can call the service at the `/hello` endpoint defined in `/services/node-service/app.js`:
To verify that everything is working, we can call the service at the `/hello-node` endpoint defined in `/services/node-service/app.js`:

```sh
$ garden call node-service/hello
✔ Sending HTTP GET request to http://simple-project.local.app.garden/hello
$ garden call node-service/hello-node
✔ Sending HTTP GET request to http://simple-project.local.app.garden/hello-node
200 OK
Expand All @@ -161,7 +161,7 @@ module:
- name: http
containerPort: 80
endpoints:
- path: /
- path: /hello-go
port: http
```

Expand Down Expand Up @@ -193,7 +193,7 @@ Calling our `go-service` from our `node-service` is straightforward from within
const request = require('request-promise')
// Unless configured otherwise, the hostname is simply the service name
const goServiceEndpoint = `http://go-service/`;
const goServiceEndpoint = `http://go-service/hello-go`;

app.get('/call-go-service', (req, res) => {
// Query the go-service and return the response
Expand Down Expand Up @@ -223,7 +223,7 @@ $ garden call node-service/call-go-service
200 OK

{
"message": "Hello from Go!"
"message": "Hello from Go!"
}
```

Expand Down
2 changes: 1 addition & 1 deletion examples/local-tls/services/go-service/webserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello %s from Go!", r.URL.Path[1:])
fmt.Fprint(w, "Hello from Go!")
}

func main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
)

func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello %s from Go!", r.URL.Path[1:])
fmt.Fprint(w, "Hello from Go!")
}


func main() {
http.HandleFunc("/", handler)
http.HandleFunc("/hello-go", handler)
fmt.Println("Server running...")

http.ListenAndServe(":80", nil)
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-project-start/services/node-service/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const express = require('express');
const app = express();

app.get('/hello', (req, res) => res.send('Hello from Node service!'));
app.get('/hello-node', (req, res) => res.send('Hello from Node service!'));

module.exports = { app }
4 changes: 2 additions & 2 deletions examples/simple-project/services/go-service/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ module:
- name: http
containerPort: 80
endpoints:
- path: /
port: http
- path: /hello-go
port: http
4 changes: 2 additions & 2 deletions examples/simple-project/services/go-service/webserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
)

func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello %s from Go!", r.URL.Path[1:])
fmt.Fprint(w, "Hello from Go!")
}

func main() {
http.HandleFunc("/", handler)
http.HandleFunc("/hello-go", handler)
fmt.Println("Server running...")

http.ListenAndServe(":80", nil)
Expand Down
4 changes: 2 additions & 2 deletions examples/simple-project/services/node-service/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const request = require('request-promise')
const app = express();

// Unless configured otherwise, the hostname is simply the service name
const goServiceEndpoint = `http://go-service/`;
const goServiceEndpoint = `http://go-service/hello-go`;

app.get('/hello', (req, res) => res.send('Hello from Node service!'));
app.get('/hello-node', (req, res) => res.send('Hello from Node service!'));

app.get('/call-go-service', (req, res) => {
// Query the go-service and return the response
Expand Down
4 changes: 3 additions & 1 deletion examples/simple-project/services/node-service/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ module:
- name: http
containerPort: 8080
endpoints:
- path: /
- path: /hello-node
port: http
- path: /call-go-service
port: http
dependencies:
- go-service
Expand Down
2 changes: 1 addition & 1 deletion garden-cli/src/commands/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class CallCommand extends Command<typeof callArgs> {
const method = "get"

const entry = ctx.log.info({
msg: chalk.cyan(`Sending HTTP GET request to `) + url + "\n",
msg: chalk.cyan(`Sending ${matchedEndpoint.protocol.toUpperCase()} GET request to `) + url + "\n",
entryStyle: EntryStyle.activity,
})

Expand Down

0 comments on commit 734d252

Please sign in to comment.