Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
7R41N33 committed Mar 22, 2022
2 parents da7c138 + fd02dda commit ffa09c1
Show file tree
Hide file tree
Showing 65 changed files with 2,386 additions and 262 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Style/AsciiComments:
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#english-comments'
Enabled: false

Style/OptionalBooleanParameter:
Enabled: false

Naming/AsciiIdentifiers:
Description: 'Use only ascii symbols in identifiers.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#english-identifiers'
Expand Down
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
uffizzi-cli (0.1.4.3)
uffizzi-cli (0.2.0)
thor

GEM
Expand Down Expand Up @@ -78,6 +78,9 @@ GEM
rubocop (~> 1.0)
ruby-progressbar (1.11.0)
thor (1.2.1)
tty-cursor (0.7.1)
tty-spinner (0.9.3)
tty-cursor (~> 0.7)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode (0.4.4.4)
Expand Down Expand Up @@ -106,6 +109,7 @@ DEPENDENCIES
rubocop
rubocop-minitest
rubocop-rake
tty-spinner
uffizzi-cli!
webmock

Expand Down
93 changes: 67 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# Uffizzi CLI
# Uffizzi CLI

A command-line interace (CLI) for [Uffizzi App](https://github.com/UffizziCloud/uffizzi_app)
A command-line interace (CLI) for [Uffizzi App](https://github.com/UffizziCloud/uffizzi_app)

## Uffizzi Overview

Uffizzi is the Full-stack Previews Engine that makes it easy for your team to preview code changes before merging—whether frontend, backend or microserivce. Define your full-stack apps with a familiar syntax based on Docker Compose, and Uffizzi will create on-demand test environments when you open pull requests or build new images. Preview URLs are updated when there’s a new commit, so your team can catch issues early, iterate quickly, and accelerate your release cycles.
Uffizzi is the Full-stack Previews Engine that makes it easy for your team to preview code changes before merging—whether frontend, backend or microserivce. Define your full-stack apps with a familiar syntax based on Docker Compose, and Uffizzi will create on-demand test environments when you open pull requests or build new images. Preview URLs are updated when there’s a new commit, so your team can catch issues early, iterate quickly, and accelerate your release cycles.

## Getting started with Uffizzi
## Getting started with Uffizzi

The fastest and easiest way to get started with Uffizzi is via the fully hosted version available at https://uffizzi.com, which includes free plans for small teams and qualifying open-source projects.
The fastest and easiest way to get started with Uffizzi is via the fully hosted version available at https://uffizzi.com, which includes free plans for small teams and qualifying open-source projects.

Alternatively, you can self-host Uffizzi via the open-source repositories available here on GitHub. The remainder of this README is intended for users interested in self-hosting Uffizzi or for those who are just curious about how Uffizzi works.

## Uffizzi Architecture
## Uffizzi Architecture

Uffizzi consists of the following components:
Uffizzi consists of the following components:

* [Uffizzi App](https://github.com/UffizziCloud/uffizzi_app) - The primary REST API for creating and managing Previews
* [Uffizzi Controller](https://github.com/UffizziCloud/uffizzi_controller) - A smart proxy service that handles requests from Uffizzi App to the Kubernetes API
* Uffizzi CLI (this repository) - A command-line interface for Uffizzi App
* [Uffizzi Dashboard](https://app.uffizzi.com) - A graphical user interface for Uffizzi App, available as a paid service at https://uffizzi.com
- [Uffizzi App](https://github.com/UffizziCloud/uffizzi_app) - The primary REST API for creating and managing Previews
- [Uffizzi Controller](https://github.com/UffizziCloud/uffizzi_controller) - A smart proxy service that handles requests from Uffizzi App to the Kubernetes API
- Uffizzi CLI (this repository) - A command-line interface for Uffizzi App
- [Uffizzi Dashboard](https://app.uffizzi.com) - A graphical user interface for Uffizzi App, available as a paid service at https://uffizzi.com

To host Uffizzi yourself, you will also need the following external dependencies:
To host Uffizzi yourself, you will also need the following external dependencies:

* Kubernetes (k8s) cluster
* Postgres database
* Redis cache
- Kubernetes (k8s) cluster
- Postgres database
- Redis cache

## Installation

Expand Down Expand Up @@ -54,40 +54,81 @@ Run rubocop:

## Commands

### login ###
### login

```
$ uffizzi login -u [email protected] -h localhost:8080
$ uffizzi login -u [email protected] --hostname localhost:8080
```
Logging you into the app which you set in the hostname option.

Logging you into the app which you set in the hostname option.

### login options ###
### login options

Option | Aliase | Description
------- | ------- | -----------
`--user` | `-u` | Your email for logging in
`--hostname`| `-h` | Adress of your app
| Option | Aliase | Description |
| ------------ | ------ | ------------------------- |
| `--user` | `-u` | Your email for logging in |
| `--hostname` | | Adress of your app |

If hostname uses basic authentication you can specify options for it by setting `basic_auth_user` and `basic_auth_password` via `config set` command.

### projects ###
### project

```
$ uffizzi projects
$ uffizzi project
```

Use this command to configure your projects. This command has 2 subcommands `list` and `compose`.

```
$ uffizzi project list
```

Shows all your projects' slugs

If you have only one project it will be added to your config file automatically, if there's more than one project you need to set up your project manually with the command `uffizzi config set YOUR_PROJECT_SLUG`

### config ###
### compose

```
$ uffizzi project compose
```

That's the subcommand for project command. Use it to configure your compose file. This command has 3 subcommands `set`, `describe` and `unset`.

```
$ uffizzi project compose set -f path_to_your_compose_file.yml
```

Creates a new or updates existed compose file in uffizzi app for project specified in config file

```
$ uffizzi project compose describe
```

Shows the content of compose file related to project specified in config file if it's valid or validation errors if it's not

```
$ uffizzi project compose unset
```

Removes compose file related to project specified in config file

You need to set project before use any of these commands via `uffizzi config set project YOUR_PROJECT_SLUG` command

### compose options

| Option | Aliase | Description |
| -------- | ------ | ------------------------- |
| `--file` | `-f` | Path to your compose file |

### config

Use this command to configure your cli app. This command has 4 subcommands `list`, `get`, `set`, and `delete`.

```
$ uffizzi config list
```

Shows all options and their values from the config file.

```
Expand Down
17 changes: 17 additions & 0 deletions config/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require 'ostruct'

module Uffizzi
def self.configuration
@configuration ||= OpenStruct.new
end

def self.configure
yield(configuration)
end

configure do |config|
config.hostname = 'http://web:7000'
end
end
9 changes: 5 additions & 4 deletions lib/uffizzi.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# frozen_string_literal: true

require 'uffizzi/shell'
require_relative 'uffizzi/version'
require_relative 'uffizzi/clients/api/api_client'
require_relative 'uffizzi/clients/api/api_routes'
require_relative 'uffizzi/config_file'
require 'uffizzi/version'
require 'uffizzi/clients/api/api_client'
require 'uffizzi/clients/api/api_routes'
require 'uffizzi/config_file'

module Uffizzi
class Error < StandardError; end

class << self
def ui
@ui ||= Uffizzi::UI::Shell.new
Expand Down
5 changes: 5 additions & 0 deletions lib/uffizzi/auth_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ def signed_in?
ConfigFile.option_exists?(:cookie) &&
ConfigFile.option_exists?(:hostname)
end

def project_set?
ConfigFile.exists? &&
ConfigFile.option_exists?(:project)
end
end
end
end
29 changes: 15 additions & 14 deletions lib/uffizzi/cli.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# frozen_string_literal: true

require 'thor'
require 'uffizzi'

module Uffizzi
class CLI < Thor
require_relative 'cli/common'
class_option :help, type: :boolean, aliases: ['-h', 'help']

class_option :help, type: :boolean, aliases: HELP_MAPPINGS

desc 'version', 'Show Version'
desc 'version', 'show version'
def version
require_relative 'version'
puts Uffizzi::VERSION
Uffizzi.ui.say(Uffizzi::VERSION)
end

desc 'login', 'Login into Uffizzi'
method_option :user, required: true, aliases: '-u'
method_option :hostname, required: true, aliases: '-h'
method_option :hostname, required: true
def login
require_relative 'cli/login'
Login.new(options).run
Expand All @@ -30,16 +30,17 @@ def logout(help = nil)
Logout.new.run
end

desc 'projects', 'projects'
def projects
require_relative 'cli/projects'
Projects.new.run
end
desc 'project', 'project'
require_relative 'cli/project'
subcommand 'project', CLI::Project

desc 'config', 'config'
def config(command, property = nil, value = nil)
require_relative 'cli/config'
Config.new.run(command, property, value)
end
require_relative 'cli/config'
subcommand 'config', CLI::Config

desc 'preview', 'preview'
method_option :project, required: false
require_relative 'cli/preview'
subcommand 'preview', CLI::Preview
end
end
48 changes: 28 additions & 20 deletions lib/uffizzi/cli/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,35 @@

require 'io/console'
require 'uffizzi'
require 'uffizzi/clients/api/api_client'

module Uffizzi
class Config
class CLI::Config < Thor
include ApiClient

def run(command, property, value)
desc 'list', 'list'
def list
run('list')
end

desc 'get', 'get'
def get(property)
run('get', property)
end

desc 'set', 'set'
def set(property, value)
run('set', property, value)
end

desc 'delete', 'delete'
def delete(property)
run('delete', property)
end

private

def run(command, property = nil, value = nil)
case command
when 'list'
handle_list_command
Expand All @@ -17,40 +40,25 @@ def run(command, property, value)
handle_set_command(property, value)
when 'delete'
handle_delete_command(property)
else
puts "#{command} is not a uffizzi config command"
end
end

private

def handle_list_command
ConfigFile.list
end

def handle_get_command(property)
if property.nil?
puts 'No property provided'
return
end
option = ConfigFile.read_option(property.to_sym)
puts option unless option.nil?
message = option.nil? ? "The option #{property} doesn't exist in config file" : option

Uffizzi.ui.say(message)
end

def handle_set_command(property, value)
if property.nil? || value.nil?
puts 'No property provided' if property.nil?
puts 'No value provided' if value.nil?
return
end
ConfigFile.write_option(property.to_sym, value)
end

def handle_delete_command(property)
if property.nil?
puts 'No property provided'
return
end
ConfigFile.delete_option(property.to_sym)
end
end
Expand Down
9 changes: 3 additions & 6 deletions lib/uffizzi/cli/login.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'io/console'
require 'uffizzi'
require 'uffizzi/response_helper'
require 'uffizzi/clients/api/api_client'

module Uffizzi
class CLI::Login
Expand All @@ -17,10 +18,10 @@ def run
params = prepare_request_params(password)
response = create_session(@options[:hostname], params)

if Uffizzi::ResponseHelper.created?(response)
if ResponseHelper.created?(response)
handle_succeed_response(response)
else
handle_failed_response(response)
ResponseHelper.handle_failed_response(response)
end
end

Expand All @@ -35,10 +36,6 @@ def prepare_request_params(password)
}
end

def handle_failed_response(response)
print_errors(response[:body][:errors])
end

def handle_succeed_response(response)
account = response[:body][:user][:accounts].first
return Uffizzi.ui.say('No account related to this email') unless account_valid?(account)
Expand Down
Loading

0 comments on commit ffa09c1

Please sign in to comment.