GithubHelp home page GithubHelp logo

codily's Introduction

Codily: Codificate your Fastly configuration

still in beta

Codily allows you to manage your Fastly configuration in Ruby DSL!

Installation

# Gemfile
gem 'codily'

Or install it yourself as:

$ gem install codily --pre

Usage

Usage: codily [options]
    -a, --apply
    -e, --export
    -v, --version
    -f, --file PATH                  file to apply, or file path to save exported file (default to ./codily.rb on applying)
    -t, --target REGEXP              Filter services by name to apply or export.
    -n, --dry-run                    Just displays the oprerations that would be performed, without actually running them.
    -D, --debug                      Debug mode
    -A, --activate                   Activate after apply
    -V, --target-version SVC_VER     Choose version to export (format= service_name:version) This option can be used multiple time..
codily --help

codily --export
codily --export --target my-service
codily --export --target my-service --target-version my-service:42
codily --export --file ./codily.rb

codily --apply --file ./codily.rb
codily --apply --file ./codily.rb --activate
codily --apply --file ./codily.rb --dry-run
codily --apply --file ./codily.rb --target my-service

You have to set api key in environment variable FASTLY_API_KEY

Restrictions

  • Directors are not supported due to its deprecation

DSL

tl;dr

It's easy to start by export existing configuration into DSL using --export option.

service "foo" do
  backend "my backend" do
    address "example.com"
  end
end

Loading file

some attributes (e.g. tls certificates, tls keys, VCL content, response object content) supports loading value from a file.

service "foo" do
  vcl "default" do
    main true
    content file: './my.vcl'
  end
end

Referring other object (e.g. condition)

Some attributes that refers other object (e.g. conditions), you can define referring object as like the following:

service "foo" do
  response_object "method not allowed" do
    status "405"
    response "Method Not Allowed"
    content "405"
    content_type "text/plain"

    request_condition "request method is not GET, HEAD or FASTLYPURGE" do
      priority 10
      statement '!(req.request == "GET" || req.request == "HEAD" || req.request == "FASTLYPURGE")'
    end
  end
end

# equals as follows:

service "foo" do
  condition "request method is not GET, HEAD or FASTLYPURGE" do
    priority 10
    statement '!(req.request == "GET" || req.request == "HEAD" || req.request == "FASTLYPURGE")'
    type "REQUEST"
  end

  response_object "method not allowed" do
    status "405"
    response "Method Not Allowed"
    content "405"
    content_type "text/plain"
    request_condition "request method is not GET, HEAD or FASTLYPURGE"
  end
end

Full example

Basically, all attributes are

service "test.example.com" do
  backend "name" do
    address
    auto_loadbalance
    between_bytes_timeout
    client_cert
    comment
    connect_timeout
    error_threshold
    first_byte_timeout
    healthcheck
    hostname
    max_conn
    max_tls_version
    min_tls_version
    port
    request_condition
    service_id
    shield
    ssl_ca_cert
    ssl_cert_hostname
    ssl_check_cert
    ssl_ciphers
    ssl_client_cert
    ssl_client_key
    ssl_hostname
    ssl_sni_hostname
    use_ssl
    weight
  end

  cache_setting "name" do
    action
    stale_ttl
    ttl

    cache_condition "name"
    # cache_condition do
    #   comment
    #   priority
    #   statement
    # end
  end

  condition "name" do
    comment
    priority
    statement
  end

  dictionary "name"

  domain "a.example.org"
  domain "a.example.org" do
    comment ""
  end

  gzip "name" do
    content_types %w(text/html)
    extensions %w(html)
    cache_condition "name"
    # cache_condition do
    #   comment
    #   priority
    #   statement
    # end
  end

  header 'name' do
    action
    src
    dst
    ignore_if_set
    priority
    substitution
    type
    cache_condition
    request_condition
    response_condition
  end

  healthcheck 'name' do
    check_interval
    comment
    expected_response
    host
    http_version
    initial
    method
    path
    threshold
    timeout
    window
  end

  request_setting "name" do
    action
    bypass_busy_wait
    default_host
    force_miss
    force_ssl
    geo_headers
    hash_keys
    max_stale_age
    timer_support
    xff
    request_condition
  end

  response_object "name" do
    content
    content_type
    status
    response
    cache_condtiion
    request_condition
  end

  vcl "name" do
    content file: 'xxx'
    main true
  end

  settings(
    "general.default_ttl": 3600,
  )
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/sorah/codily.

