Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A Vagrant+Ansible automated test project #542

Merged
merged 3 commits into from
Apr 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test-project-play-rpm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.vagrant/
76 changes: 76 additions & 0 deletions test-project-play-rpm/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.

# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "chef/centos-6.6"

# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080

# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"

# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"

# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
config.vm.synced_folder "..", "/vagrant"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will sync the complete sbt-native-packager project directory, rather than just this test subdirectory.


# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
# vb.gui = true

# Customize the amount of memory on the VM:
vb.memory = "2048"
end
#
# View the documentation for the provider you are using for more
# information on available options.

# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end

# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# sudo apt-get update
# sudo apt-get install -y apache2
# SHELL

config.vm.provision :ansible do |ansible|
ansible.playbook = "provisioning/site.yml"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vagrant up --provision or vagrant provision will run the site.yml playbook against the vm.

end
end
12 changes: 12 additions & 0 deletions test-project-play-rpm/app/controllers/Application.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package controllers

import play.api._
import play.api.mvc._

object Application extends Controller {

def index = Action {
Ok(views.html.index("Your new application is ready."))
}

}
7 changes: 7 additions & 0 deletions test-project-play-rpm/app/views/index.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@(message: String)

@main("Welcome to Play") {

@play20.welcome(message)

}
15 changes: 15 additions & 0 deletions test-project-play-rpm/app/views/main.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@(title: String)(content: Html)

<!DOCTYPE html>

<html>
<head>
<title>@title</title>
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
<script src="@routes.Assets.at("javascripts/hello.js")" type="text/javascript"></script>
</head>
<body>
@content
</body>
</html>
25 changes: 25 additions & 0 deletions test-project-play-rpm/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

scalaVersion in ThisBuild := "2.11.6"

scalacOptions in ThisBuild ++= Seq(
"-deprecation",
"-encoding", "UTF-8",
"-feature",
"-unchecked",
"-Xfuture",
"-Xlint"
)

resolvers in ThisBuild += Resolver.typesafeRepo("releases")

name := "test-project-play-rpm"

description := "Demo of RPM packaging"

libraryDependencies ++= Seq(
"com.typesafe.play" %% "play" % "2.3.8"
)

enablePlugins(PlayScala)

enablePlugins(RpmPlugin)
62 changes: 62 additions & 0 deletions test-project-play-rpm/conf/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This is the main configuration file for the application.
# ~~~~~

# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
#
# This must be changed for production, but we recommend not changing it in this file.
#
# See http://www.playframework.com/documentation/latest/ApplicationSecret for more details.
application.secret="q]BJOWD^B`A:h/Q?CJQm^D3_FArb0^P@FEF/OET8`sYERqB<cJ?wXO9@ELIPO0N"

# The application languages
# ~~~~~
application.langs="en"

# Global object class
# ~~~~~
# Define the Global object class for this application.
# Default to Global in the root package.
# application.global=Global

# Router
# ~~~~~
# Define the Router object to use for this application.
# This router will be looked up first when the application is starting up,
# so make sure this is the entry point.
# Furthermore, it's assumed your route file is named properly.
# So for an application router like `my.application.Router`,
# you may need to define a router file `conf/my.application.routes`.
# Default to Routes in the root package (and conf/routes)
# application.router=my.application.Routes

# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#
# db.default.driver=org.h2.Driver
# db.default.url="jdbc:h2:mem:play"
# db.default.user=sa
# db.default.password=""

# Evolutions
# ~~~~~
# You can disable evolutions if needed
# evolutionplugin=disabled

# Logger
# ~~~~~
# You can also configure logback (http://logback.qos.ch/),
# by providing an application-logger.xml file in the conf directory.

# Root logger:
logger.root=ERROR

# Logger used by the framework:
logger.play=INFO

# Logger provided to your application:
logger.application=DEBUG

9 changes: 9 additions & 0 deletions test-project-play-rpm/conf/routes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
GET / controllers.Application.index

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
33 changes: 33 additions & 0 deletions test-project-play-rpm/packaging.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import com.typesafe.sbt.packager.archetypes.ServerLoader


// controls the name of the bash script
executableScriptName := "play-demo-run"

maintainer := "Maintainer <[email protected]>"

packageSummary := "A demo RPM package of Play"

packageDescription := "A demonstration of using sbt-native-packager to package a Play app as an RPM"


// controls the logical name of the linux package
packageName in Linux := "play-demo"

daemonUser in Linux := "play-demo-user"

daemonGroup in Linux := "play-demo-group"

daemonShell in Linux := "/bin/bash"


// RPM settings

serverLoading in Rpm := ServerLoader.SystemV

