-
Notifications
You must be signed in to change notification settings - Fork 446
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/.vagrant/ |
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" | ||
|
||
# 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
end | ||
end |
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.")) | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@(message: String) | ||
|
||
@main("Welcome to Play") { | ||
|
||
@play20.welcome(message) | ||
|
||
} |
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> |
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) |
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 | ||
|
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) |
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") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=0.13.8 |
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" |
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 |
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 |
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 |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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 |
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!"); | ||
} |
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' |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
There was a problem hiding this comment.
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.