License

The gem is available as open source under the terms of the MIT License.

codily's People

Contributors

grezar avatar sorah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

grezar

codily's Issues

NoMethodError failure on attempt to add new service to fastly

I have a new service which I am attempting to create on Fastly. This service has been configured in the local file blog-staging.cookpad.com.rb
When running with the dry-run flag I see the following error :

envchain fastly-cookpad bundle exec codily --apply --file ./blog-staging.cookpad.com.rb --dry-run
bundler: failed to load command: codily (/Users/mrl/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/bin/codily)
NoMethodError: undefined method `number' for nil:NilClass
  /Users/mrl/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/bundler/gems/codily-f950ca6a9ba3/lib/codily/root.rb:35:in `service_version_set'
  /Users/mrl/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/bundler/gems/codily-f950ca6a9ba3/lib/codily/importer.rb:41:in `block in run'
  /Users/mrl/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/bundler/gems/codily-f950ca6a9ba3/lib/codily/importer.rb:37:in `each'
  /Users/mrl/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/bundler/gems/codily-f950ca6a9ba3/lib/codily/importer.rb:37:in `run'
  /Users/mrl/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/bundler/gems/codily-f950ca6a9ba3/lib/codily/cli.rb:42:in `do_apply'
  /Users/mrl/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/bundler/gems/codily-f950ca6a9ba3/lib/codily/cli.rb:22:in `run'
  /Users/mrl/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/bundler/gems/codily-f950ca6a9ba3/bin/codily:6:in `<top (required)>'
  /Users/mrl.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/bin/codily:23:in `load'
  /Users/mrl/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/bin/codily:23:in `<top (required)>'

I also saw this error when running the same operation with a file that already has been setup as a service (with dry-run flag set).
I was using my own token for fastly in envchain.

The following workaround was used locally to temporarily overcome this issue
vi ~/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/bundler/gems/codily-f950ca6a9ba3/lib/codily/root.rb
in method service_version_set
line 35 was

active = (versions.reverse_each.find(&:active) || versions.reverse_each.find(&:locked)).number

line 35 now

active = (versions.reverse_each.find(&:active) || versions.reverse_each.find(&:locked))&.number

domain has been added, not changed

Codily is a best practice to manage fastly. Thank you.

I found a codily bug? so I report it.

  • Wrong Case

I used codily to set the domain.
domain has been added not changed, when I changed domain and execute codily --apply --file ./hoge.rb (not specified dry-run or apply option)

  • Sample Code

$domain_names=[
  'aaa.hoge.com',
  'bbb.hoge.com',
  'ccc.hoge.com',
-  'ddd.hoge.com'   <--- modifyed from
+  'eee.hoge.com'   <--- modifyed to
]

service "#{service_name}" do
  # Domain Seting
  $domain_names.each { |domain_name|
    domain "#{domain_name}"
  }
  ... ...

end
  • unexpected diff
 domains:
 - name: aaa.hoge.com
   comment: ''
 - name: bbb.hoge.com
   comment: ''
+- name: eee.hoge.com
+  comment: ''
 - name: ddd.hoge.com
   comment: ''
  • Behavior to expect
 domains:
 - name: aaa.hoge.com
   comment: ''
 - name: bbb.hoge.com
   comment: ''
+- - name: eee.hoge.com
   comment: ''

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.