rpmRelease := "1"

// Name of the vendor for this RPM.
rpmVendor := "DemoVendor"

rpmLicense := Some("Apache-2.0")
1 change: 1 addition & 0 deletions test-project-play-rpm/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.8
13 changes: 13 additions & 0 deletions test-project-play-rpm/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resolvers += Resolver.typesafeRepo("releases")

libraryDependencies <+= Def.setting[ModuleID] {
Defaults.sbtPluginExtra(
"com.typesafe.play" % "sbt-plugin" % "2.3.8",
(sbtBinaryVersion in update).value,
(scalaBinaryVersion in update).value).exclude("com.typesafe.sbt", "sbt-native-packager")
}

lazy val root = Project("plugins", file(".")) dependsOn(packager)

lazy val packager = file("..").getAbsoluteFile.toURI

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
oracle_jdk_rpm: "jdk-8u40-linux-x64.rpm"
oracle_jdk_url: "http://download.oracle.com/otn-pub/java/jdk/8u40-b25/{{ oracle_jdk_rpm }}"
oracle_license_accept_cookie: "gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie"
21 changes: 21 additions & 0 deletions test-project-play-rpm/provisioning/roles/jdk/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: fetch oracle jdk rpm
uri:
url: "{{ oracle_jdk_url }}"
dest: "/tmp/{{ oracle_jdk_rpm }}"
creates: "/tmp/{{ oracle_jdk_rpm }}"
HEADER_Cookie: "{{ oracle_license_accept_cookie }}"
register: fetch_jdk_rpm

- name: install jdk rpm from local file
yum:
name: "/tmp/{{ oracle_jdk_rpm }}"
state: present
when: fetch_jdk_rpm | changed

- name: add java home env var
lineinfile:
dest: /etc/profile.d/java_home.sh
create: yes
line: "export JAVA_HOME=/usr/java/jdk1.8.0_40/"
state: present
8 changes: 8 additions & 0 deletions test-project-play-rpm/provisioning/roles/rpm/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: rpm dev tools
yum:
name: "{{ item }}"
state: present
with_items:
- rpm-build
- rpmlint
6 changes: 6 additions & 0 deletions test-project-play-rpm/provisioning/roles/sbt/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: install sbt-extras
get_url:
url: https://raw.githubusercontent.com/paulp/sbt-extras/master/sbt
dest: /usr/bin/sbt
mode: 0755
19 changes: 19 additions & 0 deletions test-project-play-rpm/provisioning/site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- hosts: all
sudo: true
pre_tasks:
- yum:
name: "{{ item }}"
with_items:
- python
- libselinux-python
- python-setuptools
- python-setuptools-devel
- easy_install:
name: pip
- pip:
name: httplib2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These packages are required so that Ansible can execute http requests on the guest vm.

roles:
- jdk
- rpm
- sbt
42 changes: 42 additions & 0 deletions test-project-play-rpm/provisioning/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
- hosts: all
sudo: true
vars:
project_dir: /vagrant/test-project-play-rpm
prog: play-demo
prog_v: "1.0"
rpm_dir: "{{ project_dir }}/target/rpm/RPMS/noarch/"
rpm_file: "{{ rpm_dir }}/{{ prog }}-{{ prog_v }}-1.noarch.rpm"
test_url: "http://localhost:9000"
tasks:
- name: sbt build
shell: ./run-sbt-build.sh
args:
chdir: "{{ project_dir }}"
- name: check for output rpm
stat:
path: "{{ rpm_file }}"
register: rpm_stat
- assert:
that:
- rpm_stat.stat.isreg
- name: install rpm
yum:
name: "{{ rpm_file }}"
state: present
- pause: seconds=5
- name: run http health check
uri:
url: "{{ test_url }}"
- name: restart service
service:
name: play-demo
state: restarted
- pause: seconds=5
- name: run http health check again
uri:
url: "{{ test_url }}"
- name: uninstall rpm
yum:
name: play-demo
state: absent
Binary file added test-project-play-rpm/public/images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions test-project-play-rpm/public/javascripts/hello.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if (window.console) {
console.log("Welcome to your Play application's JavaScript!");
}
Empty file.
8 changes: 8 additions & 0 deletions test-project-play-rpm/run-sbt-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'

sbt --warn update compile
sbt 'rpm:packageBin'
7 changes: 7 additions & 0 deletions test-project-play-rpm/run-test-playbook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'

ansible-playbook --private-key=.vagrant/machines/default/virtualbox/private_key --user=vagrant --connection=ssh --limit='default' --inventory-file=.vagrant/provisioners/ansible/inventory provisioning/test.yml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading