Skip to content

Commit

Permalink
structuring
Browse files Browse the repository at this point in the history
  • Loading branch information
Dharmender Singh authored and Dharmender Singh committed Mar 1, 2017
1 parent 98fde1e commit 79ce0e6
Show file tree
Hide file tree
Showing 12 changed files with 473 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .fixtures.yml
@@ -0,0 +1,7 @@
fixtures:
repositories:
stdlib:
repo: 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
ref: '4.1.0'
symlinks:
verdaccio: "#{source_dir}"
15 changes: 15 additions & 0 deletions .gitignore
@@ -0,0 +1,15 @@
## MAC OS
.DS_Store

## TEXTMATE
*.tmproj
tmtags

## EMACS
*~
\#*
.\#*

## VIM
*.swp
tags
7 changes: 7 additions & 0 deletions Gemfile
@@ -0,0 +1,7 @@
source 'https://rubygems.org'

puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 3.3']
gem 'puppet', puppetversion
gem 'puppetlabs_spec_helper', '>= 0.1.0'
gem 'puppet-lint', '>= 0.3.2'
gem 'facter', '>= 1.7.0'
98 changes: 98 additions & 0 deletions README.md
@@ -0,0 +1,98 @@
# puppet-verdaccio module

## Overview

Install verdaccio npm-cache-server (https://github.com/verdaccio/verdaccio) for Debian, Ubuntu, Fedora, and RedHat.


## Usage

There are two variants to install verdaccio using this Puppet module: Apply-mode (with puppet-apply and no puppetmaster setup needed) or Master-Agent-mode (with puppet-agent accessing your configuration through the puppetmaster). In both variants you have to explicitely call "class nodejs {}" in your puppet script because the puppet-verdaccio module only defines this as a requirement, so you have all the flexibility you want when installing nodejs. Scroll down for details about Master-Agent-mode variant.

### General usage

#### class verdaccio

Installs verdaccio + required npms in one defined directory and integrates the verdaccio as a service (/etc/init.d/verdaccio). It also creates a user to run the verdaccio server (default: verdaccio). If you wish, you can change the username, see examples below.

Examples:

minimal:

```bash
class { '::verdaccio':
conf_admin_pw_hash => 'your-pw-hash',
}
```

You can generate the admin password hash according to https://github.com/verdaccio/verdaccio via command-line:

```bash
$ node
> crypto.createHash('sha1').update('your-admin-password').digest('hex')
```

You can also override several configuration parameters.

```bash
class { '::verdaccio':
install_root => '/usr/local',
install_dir => 'verdaccioxy',
conf_admin_pw_hash => 'your-pw-hash',
conf_port => '8080',
deamon_user => 'verdaccioxy',
conf_listen_to_address => '127.0.0.1',
http_proxy => 'http://proxy.com:3128',
https_proxy => 'http://proxy.com:3128',
conf_template => 'mymodule/config.yaml.erb',
service_template => 'mymodule/service.erb',
conf_max_body_size => '10mb',
conf_max_age_in_sec => '604800',
install_as_service => false,
}
```

The default values for all so far configurable parameters are:

```bash
class { '::verdaccio':
install_root => '/opt',
install_dir => 'verdaccio',
deamon_user => 'verdaccio',
conf_listen_to_address => '0.0.0.0',
conf_port => '4783',
conf_admin_pw_hash
conf_user_pw_combinations => undef,
http_proxy => '',
https_proxy => '',
conf_template => 'verdaccio/config.yaml.erb',
service_template => 'verdaccio/service.erb',
conf_max_body_size => '1mb',
conf_max_age_in_sec => '86400',
install_as_service => true,
}
```





### Master-Agent-mode installation

In your puppet script for your agent add:
```bash
class { 'nodejs':
# this automatically installs nodejs and npm
make_default => true,
}
class { '::verdaccio':
conf_admin_pw_hash => 'your-pw-hash',
}
```

## Supported Platforms

The module has been tested on the following operating systems. Testing and patches for other platforms are welcome.

* RedHat EL7.

18 changes: 18 additions & 0 deletions Rakefile
@@ -0,0 +1,18 @@
require 'rubygems'
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]

