This guide is a step-by-step approach to developing, building and deploying a sample app with wercker within minutes.
While this guide uses PHP, the general concepts explained in this tutorial apply to every other programming language.
To be able to follow along with this guide, you will need the following things:
For this demo, we will be using Java Spring to create a simple web page that shows a counter which displays how many times the site has been visited. We will use Redis as a backend to save this data.
Before we can start developing, we have to fork and clone the sample
app into our local development
environment. After you've done that, cd
into the project directory.
$ cd getting-started-java/
Now that we've setup our app we can start developing. Let's start by taking a closer look at the wercker.yml file included in your project folder.
The wercker.yml is the only config file you need for using wercker. In it, you will define all your steps needed to successfully develop, build and deploy your application.
To get started however, we're only interested in developing our app, so
let's take a closer look at this dev
pipeline right now.
# The container definition we want to use for developing our app
box: combient/java-mvn
# Defining the development pipeline
dev:
services:
- id: redis
steps:
- script:
code: export PORT='8082'
- script:
code: 'mvn package'
- script:
code: 'mvn spring-boot:run'
The first line specifies which container image you want to use for your project. Since we're developing with Java, we've already specified a Java image for you. These container images are retrieved from Docker Hub if no other registry is specified. You can read more about containers here.
In the dev
clause we define what we want to happen in our development
pipeline. First we describe which service we will be using alongside
our main container, which in our case is Redis. We won't expand too much into how services
work here, but you can read more on our devcenter.
In the steps
section we describe which actions we want to take before we're ready
Let's see these steps in action now and fire up our dev pipeline.
In your project folder, run wercker dev --publish 8080
. You should end up
with input similar to this:
(...)
mapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-02-22 15:50:33.508 INFO 111 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-02-22 15:50:33.643 INFO 111 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-02-22 15:50:33.657 INFO 111 --- [ main] resources.HelloResource : Started HelloResource in 8.721 seconds (JVM running for 16.642)
2016-02-22 15:55:20.314 INFO 111 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2016-02-22 15:55:20.314 INFO 111 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2016-02-22 15:55:20.336 INFO 111 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 22 ms
Connecting to redis at host 'redis'
Wercker first checks out your code and then sets up the container environment. This means that the container will be pulled from Docker Hub and subsequently started with access to your checked out code. It will then start executing all the steps that are defined in the wercker.yml.
Please note that the IP displayed here could be different for you, as this
tutorial was written using docker-machine
.