Skip to content
Closed
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
40 changes: 36 additions & 4 deletions docker-1/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
MTN.*NIX.11 Automated Environment Configuration Management
---

***Student***: Put_Your_Name
***Student***: Andrei Konchyts

Home Task
---

Using base docker image ***sbeliakou/centos:7.2***

1. Wiht ```Dockerfiles```:
- Create Docker Image of ```nginx``` ([web.Dockerfile](/web.Dockerfile))
- Create Docker Image of ```Tomcat 7``` ([tomcat.Dockerfile](/tomcat.Dockerfile))
- Create Docker Image of ```nginx``` ([web.Dockerfile](web.Dockerfile))
- Create Docker Image of ```Tomcat 7``` ([tomcat.Dockerfile](tomcat.Dockerfile))
- Create Docker Image (Data Volume) with [```hello world```](https://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/sample.war) application for Tomcat ([application.Dockerfile](application.Dockerfile))
- Run these Images so that [http://localhost/sample](http://localhost/sample) shows ```hello world``` page
- ```Nginx``` container forwards http requests to ```Tomcat``` container; Only ```nginx``` container exposes port (80)
Expand All @@ -23,4 +23,36 @@ Using base docker image ***sbeliakou/centos:7.2***

Task Report Notes
---
*All stuff must be provided in this section
### **1.** With Dockerfiles:
* Building Docker Image of ```nginx``` ([web.Dockerfile](web.Dockerfile)):
*$ docker build -t nginx -f web.Dockerfile .*
<img src="resources/3.png">

* Building Docker Image of ```Tomcat 7``` ([tomcat.Dockerfile](tomcat.Dockerfile)):
*$ docker build -t tomcat -f tomcat.Dockerfile .*
<img src="resources/2.png">

* Building Docker Image of ```application``` for Tomcat ([application.Dockerfile](application.Dockerfile)):
*$ docker build -t app -f application.Dockerfile .*
<img src="resources/1.png">

* Running these images:
*$ docker run -d --name myapp app*
*$ docker run -d --volumes-from myapp --name mytomcat tomcat*
*$ docker run --name mynginx --link mytomcat:tomcat -d -p 80:80 nginx*
<img src="resources/4.png">

* Check the result:
<img src="resources/5.png">

### **2.** With docker-compose ([docker-compose.yml](docker-compose.yml)):

* Build containers from previos task:
*$ docker-compose up -d*
<img src="resources/6.png">

<img src="resources/7.png">

* Check the result:
<img src="resources/8.png">

5 changes: 5 additions & 0 deletions docker-1/application.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM sbeliakou/centos:7.2
MAINTAINER Andrei Konchyts (andrei_konchyts@epam.com)
VOLUME /var/lib/tomcat/webapps
COPY resources/sample.war /var/lib/tomcat/webapps/
CMD sleep infinity
24 changes: 24 additions & 0 deletions docker-1/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '2'
services:
app:
build:
context: .
dockerfile: application.Dockerfile
tomcat:
build:
context: .
dockerfile: tomcat.Dockerfile
depends_on:
- app
volumes_from:
- app
nginx:
build:
context: .
dockerfile: web.Dockerfile
depends_on:
- tomcat
ports:
- "80:80"
links:
- "tomcat:tomcat"
Binary file added docker-1/resources/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-1/resources/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-1/resources/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-1/resources/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-1/resources/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-1/resources/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-1/resources/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-1/resources/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-1/resources/sample.war
Binary file not shown.
10 changes: 10 additions & 0 deletions docker-1/resources/tomcat.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
server {
listen 80;
server_name localhost;
location / {
sendfile off;
proxy_pass http://tomcat:8080;
proxy_redirect default;
proxy_http_version 1.1;
}
}
4 changes: 4 additions & 0 deletions docker-1/tomcat.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM sbeliakou/centos:7.2
MAINTAINER Andrei Konchyts (andrei_konchyts@epam.com)
RUN yum install tomcat tomcat-webapps -y; yum clean all
CMD /usr/libexec/tomcat/server start
6 changes: 6 additions & 0 deletions docker-1/web.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM sbeliakou/centos:7.2
MAINTAINER Andrei Konchyts (andrei_konchyts@epam.com)
RUN yum install nginx -y
COPY resources/tomcat.conf /etc/nginx/conf.d/
EXPOSE 80
CMD nginx -g 'daemon off;'
17 changes: 17 additions & 0 deletions docker-2/JenkinsfileBuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
node('Docker Host') {
stage('Preparation (Checking out)') {
git branch: "akonchyts_docker2", url: 'https://github.com/akonchyts/docker.git'
}
stage ('Building Gradle Image'){
docker.build('gradle', '-f docker-2/gradle.Dockerfile .')
}
stage('Building application') {
docker.image('gradle').inside {
sh 'gradle -b docker-2/resources/spring-boot/build.gradle build'
}
}
stage ('Archiving artifact') {
sh 'cp docker-2/resources/spring-boot/build/libs/gs-spring-boot-0.1.0.jar .'
archive('gs-spring-boot-0.1.0.jar')
}
}
23 changes: 23 additions & 0 deletions docker-2/JenkinsfileDeploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
node('Docker Host') {
def job = 'Build_Spring-Boot_APP_Docker-Gradle-Image'
def art = 'gs-spring-boot-0.1.0.jar'
stage('Preparation (Checking out)') {
git branch: "akonchyts_docker2", url: 'https://github.com/akonchyts/docker.git'
}
stage('Triggering job and fetching artifact') {
build job: "${job}"
step ([$class: 'CopyArtifact',
projectName: "${job}",
filter: "${art}"]);
sh "mv ${art} docker-2/"
}
stage ('Deploy application'){
sh 'docker-compose -f docker-2/docker-compose.yml up -d'
}
stage ('Check application'){
sh 'sleep 10'
sh 'curl http://localhost:8081'
sh 'docker-compose -f docker-2/docker-compose.yml stop'
sh 'docker-compose -f docker-2/docker-compose.yml rm -f deploy'
}
}
46 changes: 46 additions & 0 deletions docker-2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,49 @@ $ ansible-playbook playbook.yml

### Dockerized Zabbix
[Solution](https://www.zabbix.org/wiki/Dockerized_Zabbix)


Task Report Notes
---
### **1.** Launch Jenkins from [official image](https://hub.docker.com/_/jenkins/):
*$ docker run --name myjenkins -p 8080:8080 -p 50000:50000 -d -v /home/student/jenkins_home:/var/jenkins_home jenkins*
<img src="resources/1.png">

<img src="resources/14.png">

### **2.** Link Docker Host as Jenknis slave (ssh):
* Add Docker Host as node slave in Jinkins:
<img src="resources/2.png">

<img src="resources/3.png">

### **3.** Create custom gradle image:
* Create custom gradle image (see [gradle.Dockerfile](gradle.Dockerfile)):
<img src="resources/15.png">

### **4.** Configure a job to build [spring-boot application](https://spring.io/guides/gs/spring-boot/) using gradle image buit on previous step:
* Create pipeline job "Build_Spring-Boot_APP_Docker-Gradle-Image" as downstream job to just build an application (see [JenkinsfileBuild](JenkinsfileBuild)):
<img src="resources/5.png">

### **5.** Configure a job to run just built Spring Boot app with docker-compose:
* Create pipeline job "Deploy_Spring-Boot_APP_Docker-Compose" as upstream job to run the downstream job "Build_Spring-Boot_APP_Docker-Gradle-Image" to fetch the artifact to deploy it and check it (see [JenkinsfileDeploy](JenkinsfileDeploy)):
<img src="resources/4.png">

* See the result of the upstream job:
<img src="resources/7.png">

<img src="resources/8.png">

<img src="resources/9.png">

* See the result of the downstream job:
<img src="resources/10.png">

<img src="resources/11.png">

<img src="resources/12.png">

<img src="resources/13.png">

* See the result of deployment:
<img src="resources/6.png">
10 changes: 10 additions & 0 deletions docker-2/deploy.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM sbeliakou/centos:7.2
MAINTAINER Andrei Konchyts (andrei_konchyts@epam.com)

RUN yum install java-1.8.0-openjdk -y; yum clean all && \
mkdir /opt/app
COPY gs-spring-boot-0.1.0.jar /opt/app/

EXPOSE 8080

CMD java -jar /opt/app/gs-spring-boot-0.1.0.jar
8 changes: 8 additions & 0 deletions docker-2/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '2'
services:
deploy:
build:
context: .
dockerfile: deploy.Dockerfile
ports:
- "8081:8080"
15 changes: 15 additions & 0 deletions docker-2/gradle.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM sbeliakou/centos:7.2
MAINTAINER Andrei Konchyts (andrei_konchyts@epam.com)

ENV GRADLE_HOME /opt/gradle
ENV GRADLE_VERSION 4.0.2
ENV JAVA_HOME /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64

RUN yum install java-1.8.0-openjdk-devel wget unzip -y; yum clean all && \
wget --no-verbose --output-document=gradle.zip "https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip" && \
unzip gradle.zip && \
rm gradle.zip && \
mv "gradle-${GRADLE_VERSION}" "${GRADLE_HOME}/" && \
ln -s "${GRADLE_HOME}/bin/gradle" /usr/bin/gradle

CMD gradle
Binary file added docker-2/resources/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-2/resources/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-2/resources/11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-2/resources/12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-2/resources/13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-2/resources/14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-2/resources/15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-2/resources/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-2/resources/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-2/resources/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-2/resources/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-2/resources/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-2/resources/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-2/resources/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docker-2/resources/9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions docker-2/resources/spring-boot/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.6.RELEASE")
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'

jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}

repositories {
mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// end::actuator[]
// tag::tests[]
testCompile("org.springframework.boot:spring-boot-starter-test")
// end::tests[]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package hello;

import java.util.Arrays;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {

System.out.println("Let's inspect the beans provided by Spring Boot:");

String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}

};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package hello;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

@RestController
public class HelloController {

@RequestMapping("/")
public String index() {
return "Greetings from Spring Boot!";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package hello;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.net.URL;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class HelloControllerIT {

@LocalServerPort
private int port;

private URL base;

@Autowired
private TestRestTemplate template;

@Before
public void setUp() throws Exception {
this.base = new URL("http://localhost:" + port + "/");
}

@Test
public void getHello() throws Exception {
ResponseEntity<String> response = template.getForEntity(base.toString(),
String.class);
assertThat(response.getBody(), equalTo("Greetings from Spring Boot!"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package hello;

import static org.hamcrest.Matchers.equalTo;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class HelloControllerTest {

@Autowired
private MockMvc mvc;

@Test
public void getHello() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().string(equalTo("Greetings from Spring Boot!")));
}
}