desc "Validate manifests, templates, and ruby files"
task :validate do
Dir['manifests/**/*.pp'].each do |manifest|
sh "puppet parser validate --noop #{manifest}"
end
Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file|
sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/
end
Dir['templates/**/*.erb'].each do |template|
sh "erb -P -x -T '-' #{template} | ruby -c"
end
end
122 changes: 122 additions & 0 deletions manifests/init.pp
@@ -0,0 +1,122 @@
# Class: puppet-verdaccio
#
# This module manages verdaccio npm-cache-server installations.
#
# Parameters:
#
# conf_admin_pw_hash
# generate the password hash for your plain text password (e.g. newpass) with:
# $ node
# > crypto.createHash('sha1').update('newpass').digest('hex')
#
# conf_listen_to_address
# the ip4 address your proxy is supposed to listen to,
# default 0.0.0.0 (=all addresses)
#
# Actions:
#
# Requires: see Modulefile
#
# Sample Usage:
#
class verdaccio (
$install_root = '/opt',
$install_dir = 'verdaccio',
$version = undef, # latest
$deamon_user = 'verdaccio',
$package_name = 'verdaccio',
$conf_listen_to_address = '0.0.0.0',
$conf_port = '4783',
$conf_admin_pw_hash,
$conf_user_pw_combinations = undef,
$http_proxy = '',
$https_proxy = '',
$conf_template = 'verdaccio/config.yaml.erb',
$service_template = 'verdaccio/service.erb',
$conf_max_body_size = '1mb',
$conf_max_age_in_sec = '86400',
$install_as_service = true,) {
require nodejs
$install_path = "${install_root}/${install_dir}"

group { $deamon_user:
ensure => present,
}

user { $deamon_user:
ensure => present,
gid => $deamon_user,
managehome => true,
require => Group[$deamon_user]
}

file { $install_root:
ensure => directory,
}

file { $install_path:
ensure => directory,
owner => $deamon_user,
group => $deamon_user,
require => [User[$deamon_user], Group[$deamon_user]]
}

### ensures, that always the latest versions of npm modules are installed ###
$modules_path="${install_path}/node_modules"
file { $modules_path:
ensure => absent,
}

$service_notify = $install_as_service ? {
default => undef,
true => Service['verdaccio']
}
nodejs::npm { "${install_path}:${package_name}":
version => $version,
ensure => present,
require => [File[$install_path,$modules_path],User[$deamon_user]],
notify => $service_notify,
exec_as_user => $deamon_user,
}

###
# config.yaml requires $admin_pw_hash, $port, $listen_to_address
###
file { "${install_path}/config.yaml":
ensure => present,
owner => $deamon_user,
group => $deamon_user,
content => template($conf_template),
require => File[$install_path],
notify => $service_notify,
}

file { "${install_path}/deamon.log":
ensure => present,
owner => $deamon_user,
group => $deamon_user,
require => File[$install_path],
}

if $install_as_service {
$init_file = '/etc/init.d/verdaccio'

file { $init_file:
content => template($service_template),
mode => '0755',
notify => $service_notify,
}

service { 'verdaccio':
ensure => running,
enable => true,
hasstatus => true,
restart => true,
require => File[
$init_file,
"${install_path}/config.yaml",
"${install_path}/deamon.log"
]
}
}
}
14 changes: 14 additions & 0 deletions metadata.json
@@ -0,0 +1,14 @@
{
"name": "puppet-verdaccio",
"version": "0.0.1",
"author": "Dharmender Singh",
"summary": "Installing Verdaccio Npm Package",
"license": "Apache 2.0",
"source": "github",
"project_page": null,
"issues_url": null,
"dependencies": [
{"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"}
]
}

7 changes: 7 additions & 0 deletions spec/classes/init_spec.rb
@@ -0,0 +1,7 @@
require 'spec_helper'
describe 'verdaccio' do

context 'with defaults for all parameters' do
it { should contain_class('verdaccio') }
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
@@ -0,0 +1 @@
require 'puppetlabs_spec_helper/module_spec_helper'
89 changes: 89 additions & 0 deletions templates/config.yaml.erb
@@ -0,0 +1,89 @@
# path to a directory with all packages
storage: ./storage

# a list of users
users:
admin:
# crypto.createHash('sha1').update(pass).digest('hex')
password: <%=@conf_admin_pw_hash %>
<% if @conf_user_pw_combinations != nil %>
<% @conf_user_pw_combinations.each do |combi|
-%><%= combi[0] %>:
password: <%= combi[1] %>
<% end -%>
<% end -%>
# a list of other known repositories we can talk to
uplinks:
npmjs:
url: https://registry.npmjs.org/

# amount of time (in milliseconds) to wait for repository to respond
# before giving up and use the local cached copy
#timeout: 30000

# maximum time (in seconds) in which data is considered up to date
#
# default is 2 minutes, so server won't request the same data from
# uplink if a similar request was made less than 2 minutes ago
#maxage: 120
maxage: <%=@conf_max_age_in_sec %>

packages:
# uncomment this for packages with "local-" prefix to be available
# for admin only, it's a recommended way of handling private packages
#'local-*':
# allow_access: admin
# allow_publish: admin
# # you can override storage directory for a group of packages this way:
# storage: 'local_storage'

'*':
# allow all users to read packages ('all' is a keyword)
# this includes non-authenticated users
allow_access: all

# allow 'admin' to publish packages
allow_publish: admin
# if package is not available locally, proxy requests to 'npmjs' registry
proxy: npmjs

#####################################################################
# Advanced settings
#####################################################################

# if you use nginx with custom path, use this to override links
#url_prefix: https://dev.company.local/sinopia/

# you can specify listen address (or simply a port)
# listen: localhost:4783
listen: <%=@conf_listen_to_address %>:<%=@conf_port %>

# type: file | stdout | stderr
# level: trace | debug | info | http (default) | warn | error | fatal
#
# parameters for file: name is filename
# {type: 'file', path: 'sinopia.log', level: 'debug'},
#
# parameters for stdout and stderr: format: json | pretty
# {type: 'stdout', format: 'pretty', level: 'debug'},
logs:
- {type: stdout, format: pretty, level: http}
#- {type: file, path: sinopia.log, level: info}

# you can specify proxy used with all requests in wget-like manner here
# (or set up ENV variables with the same name)
<% if @http_proxy %>
http_proxy: <%= @http_proxy %>
<% end %>
<% if @https_proxy %>
https_proxy: <%= @https_proxy %>
<% end %>
#http_proxy: http://something.local/
#https_proxy: https://something.local/
#no_proxy: localhost,127.0.0.1

# maximum size of uploaded json document
# increase it if you have "request entity too large" errors
#max_body_size: 1mb
max_body_size: <%=@conf_max_body_size %>

0 comments on commit 79ce0e6

Please sign in to comment.