项目作者: e-graveyard

项目描述 :
Ruby CI/CD pipeline with Travis
高级语言: Ruby
项目地址: git://github.com/e-graveyard/sinatra-pipeline.git
创建时间: 2018-12-13T13:40:04Z
项目社区:https://github.com/e-graveyard/sinatra-pipeline

开源协议:MIT License

下载


Build Status

Sinatra CI/CD pipeline with Travis

This repository contains a simple Sinatra web application, the unit tests and a
CI/CD pipeline using Travis-CI.

Table of Contents

The Application

The web application tries to establish a RESTful API that interacts with a
PostgreSQL database. It simply create new “person” records on POST requests and
query by the id on GET requests.

Requirements

System

  • Ruby 2.2.10 (or superior).

Gems

Usage

Vendor

To install the required libraries/3rd-party dependencies, use:

  1. $ make install

This target will install bundler and, with bundler, install the necessary gems.
Alternatively, just use:

  1. $ bundle install

Execution

To start the service, use:

  1. $ make run

This target uses rack, so the service port will be binded, by default, to
9292. Alternatively, just use:

  1. $ ruby src/app.py

To do it directly. In this case, the service port will be binded to 4567.

Environment

The following environment variables are used by the service:

Variable Description
PG_HOST The database hostname
PG_PORT The port number
PG_USER The database username
PG_DBNM The username password

Database Schema

The service expects an already created database with a table called users.
The table should have the following schema:

  1. id SERIAL
  2. name VARCHAR(255)
  3. surname VARCHAR(255)
  4. age INT

After connecting to the database:

  • Create the database
  1. CREATE DATABASE sinatra;
  2. USE sinatra;
  • Create the table users
  1. CREATE TABLE users (id SERIAL, name VARCHAR(255), surname VARCHAR(255), age INT);

API

The application exposes three routes:

  • GET /

    Returns a “Hello World“.

  • GET /users/:id

    Connects to the database and query the users table by the id. The
    response should be similar to:

    1. {
    2. "name": "John",
    3. "surname": "Williams",
    4. "age": "86"
    5. }
  • POST /users

    Connects to the database and inserts a new row into the users table. The
    payload should contains the keys name (string), surname (string) and
    age (int).

    E.g. (using the http tool):

    • http POST :4567 name="John" surname="Williams" age=86

Tests

To execute the unit tests, use:

  1. $ make test

The Pipeline

The pipeline tries to accomplish a flow where, given a new release (a tag), a
new Docker image is generated and pushed to a private Docker registry (in AWS,
with ECR. It’s the “CD“ (continuous delivery) aspect of it. The
CI“ (continuous integration) is achieved by the unit tests.

Steps

Test

  • Dependency : N/A.
  • Condition : push, pull request and tag
  • Description : Installs the dependencies and execute the unit tests.

Build

  • Dependency : test
  • Condition : push on master or tag
  • Description : Builds the Docker image.

Publish

  • Dependency : build
  • Condition : tag
  • Description : Tags the builded image and pushes to the registry.