A Vagrantfile for Payara Server
Originally published on 02 Jul 2015
Last updated on 05 Apr 2016
This is a preview of a personal project I've been working on which I'm sharing (through Payara) with the community, hence it's not exactly polished and there's still plenty more I'd like to do with it - although I could probably say that about most of the things I
work on in my spare time.
For those already familiar with Vagrant concepts and who just want to get started and look for themselves, the repository is here: https://github.com/mikecroft/payara-vagrant For those who haven't used Vagrant before, or are new to DevOps in general, there's probably no better place to get up and running with Vagrant than to look at the official documentation. Vagrant is a tool that's been around for a while now, and become quite popular with developers. It is very different to something like Docker, although it can be used to achieve the same goals.
In a nutshell, Vagrant wraps, and provides an interface to, a Virtual Machine (VM) provider.Originally Vagrant was designed for use with VirtualBox, an already well-established VM platform, although there are now plugins for AWS and VMWare so you can even use Vagrant in the provisioning of VMs on ESXi in an enterprise scenario. The advantage of this is that, if you're sure about the base image you're working with - for example, a clean LTS version of Ubuntu or RedHat - which will be supported for a while, you can switch the virtualisation layer in and out with minimal fuss.In theory - the Ubuntu 14.04 compatible Vagrantfile you created with VirtualBox should also work with an Ubuntu 14.04 Amazon EC2 instance.
Rather than downloading the image every time, it gets downloaded once and can then be cloned for each time you need to start a VM based on that image.What will also happen is that Vagrant will read the Vagrantfile and find that, aside from giving the VM 1GB of RAM, I have also provided a bash script to provision the instance, imaginatively named provision.sh.Once that's all finished (which might take quite a while), you'll be able to ssh into your instance and deploy to Payara, with a single, simple command:
work on in my spare time.
For those already familiar with Vagrant concepts and who just want to get started and look for themselves, the repository is here: https://github.com/mikecroft/payara-vagrant For those who haven't used Vagrant before, or are new to DevOps in general, there's probably no better place to get up and running with Vagrant than to look at the official documentation. Vagrant is a tool that's been around for a while now, and become quite popular with developers. It is very different to something like Docker, although it can be used to achieve the same goals.
In a nutshell, Vagrant wraps, and provides an interface to, a Virtual Machine (VM) provider.Originally Vagrant was designed for use with VirtualBox, an already well-established VM platform, although there are now plugins for AWS and VMWare so you can even use Vagrant in the provisioning of VMs on ESXi in an enterprise scenario. The advantage of this is that, if you're sure about the base image you're working with - for example, a clean LTS version of Ubuntu or RedHat - which will be supported for a while, you can switch the virtualisation layer in and out with minimal fuss.In theory - the Ubuntu 14.04 compatible Vagrantfile you created with VirtualBox should also work with an Ubuntu 14.04 Amazon EC2 instance.
Using the Vagrantfile
You will need:- Git (preferable, but not strictly necessary)
- Vagran
- VirtualBox
git clone https://github.com/mikecroft/payara-vagrant.git
cd payara-vagrant
vagrant up
You should see a lot of output in your console telling you that Vagrant is downloading the ubuntu/trusty64 (14.04 LTS) VirtualBox base image. The nice thing about Vagrant is that this is a one-time download - this is a base image which is not affected by creating new Vagrant boxes.
Rather than downloading the image every time, it gets downloaded once and can then be cloned for each time you need to start a VM based on that image.What will also happen is that Vagrant will read the Vagrantfile and find that, aside from giving the VM 1GB of RAM, I have also provided a bash script to provision the instance, imaginatively named provision.sh.Once that's all finished (which might take quite a while), you'll be able to ssh into your instance and deploy to Payara, with a single, simple command:
vagrant ssh
Configuration
The provision script is where the magic happens.To begin with, variables are set. I've used the latest 4.1.152 (2015Q2) release of Payara, but changing the version to 4.1.151 will change the version used to the 2015Q1 release.I've included URLs to all the versions available on the Payara downloads page and the previous release too. To use the previous version, simply change the version number at line 9.Currently, the script installs the Web profile version. I chose that because it's probably the one that most people will want to use. If you need the full profile, then line 57 needs to be changed from:
wget -q $WEB -O temp.zip > /dev/null
to
wget -q $FULL -O temp.zip > /dev/null
If you want to use one of the embedded versions or Payara Micro, however, you will need to comment out (or delete) everything from line 61 down, since that section is where Payara is installed as a service.Once the provisioning script has run, and you've logged in to your running VM, you should be able to stop, start and restart Payara by calling:
service payara start payaradomain
Next Steps
As I said at the top of this post, this is a script intended to be helpful for development/testing purposes, so there are always improvements that can be made. For example, Dave Winters has already created a Dockerfile for Payara, and Vagrant can make use of Docker for provisioning, so that's something I'd like to add.I'm sure there are other things that people might like, so feel free to raise a Github issue or just submit a pull request.
Related Posts
Easy Jakarta EE Integration Testing with the Payara Platform and Testcontainers
Published on 24 Mar 2022
by Fabio Turizo
0 Comments
Payara Micro 5によるUber JARの作成
Published on 18 May 2021
by Fabio Turizo
0 Comments
Payara Microでは、Webアプリケーションを自己完結型で簡単に実行することができます。2016年5月のPayara Serverリリースからは、WARファイルの内容とPayara Microを構成するクラスやリソースを束ねる “Uber JAR” を作成する簡単な方法があります。
この “Uber” Jarは、Docker ...