Skip to content

Commit

Permalink
Merge pull request wso2#38 from sinthuja/master
Browse files Browse the repository at this point in the history
Refactor samples repository to separate the cell and source
  • Loading branch information
azinneera authored Jul 1, 2019
2 parents ff10b86 + 22d1445 commit 046cd6b
Show file tree
Hide file tree
Showing 83 changed files with 517 additions and 353 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ DOCKER_IMAGE_TAG ?= $(GIT_REVISION)
CELLERY_ORG ?= wso2cellery
CELLERY_VERSION ?= latest

SAMPLES := pet-store hello-world hello-world-api
SAMPLES := $(addprefix cells/, pet-store hello-world hello-world-api) $(addprefix src/, pet-store hello-world hello-world-api)

CLEAN_TARGETS := $(addprefix clean., $(SAMPLES))
CHECK_STYLE_TARGETS := $(addprefix check-style., $(SAMPLES))
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ Cellery Samples
[![GitHub last commit](https://img.shields.io/github/last-commit/wso2-cellery/samples.svg)](https://github.com/wso2-cellery/samples/commits/master)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

**Note**: If you just wish to get started with trying out Cellery, you can start your journey at [wso2-cellery/sdk](https://github.com/wso2-cellery/sdk) repository.
Cellery Samples contains various samples that can be deployed in a Cellery Runtime.

Cellery Samples contains various samples that can be deployed in a Cellery Runtime. If you have not already set-up a Cellery CLI and Runtime, please visit the [Getting Started](https://github.com/wso2-cellery/sdk#getting-started) to set-up your Cellery CLI and Runtime.
- To quick start on cellery, please go through the [Quick Start Guide](https://github.com/wso2-cellery/sdk/tree/master#quickstart-guide)
- For installation options, please visit the [Installation Guide](https://github.com/wso2-cellery/sdk/blob/master/docs/installation-options.md)
- For more information about Cellery, please visit [https://wso2-cellery.github.io/](https://wso2-cellery.github.io/)

Once you have set-up the Cellery CLI and Runtime you can proceed with deploying the samples provided here. You can find the following samples in this repository.
Once you have completed cellery setup, you can proceed with deploying the samples provided below. You can find the following samples in this repository.

* [Hello world](hello-world)
* [Hello world Api](hello-world-api)
* [Pet store](pet-store)
* [Hello world](cells/hello-world)
* [Hello world Api](cells/hello-world-api)
* [Pet store](cells/pet-store)

Please follow the relevant documentation provided in the samples to learn more about the samples and deploy them.
54 changes: 54 additions & 0 deletions cells/hello-world-api/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright (c) 2019 WSO2 Inc. (http:www.wso2.org) All Rights Reserved.
#
# WSO2 Inc. licenses this file to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file except
# in compliance with the License.
# You may obtain a copy of the License at
#
# http:www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

PROJECT_ROOT := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
GIT_REVISION := $(shell git rev-parse --verify HEAD)
CELLERY_ORG ?= wso2cellery
CELLERY_VERSION ?= latest

SAMPLE := hello-world-api
CELL := hello-world-api
COMPONENT := hello-service

all: clean build docker

.PHONY: clean
clean:
@:

.PHONY: build
build:
@:

.PHONY: check-style
check-style:
@

.PHONY: docker
docker:
@:

.PHONY: docker-push
docker-push:
@:

.PHONY: cellery-build
cellery-build:
cellery build $(CELL).bal $(CELLERY_ORG)/$(CELL)-cell:$(CELLERY_VERSION)

.PHONY: cellery-push
cellery-push:
cellery push $(if $(CELLERY_REGISTRY),$(CELLERY_REGISTRY)/)$(CELLERY_ORG)/$(CELL)-cell:$(CELLERY_VERSION) -u $(CELLERY_USER) -p $(CELLERY_USER_PASS)
74 changes: 19 additions & 55 deletions hello-world-api/README.md → cells/hello-world-api/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Hello world API cell
===============

Hello World API sample is a simple rest API that returns the text 'Hello World!' as a response to a GET request.
Hello-world API sample is a simple rest API that returns the text 'Hello World!' as a response to a GET request.

![Hello World API Cell Architecture Diagram](../docs/images/hello-world-api/hello-world-api-architecture.jpg)
![Hello World API Cell Architecture Diagram](../../docs/images/hello-world-api/hello-world-api-architecture.jpg)

##### Note: To run this sample, a cellery deployment which includes API Manager component is required (complete cellery deployment or basic celley deployment with APIM is required).

Expand All @@ -14,13 +14,12 @@ Hello World API sample is a simple rest API that returns the text 'Hello World!'
1. Clone the [wso2-cellery/samples](https://github.com/wso2-cellery/samples) repository
2. Navigate to the hello-world-api Sample.
```
cd <SAMPLES_ROOT>/hello-world-api
cd <SAMPLES_ROOT>/cells/hello-world-api
```
### 2. Build and run hello world api cell
In this section let's focus on build, run and push a [hello world api cell](hello-world-api.bal).

The cell `helloCell` consists of one component defined as `helloComponent` and it has one http api ingress which is
exposed as `global` API.
The cell `helloCell` consists of one component defined as `hello` component and it has one http API ingress that is exposed globally.

```ballerina
import ballerina/io;
Expand All @@ -31,7 +30,7 @@ public function build(cellery:ImageName iName) returns error? {
cellery:Component helloComponent = {
name: "hello-api",
source: {
image: "docker.io/wso2cellery/samples-hello-world-api-hello-service:0.2.0"
image: "docker.io/wso2cellery/samples-hello-world-api-hello-service:latest"
},
ingresses: {
helloApi: <cellery:HttpApiIngress>{ port: 9090,
Expand Down Expand Up @@ -64,37 +63,37 @@ public function build(cellery:ImageName iName) returns error? {

1. Build the cellery image for hello world project by executing the cellery build command as shown below. Note `DOCKER_HUB_ORG` is your organization name in docker hub.
```
$ cellery build hello-world-api.bal <DOCKER_HUB_ORG>/hello-world-api-cell:1.0.0
$ cellery build hello-world-api.bal <DOCKER_HUB_ORG>/hello-world-api-cell:latest
✔ Building image <DOCKER_HUB_ORG>/hello-world-api-cell:1.0.0
✔ Building image <DOCKER_HUB_ORG>/hello-world-api-cell:latest
✔ Saving new Image to the Local Repository
✔ Successfully built cell image: <DOCKER_HUB_ORG>/hello-world-api-cell:1.0.0
✔ Successfully built cell image: <DOCKER_HUB_ORG>/hello-world-api-cell:latest
What's next?
--------------------------------------------------------
Execute the following command to run the image:
$ cellery run <DOCKER_HUB_ORG>/helloworld:1.0.0
$ cellery run <DOCKER_HUB_ORG>/helloworld:latest
--------------------------------------------------------
```
2. Run the cell image by executing `cellery run` command as shown below.
```
$ cellery run <DOCKER_HUB_ORG>/hello-world-api-cell:1.0.0 -n hello-world-api-cell
✔ Extracting Cell Image <DOCKER_HUB_ORG/hello-world-api-cell:1.0.0
$ cellery run <DOCKER_HUB_ORG>/hello-world-api-cell:latest -n hello-world-api-cell
✔ Extracting Cell Image <DOCKER_HUB_ORG/hello-world-api-cell:latest
Main Instance: my-hello-world
✔ Reading Cell Image <DOCKER_HUB_ORG/hello-world-api-cell:1.0.0
✔ Reading Cell Image <DOCKER_HUB_ORG/hello-world-api-cell:latest
✔ Validating environment variables
✔ Validating dependencies
Instances to be Used:
INSTANCE NAME CELL IMAGE USED INSTANCE SHARED
---------------------- --------------------------------------------- --------------- --------
hello-world-api-cell <DOCKER_HUB_ORG>/hello-world-api-cell:1.0.0 To be Created -
hello-world-api-cell <DOCKER_HUB_ORG>/hello-world-api-cell:latest To be Created -
Dependency Tree to be Used:
Expand All @@ -105,7 +104,7 @@ public function build(cellery:ImageName iName) returns error? {
✔ Starting main instance my-hello-world
✔ Successfully deployed cell image: <DOCKER_HUB_ORG>/hello-world-api-cell:1.0.0
✔ Successfully deployed cell image: <DOCKER_HUB_ORG>/hello-world-api-cell:latest
What's next?
--------------------------------------------------------
Expand All @@ -118,14 +117,14 @@ public function build(cellery:ImageName iName) returns error? {
```
$ cellery list instances
INSTANCE CELL IMAGE STATUS GATEWAY COMPONENTS AGE
------------------------------------------ -------------------------------------------- -------- -------------------------------------------------------------- ------------ ----------------------
hello-world-api-cell-1-0-0-676b2131 sinthuja/hello-world-api-cell:1.0.0 Ready sinthuja-hello-world-api-cell-1-0-0-676b2131--gateway-service 1 10 minutes 1 seconds
------------------------------------------ -------------------------------------------- -------- ----------------------------------------------------------------- ------------ ----------------------
hello-world-api-cell-1-0-0-676b2131 sinthuja/hello-world-api-cell:latest Ready sinthuja-hello-world-api-cell-latest-676b2131--gateway-service 1 10 minutes 1 seconds
```
4. Execute `cellery view` to see the components of your cell. This will open a HTML page in a browser and you can visualize the components and dependent cells of the cell image.
```
$ cellery view <DOCKER_HUB_ORG>/hello-world-api-cell:1.0.0
$ cellery view <DOCKER_HUB_ORG>/hello-world-api-cell:latest
```
![hello world api cell view](../docs/images/hello-world-api/hello-world-cell-api-docs-view.png)
![hello world api cell view](../../docs/images/hello-world-api/hello-world-cell-api-docs-view.png)
### 3. Obtain access token and invoke API
Expand All @@ -145,42 +144,7 @@ And, by default all the APIs are secured, therefore we need to obtain a token to
Congratulations! You have successfully tried out the hello world api sample!
## Building the Components from Source
You do not need to build the components if you just wish to deploy the cells. This should only be done if you wish to change the Hello World API sample and play around with it.
### Prerequisites
* Docker
* GNU Make 4.1+
### Building the Components
If you wish to change the Hello World API Sample and play around with Cellery, you can follow this section to rebuild the Components.
1. Clone the [wso2-cellery/samples](https://github.com/wso2-cellery/samples) repository to your `GO_PATH/src/github.com/wso2cellery` directory.
2. Set the following environment variables for customizing the build.
| Environment Variable | |
|-----------------------|-----------------------------------------------------------------------|
| DOCKER_REPO | The name of the repository of the Docker images (Your Docker Hub ID) |
| DOCKER_IMAGE_TAG | The tag of the Docker images |
3. Run the make target for building docker images.
```
make docker
```
This would build the components from source and build the docker images using the environment variables you have provided.
4. Login to Docker Hub
```
docker login
```
5. Run the target for pushing the docker images.
```
make docker-push
```
6. Update the `<SAMPLES_ROOT>/hello-world-api/hello-world-api.bal` file and set the newly created image names for the component source.
7. [Build and run](#2.-build-and-run-hello-world-web-cell) the Cells.
Please feel free to checkout this repository and play around with the sample as explained [here](../../src/hello-world-api)
## Did you try?
1. [Hello world](../hello-world)
Expand Down
File renamed without changes.
13 changes: 3 additions & 10 deletions hello-world/Makefile → cells/hello-world/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@

PROJECT_ROOT := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
GIT_REVISION := $(shell git rev-parse --verify HEAD)
DOCKER_REPO ?= wso2cellery
DOCKER_IMAGE_TAG ?= $(GIT_REVISION)
CELLERY_ORG ?= wso2cellery
CELLERY_VERSION ?= latest

SAMPLE := hello-world
CELL := hello-world
COMPONENT := webapp

all: clean build docker

Expand All @@ -37,19 +34,15 @@ build:

.PHONY: check-style
check-style:
cd components/$(COMPONENT); \
npm ci; \
npm run lint
@:

.PHONY: docker
docker:
cd components/$(COMPONENT); \
docker build -t ${DOCKER_REPO}/samples-$(SAMPLE)-$(COMPONENT):${DOCKER_IMAGE_TAG} .; \
@:

.PHONY: docker-push
docker-push:
cd components/$(COMPONENT); \
docker push ${DOCKER_REPO}/samples-$(SAMPLE)-$(COMPONENT):${DOCKER_IMAGE_TAG}
@:

.PHONY: cellery-build
cellery-build:
Expand Down
Loading

0 comments on commit 046cd6b

Please sign in to comment.