Skip to content

Commit

Permalink
Major realignment
Browse files Browse the repository at this point in the history
  • Loading branch information
alvagante committed Feb 2, 2017
1 parent 38bb9f3 commit c6be169
Show file tree
Hide file tree
Showing 212 changed files with 18,921 additions and 302 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -11,6 +11,7 @@ spec/fixtures
modules/
/keys/private_key.pkcs7.pem
*.pyc
*Gemfile.lock

# Vagrant artifacts
vagrant/environments/*/ubuntu-xenial-16.04-cloudimg-console.log
Expand Down
92 changes: 64 additions & 28 deletions .gitlab-ci.yml
@@ -1,42 +1,78 @@
# GitLab CI configuration
# Example for public Gitlab workflow
#
stages:
- test
- deploy
- checks
- specs
- diffs
- integration
- live_runs
- merge_request
- promote
- rollout
- postcheck


# Development branch
syntax:
stage: test
stage: checks
before_script:
- "bin/gitlab_before.sh"
script: "bin/puppet_check_syntax_fast.sh"
cache:
untracked: true
paths:
- modules/
tags:
- test_puppet
only:
- development
environment:
name: development
url: https://development.example.com

catalog:
stage: test
lint:
stage: checks
before_script:
- "bin/gitlab_before.sh"
script: "bin/gitlab_catalog_diff.sh"
script: "bin/puppet_lint.sh"
cache:
untracked: true
paths:
- modules/
tags:
- test_puppet
only:
- development
allow_failure: true

vagrant:
stage: test
rake_site:
stage: specs
before_script:
- "bin/gitlab_before.sh"
script: "bin/vagrant_node_test.sh pe-centos7 pe"



deploy_test:
stage: deploy
script:
- echo "Deploy to staging server"
environment:
name: staging
url: https://staging.example.com
script: "bin/puppet_check_rake.sh site"
cache:
untracked: true
paths:
- modules/
tags:
- test_puppet
only:
- development
allow_failure: true

deploy_prod:
stage: deploy
script:
- echo "Deploy to production server"
environment:
name: production
url: https://example.com
when: manual
rake_modules:
stage: specs
before_script:
- "bin/gitlab_before.sh"
script: "bin/puppet_check_rake.sh modules"
cache:
untracked: true
paths:
- modules/
tags:
- test_puppet
only:
- production
- development
allow_failure: true

10 changes: 8 additions & 2 deletions CHANGELOG.md
@@ -1,3 +1,11 @@
## Release 0.0.6
## This control repo has nothing to do with earlier
## example42 puppet modules versions. Resetting versions.
- Added profiles and tools
- Added and improved scripts
- Added wide GitLab integration
- Added Puppet Enterprise integration and Vagrant environment

## Release 4.0.0.beta.3
- Widely improved scripting
- Aws role and relevant profiles and fab commands
Expand All @@ -10,9 +18,7 @@
- Added Docker building or role images (WIP)
- Several improvements


## Release 4.0.0.beta.1

- Introduced hiera-eyaml
- Hiera driven roles definition
- Resource defaults for tp
Expand Down
51 changes: 51 additions & 0 deletions Dangerfile
@@ -0,0 +1,51 @@


# Identify changes type
has_danger_changes = !git.modified_files.grep(/^manifests\/.pp$|^hieradata\/common.yaml$/).empty?
has_puppet_changes = !git.modified_files.grep(/.pp$/).empty?
has_spec_changes = !git.modified_files.grep(/spec/).empty?
is_version_bump = git.modified_files.sort == ["metadata.json", "lib/danger/version.rb"].sort

# Puppet code changes without test changes
if has_puppet_changes && !has_spec_changes
warn("There're changes in manifests, but not tests. That's OK as long as you're refactoring existing code.", sticky: false)
end

# Tests changes without code changes
if !has_puppet_changes && has_spec_changes
message('We really puppetreciate pull requests that demonstrate issues, even without a fix. That said, the next step is to try and fix the failing tests!', sticky: false)
end

# Have you updated CHANGELOG.md?
changelog.check

# Add a CHANGELOG entry for puppet changes
if !git.modified_files.include?("CHANGELOG.md") && has_puppet_changes && is_version_bump
warn("Please include a CHANGELOG entry when changing version).")
message "Note, we hard-wrap at 80 chars and use 2 spaces after the last line."
end

# Changes in files with large impact
if has_danger_changes
warn("This change may impact many systems. Double check what you are doing.", sticky: false)
end


# Ensure a clean commits history
if git.commits.any? { |c| c.message =~ /^Merge branch/ }
warn('Please rebase to get rid of the merge commits in this PR')
end

# Large PR
warn('Big PR') if git.lines_of_code > @SDM_DANGER_BIG_PR_LINES


# GitHub
warn "PR is classed as Work in Progress" if github.pr_title.include? "[WIP]"

if github.pr_body.length < 5
warn "Please provide a summary in the Pull Request description"
end



42 changes: 42 additions & 0 deletions Gemfile
@@ -0,0 +1,42 @@
# puppet lint plugins
# https://puppet.community/plugins/#puppet-lint
gem 'puppet-lint-appends-check',
:git => 'https://github.com/voxpupuli/puppet-lint-appends-check.git',
:require => false
gem 'puppet-lint-classes_and_types_beginning_with_digits-check',
:git => 'https://github.com/voxpupuli/puppet-lint-classes_and_types_beginning_with_digits-check.git',
:require => false
gem 'puppet-lint-empty_string-check',
:git => 'https://github.com/voxpupuli/puppet-lint-empty_string-check.git',
:require => false
gem 'puppet-lint-file_ensure-check',
:git => 'https://github.com/voxpupuli/puppet-lint-file_ensure-check.git',
:require => false
gem 'puppet-lint-leading_zero-check',
:git => 'https://github.com/voxpupuli/puppet-lint-leading_zero-check.git',
:require => false
gem 'puppet-lint-numericvariable',
:git => 'https://github.com/fiddyspence/puppetlint-numericvariable.git',
:require => false
gem 'puppet-lint-resource_reference_syntax',
:git => 'https://github.com/voxpupuli/puppet-lint-resource_reference_syntax.git',
:require => false
gem 'puppet-lint-spaceship_operator_without_tag-check',
:git => 'https://github.com/voxpupuli/puppet-lint-spaceship_operator_without_tag-check.git',
:require => false
gem 'puppet-lint-trailing_comma-check',
:git => 'https://github.com/voxpupuli/puppet-lint-trailing_comma-check.git',
:require => false
gem 'puppet-lint-undef_in_function-check',
:git => 'https://github.com/voxpupuli/puppet-lint-undef_in_function-check.git',
:require => false
gem 'puppet-lint-unquoted_string-check',
:git => 'https://github.com/voxpupuli/puppet-lint-unquoted_string-check.git',
:require => false
gem 'puppet-lint-variable_contains_upcase',
:git => 'https://github.com/fiddyspence/puppetlint-variablecase.git',
:require => false
gem 'puppet-lint-version_comparison-check',
:git => 'https://github.com/voxpupuli/puppet-lint-version_comparison-check.git',
:require => false

24 changes: 24 additions & 0 deletions bin/codemanager_check_deploy.sh
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
repo_dir="$(dirname $0)/.."
. "${repo_dir}/bin/functions"

env=$1

echo_title "Deployment status on ${env}"
sudo cat /etc/puppetlabs/code/environments/$env/.r10k-deploy.json

deployed_commit=$(sudo /usr/bin/cat /etc/puppetlabs/code/environments/$env/.r10k-deploy.json | grep signature | awk '{ print $2}' | sed -e 's/"//g' | sed -e 's/,//')
echo_title "Deployed commit on Puppet Server: ${deployed_commit}"
git show --no-abbrev-commit -s ${deployed_commit}

local_commit=$(git rev-parse HEAD)
echo_title "Latest commit on local runner repo: ${local_commit}"
git show --no-abbrev-commit -s ${local_commit}

if [[ "${deployed_commit}" == "${local_commit}" ]]; then
echo_success "Code correctly deployed to Puppet Server"
exit 0
else
echo_failure "Code not correctly deployed to Puppet Server !!!"
exit 1
fi
6 changes: 5 additions & 1 deletion bin/enc_cat.sh
Expand Up @@ -4,4 +4,8 @@ script_dir="$(dirname $0)"
. "${script_dir}/functions"

host=$1
cat "${repo_dir}/bin/enc_cat/${host}.yaml"
if [ -f "${repo_dir}/bin/enc_cat/${host}.yaml" ]; then
cat "${repo_dir}/bin/enc_cat/${host}.yaml"
else
cat "${repo_dir}/bin/enc_cat/default.yaml"
fi
7 changes: 7 additions & 0 deletions bin/enc_cat/default.yaml
@@ -0,0 +1,7 @@
---
environment: production
classes:
- profile::base::pre
parameters:
env: development
role: default
25 changes: 25 additions & 0 deletions bin/gitlab_accept_merge_request.rb
@@ -0,0 +1,25 @@
#!/usr/bin/env ruby
require 'gitlab'
GITLAB_CONFIG='/etc/gitlab-cli.conf'
config = {}
File.foreach GITLAB_CONFIG do |line|
k = line.split("=")[0].gsub("\n",'') if line =~/=/
v = line.split("=")[1].gsub("\n",'') if line =~/=/
config.store(k,v)
end
last_commit=`git log -1 --oneline`
source_branch = ARGV[0] ? ARGV[0] : 'none'
destination_branch = ARGV[1] ? ARGV[1] : 'master'
mr_title = ARGV[2] ? ARGV[2] : "Merged: #{last_commit} from #{source_branch} to #{destination_branch}"
project_id = config['GITLAB_API_PROJECT_ID']
endpoint = config['GITLAB_API_ENDPOINT']
private_token = config['GITLAB_API_PRIVATE_TOKEN']
httparty = config['GITLAB_API_HTTPARTY_OPTIONS'].gsub("'",'')

Gitlab.endpoint = endpoint
Gitlab.private_token = private_token
Gitlab.httparty = eval(httparty)
merge_requests = Gitlab.merge_requests(project_id, { page: 1 })
mr_id = merge_requests.first.to_h['id']
Gitlab.accept_merge_request(project_id,mr_id, { merge_commit_message: "#{mr_title}" })

2 changes: 0 additions & 2 deletions bin/gitlab_before.sh
Expand Up @@ -4,8 +4,6 @@ script_dir="$(dirname $0)"
# repo_dir=$(git rev-parse --show-toplevel)
. "${script_dir}/functions"

ln -s Puppetfile_public Puppetfile

echo
cd $repo_dir
echo_title "Installing external modules via r10k"
Expand Down
51 changes: 42 additions & 9 deletions bin/gitlab_catalog_diff.sh
@@ -1,13 +1,46 @@
#!/usr/bin/env bash
repo_dir="$(dirname $0)/.."
. "${repo_dir}/bin/functions"
test -f /etc/gitlab-ci.conf && . /etc/gitlab-ci.conf
default_nodes=$catalag_diff_default_nodes
always_nodes=$catalag_diff_always_nodes

node='git.lan'
diff_commits_number=1

PUPPET=$(which puppet)
ERB=$(which erb)
RUBY=$(which ruby)
global_exit=0
if [[ "x$1" != "x" ]]; then
git checkout $1
git pull
fi
diff_commits_number=$(git log production..$1 --pretty=oneline | wc -l)
echo "Checking for files in the last $diff_commits_number commits"
for changedfile in $(git diff HEAD~$diff_commits_number --name-only); do
node=''
if [[ $(echo "$changedfile" | grep -q 'hieradata/hostname'; echo $?) -eq 0 ]]; then
node=$(echo $changedfile | sed -e "s/^hieradata\/hostname\///" -e "s/\.yaml//")
fi
if [[ $(echo "$changedfile" | grep -q 'hieradata/role'; echo $?) -eq 0 ]]; then
role=$(echo $changedfile | sed -e "s/^hieradata\/role\///" -e "s/\.yaml//")
fi

octocatalog-diff -n $node
exit $global_exit
if [[ "x$node" != "x" ]]; then
echo
echo "Catalog diff on ${node} - Check based on commits"
octocatalog-diff -n $node
fi

if [[ "x$role" != "x" ]]; then
echo
echo "Catalog diff on role ${role} - Check based on commits"
octocatalog-diff -n $role.$(facter domain)
fi
done

for node in $default_nodes; do
echo
echo "Catalog diff on ${node} - Default check"
octocatalog-diff -n $node
done

for node in $always_nodes; do
echo
echo "Catalog diff on ${node} - Check always done"
octocatalog-diff -n $node
done

0 comments on commit c6be169

Please sign in to comment.