Skip to content

Commit

Permalink
Fb cdpipeline, fixes #10 (#11)
Browse files Browse the repository at this point in the history
* First version of the build pipeline

* Fix problem in docker script to start tests

* Remove checkout

* Fix typo in docker run script

* Working jenkins pipeline with instructions
  • Loading branch information
wasadigi authored Apr 6, 2017
1 parent ee59133 commit 55336ed
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 5 deletions.
29 changes: 29 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
pipeline {
agent any
stages {
stage('Build') {
steps {
dir (path: "./docker-images/oa-java-server/") {
sh './build-docker-image.sh'
}
}
}
stage('Redeploy') {
steps {
dir (path: "./docker-topologies/runtime/") {
echo "current directory is: ${pwd()}"
sh 'docker-compose down --volumes'
sh 'docker-compose up -d'
}
}
}
stage('API tests') {
steps {
dir (path: "./docker-images/oa-server-specs/") {
sh './build-docker-image.sh'
sh './run-docker-image.sh'
}
}
}
}
}
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,23 @@ You can edit this file with the Swagger Editor, which you can run with Docker. T
docker run -p 28080:8080 swaggerapi/swagger-editor
```

## How do I build, validate and deploy the server?

## How do I run the server?
Since version 0.1.3, we provide a CI/CD pipeline for the server, directly in this repo. The pipeline is built on top of Jenkins and Docker. The following process allows you to start the CI/CD server, to build the code, to run API tests and to have a running server on your machine:

1. Start the CI/CD server
* `cd docker-topologies/cdpipeline/`
* `docker-compose up`
* wait until jenkins has fully started
* Open a web browser on [http://localhost:1080](http://localhost:1080) or [http://192.168.99.100:1080](http://192.168.99.100:1080) (depending on your Docker configuration and whether you use docker machine or not)
* Start the **build, validate and deploy open affect server** job
* Check the results in the jenkins UI
2. At the end of the process, you should have a running docker topology
* Open a web browser on [http://localhost:8080/api](http://localhost:8080/api) or [http://192.168.99.100:8080/api](http://192.168.99.100:8080/api) (depending on your Docker configuration and whether you use docker machine or not)

## Legacy instructions (prior to version 0.1.3)

### How do I run the server?

1. Build the docker image
* `cd docker-images/oa-java-server/`
Expand All @@ -33,18 +48,18 @@ docker run -p 28080:8080 swaggerapi/swagger-editor
* Open a web browser on [http://localhost:8080/api](http://localhost:8080/api) or [http://192.168.99.100:8080/api](http://192.168.99.100:8080/api) (depending on your Docker configuration and whether you use docker machine or not)


## How do I send API requests to the server?
### How do I send API requests to the server?

In the current version, there is a single end-point: `/measures`, which supports `POST` and `GET` methods. The first method is used to create a measure, the second one is used to retrieve the list of all measures stored on the server.

An example is provided in the form of a PostMan collection, available in `examples/OpenAffectAPI.postman_collection`. The example shows how to report a measure, which captures the fact that a person has expressed an emotion about a particular issue on GitHub.


## Is there an executable specification for the server?
### Is there an executable specification for the server?

Yes, since release 0.1.1. We use [Cucumber-JVM](https://cucumber.io/docs/reference/jvm) to specify the expected behaviour of the REST API implementation. We have a separate maven project for that, in the `./microservices/oa-server-specs` directory. The build process of that project also uses the Swagger API specification to generate client stubs. The features are described in Gherkin feature files in the `./microservices/oa-server-specs/src/test/resources/scenarios` directory.

## How do I run the executable specification?
### How do I run the executable specification?

1. Start the docker topology, as explained before.
2. Build the docker image that encapsulates the executable specification
Expand Down
44 changes: 44 additions & 0 deletions docker-images/jenkins/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
FROM jenkins:2.46.1-alpine


#
# Running jenkins as root (instead as jenkins) is not recommended for a regular CD server. However,
# it solves a couple of issues and enables a smooth out-of-the-box experience for this repo. One of the
# issues is that ADDing a directory to a VOLUME uses the uid/gid on the host (it does not use the USER
# value into account). This means that the standard jenkins image will cause access rights problems at
# container startup time. Another issue is that when jenkins is not run as root, then the user has to
# enter a randomly generated password the first time it connects to the UI. He also sees the setup wizard,
# which we want to avoid here since we install the plugins ourselves.
#
USER root

#
# Install docker and docker-compose. Note that on alpine, we may be behind latest releases... See bottom of
# this file to build an image with the latest version on a another linux distribution.
#
RUN apk update && apk add docker make py-pip shadow && pip install docker-compose
RUN usermod -aG users jenkins

#
# Add initial jenkins configuration. This is how jenkins knows about our job. If we were accessing a private
# git repo, we would also setup credentials and keys via this process.
#
ADD config/jenkins_home /var/jenkins_home/

#
# Install plugins that we want to use
#
RUN /usr/local/bin/install-plugins.sh nodejs workflow-aggregator pipeline-stage-view blueocean


#FROM jenkins:2.32.3
#
# Install Docker
#
#USER root
#RUN curl -fsSL https://get.docker.com/ | sh
#RUN usermod -aG docker jenkins
#RUN curl -L https://github.com/docker/compose/releases/download/1.11.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
#RUN chmod +x /usr/local/bin/docker-compose
#RUN usermod -aG users jenkins
#USER jenkins
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version='1.0' encoding='UTF-8'?>
<flow-definition plugin="[email protected]">
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties>
<org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
<triggers/>
</org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
</properties>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="[email protected]">
<scm class="hudson.plugins.git.GitSCM" plugin="[email protected]">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url>https://github.com/openaffect/openaffect-server</url>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>*/fb-cdpipeline</name>
</hudson.plugins.git.BranchSpec>
</branches>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<submoduleCfg class="list"/>
<extensions/>
</scm>
<scriptPath>./Jenkinsfile</scriptPath>
<lightweight>true</lightweight>
</definition>
<triggers/>
</flow-definition>
2 changes: 1 addition & 1 deletion docker-images/oa-server-specs/run-docker-image.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
docker run -it -v ~/.m2:/root/.m2 --net runtime_default openaffect/server-specs
docker run --rm -v ~/.m2:/root/.m2 --net runtime_default openaffect/server-specs
12 changes: 12 additions & 0 deletions docker-topologies/cdpipeline/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '2'
services:
jenkins:
build: ../../docker-images/jenkins
ports:
- "1080:8080"
volumes:
- jenkins-data:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
volumes:
jenkins-data:

0 comments on commit 55336ed

Please sign in to comment.