Search…
Develop one or more microservices
Velocity enables you to work on one or more components of your environment without having to worry about running everything locally on your computer. Instead, you develop what you need, while the rest of the environments' dependencies run on the cloud.
In this tutorial, we will start by developing the backend locally and then also run and debug the worker service.

Installation

If you already followed the Setup, feel free to skip directly into Creating your environment.
macOS
Linux
Windows
1
brew install techvelocity/tap/veloctl
Copied!
1
sudo snap install veloctl --classic
Copied!

Authenticate to Velocity

1
veloctl auth login
Copied!
1
Attempting to automatically open the login page in your default browser.
2
If the browser does not open or you wish to use a different device to authorize this request, open the following URL:
3
4
https://login.velocity.tech/activate?user_code=ABCD-EFGH
5
6
and verify the following code appears:
7
8
ABCD-EFGH
9
10
* Fetching underlying Kubernetes cluster configuration...
11
* Stored context 'velocity-VELOACME' locally (`/Users/Marty/.kube/config`).
12
Welcome Marty McFly ([email protected])!
Copied!

Creating your environment

In this tutorial, we will be developing two services - backend and worker.
Use veloctl env create to ask Velocity to create an isolated environment for you with these services inside:
1
veloctl env create --service backend --service worker
Copied!
1
Watching environment exciting-friday-64 status... /
2
3
Point in time: 2015-10-21T19:28:00Z
4
5
Service Status Version Public URI
6
database In Progress mysql:5.7
7
backend Pending ...6c6ed6e8d52388190 (pending)
8
worker Pending ...91698f97536e95126
9
10
Overall status: In Progress
Copied!
Once the environment is ready, the CLI will show its up-to-date status:
1
Watching environment exciting-friday-64 status...
2
3
Point in time: 2015-10-21T19:28:00Z
4
5
Service Status Version Public URI
6
database Ready mysql:5.7
7
backend Ready ...6c6ed6e8d52388190 https://backend-exciting-friday-64.awesomedev.com
8
worker Ready ...91698f97536e95126
9
10
Overall status: Ready
11
12
Your environment is ready! To develop on your services with command <CMD>, please run:
13
14
veloctl env develop --service backend -- <CMD>
15
veloctl env develop --service worker -- <CMD>
Copied!
Where is the website?
Velocity automatically resolves the dependencies of your services, so you don't have to worry about the other components required for your app to work.
In the current tutorial, neither the backend nor the worker require the website, so it wasn't created.
At this point, you can work directly against the backend created in your environment by using its new URL - https://backend-exciting-friday-64.awesomedev.com

Running the backend

The environment was created in order to develop a new feature, and I want to run the backend service locally. Using veloctl env develop , I can wrap my backend's run command to start developing. Below are few examples to give you the gist of how to wrap your run command:
Go
Node.js (NPM)
Ruby (Rails)
Docker
Python (Flask)
1
veloctl env develop --service backend -- go run .
Copied!
1
veloctl env develop --service backend -- npm start
Copied!
1
veloctl env develop --service backend -- rails server
Copied!
1
veloctl env develop --service backend -- docker run -v `pwd`:/app -t my-image
Copied!
1
FLASK_APP=app.py veloctl env develop --service backend -- flask run
Copied!
The double dash (--) is important to separate any arguments you pass to your command from the commands passed to veloctl. But don't worry, we'll remind you if you forget it!
1
veloctl env develop --service backend -v -- go run .
Copied!
1
[VELOCTL] Developing service 'backend' in environment 'exciting-friday-64'...
2
[VELOCTL] Forwarding: localhost:50271 => database:3306
3
[VELOCTL] Executing command: go run .
4
[VELOCTL] Service 'website' is also accessible via https://backend-exciting-friday-64.awesomedev.com
5
6
Connecting to the database (`DATABASE_URL` env): mysql://RA6su4rv:[email protected]:50271/app
7
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.
8
9
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
10
- using env: export GIN_MODE=release
11
- using code: gin.SetMode(gin.ReleaseMode)
12
13
[GIN-debug] GET /ping --> main.main.func1 (3 handlers)
14
[GIN-debug] Environment variable PORT="8080"
15
[GIN-debug] Listening and serving HTTP on :8080
Copied!
The backend is now available locally (on port 8080) and also via the Public URI mentioned before - https://backend-exciting-friday-64.awesomedev.com . That URI is accessible to any of your coworkers and it will proxy the incoming traffic to your local process!
What is this "Forwarding" line?
To let your locally run process access internal resources (like the database), we bind a random port on your computer and forward it to the resource. In this case, the MySQL database is accessible at 127.0.0.1:50271 and Velocity automatically stored the full connection string in the DATABASE_URL that the backend is expecting.

Running the worker

See logs from the environment

When we created the environment, the worker service was created in the cloud. We can see the output from it by using the veloctl env logs command:
1
veloctl env logs --service worker
Copied!
1
worker-cfdb86554-v8dfl worker 2015-10-21T19:28:02Z info: Queue backend: MySQL (mysql://RA6su4rv:[email protected]:3306/app)
2
worker-cfdb86554-v8dfl worker 2015-10-21T19:28:03Z info: 0 jobs in queue
Copied!

Run the worker locally

Now that we have seen the worker is running in the environment, we might want to develop it locally too. Just as we started the previous service, we will use veloctl env develop to start the worker:
1
veloctl env develop --service worker -- yarn start
Copied!
1
[VELOCTL] Developing service 'worker' in environment 'exciting-friday-64'...
2
[VELOCTL] Forwarding: localhost:50271 => database:3306
3
[VELOCTL] Executing command: yarn start
4
5
yarn run v1.22.10
6
$ node .
7
2015-10-21T19:28:22Z info: Queue backend: MySQL (mysql://RA6su4rv:[email protected]:50271/app)
8
2015-10-21T19:28:23Z info: 0 jobs in queue
Copied!

Cleaning up

When you are done developing and ready to clean up the resources, use:
1
veloctl env destroy
Copied!
1
? Are you sure you want to destroy the 'exciting-friday-64' environment? Yes
2
Destroying environment exciting-friday-64... \
3
4
Environment successfully destroyed
Copied!

What's next?

Last modified 14d ago