gocha124の日記

ごちゃごちゃ書きます

AWSでJenkinsをセットアップ(Dockerで)

Dockerをインストール。

[ec2-user@ip-172-31-39-109 ~]$ sudo yum install -y docker
[ec2-user@ip-172-31-39-109 ~]$ sudo service docker start
Starting cgconfig service:                                 [  OK  ]
Starting docker:	.                                  [  OK  ]
[ec2-user@ip-172-31-39-109 ~]$ sudo usermod -a -G docker ec2-user
[ec2-user@ip-172-31-39-109 lib]$ sudo service docker start
[ec2-user@ip-172-31-39-109 lib]$ sudo chkconfig docker on


公式手順に乗っ取ってdocker composeをインストール。
Install Docker Compose | Docker Documentation

[ec2-user@ip-172-31-39-109 lib]$ sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
[ec2-user@ip-172-31-39-109 lib]$ sudo chmod +x /usr/local/bin/docker-compose
[ec2-user@ip-172-31-39-109 lib]$ docker-compose --version
docker-compose version 1.23.2, build 1110ad01

DockerのHelloWorld

[ec2-user@ip-172-31-39-109 ~]$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

Dockerのpsコマンド

[ec2-user@ip-172-31-39-109 ~]$ docker ps

JenkinsのDockderイメージをダウンロード

[ec2-user@ip-172-31-39-109 ~]$ docker pull jenkinsci/jenkins
Using default tag: latest
latest: Pulling from jenkinsci/jenkins
bc9ab73e5b14: Pull complete 
193a6306c92a: Pull complete 
e5c3f8c317dc: Pull complete 
省略
fe19092ec048: Pull complete 
283ce97c8511: Pull complete 
Digest: sha256:3a2753dff50a530c6111f9166e822e49ff108ca076bbbce5026ba0ce80b64044
Status: Downloaded newer image for jenkinsci/jenkins:latest

Jenkinsを起動する

[ec2-user@ip-172-31-39-109 /]$ docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
Apr 03, 2019 3:15:46 PM org.eclipse.jetty.util.log.Log initialized
INFO: Logging initialized @614ms to org.eclipse.jetty.util.log.JavaUtilLog
Apr 03, 2019 3:15:46 PM winstone.Logger logInternal
INFO: Beginning extraction from war file
Apr 03, 2019 3:15:46 PM org.eclipse.jetty.server.handler.ContextHandler setContextPath
WARNING: Empty contextPath
Apr 03, 2019 3:15:46 PM org.eclipse.jetty.server.Server doStart
INFO: jetty-9.4.z-SNAPSHOT; built: 2018-08-30T13:59:14.071Z; git: 27208684755d94a92186989f695db2d7b21ebc51; jvm 1.8.0_181-8u181-b13-2~deb9u1-b13
Apr 03, 2019 3:15:47 PM org.eclipse.jetty.webapp.StandardDescriptorProcessor visitServlet
INFO: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
Apr 03, 2019 3:15:47 PM org.eclipse.jetty.server.session.DefaultSessionIdManager doStart
INFO: DefaultSessionIdManager workerName=node0
Apr 03, 2019 3:15:47 PM org.eclipse.jetty.server.session.DefaultSessionIdManager doStart
INFO: No SessionScavenger set, using defaults
Apr 03, 2019 3:15:47 PM org.eclipse.jetty.server.session.HouseKeeper startScavenging
INFO: node0 Scavenging every 660000ms
Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
Apr 03, 2019 3:15:48 PM org.eclipse.jetty.server.handler.ContextHandler doStart
INFO: Started w.@3bcd05cb{Jenkins v2.164.1,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
Apr 03, 2019 3:15:48 PM org.eclipse.jetty.server.AbstractConnector doStart
INFO: Started ServerConnector@38210c50{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
Apr 03, 2019 3:15:48 PM org.eclipse.jetty.server.Server doStart
INFO: Started @2540ms
Apr 03, 2019 3:15:48 PM winstone.Logger logInternal
INFO: Winstone Servlet Engine v4.0 running: controlPort=disabled
Apr 03, 2019 3:15:49 PM jenkins.InitReactorRunner$1 onAttained
INFO: Started initialization
Apr 03, 2019 3:15:49 PM jenkins.InitReactorRunner$1 onAttained
INFO: Listed all plugins
Apr 03, 2019 3:15:59 PM jenkins.InitReactorRunner$1 onAttained
INFO: Prepared all plugins
Apr 03, 2019 3:15:59 PM jenkins.InitReactorRunner$1 onAttained
INFO: Started all plugins
Apr 03, 2019 3:16:02 PM hudson.ExtensionFinder$GuiceFinder$FaultTolerantScope$1 error
INFO: Failed to instantiate optional component hudson.plugins.build_timeout.operations.AbortAndRestartOperation$DescriptorImpl; skipping
Apr 03, 2019 3:16:02 PM jenkins.InitReactorRunner$1 onAttained
INFO: Augmented all extensions
Apr 03, 2019 3:16:02 PM jenkins.InitReactorRunner$1 onAttained
INFO: Loaded all jobs
Apr 03, 2019 3:16:02 PM hudson.model.AsyncPeriodicWork$1 run
INFO: Started Download metadata
Apr 03, 2019 3:16:02 PM jenkins.util.groovy.GroovyHookScript execute
INFO: Executing /var/jenkins_home/init.groovy.d/tcp-slave-agent-port.groovy
Apr 03, 2019 3:16:02 PM hudson.util.Retrier start
INFO: Attempt #1 to do the action check updates server
Apr 03, 2019 3:16:03 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@3d150dd7: display name [Root WebApplicationContext]; startup date [Wed Apr 03 15:16:03 UTC 2019]; root of context hierarchy
Apr 03, 2019 3:16:03 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@3d150dd7]: org.springframework.beans.factory.support.DefaultListableBeanFactory@27d0bc60
Apr 03, 2019 3:16:03 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@27d0bc60: defining beans [authenticationManager]; root of factory hierarchy
Apr 03, 2019 3:16:04 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@1d0e796a: display name [Root WebApplicationContext]; startup date [Wed Apr 03 15:16:04 UTC 2019]; root of context hierarchy
Apr 03, 2019 3:16:04 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@1d0e796a]: org.springframework.beans.factory.support.DefaultListableBeanFactory@3c5849b9
Apr 03, 2019 3:16:04 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3c5849b9: defining beans [filter,legacy]; root of factory hierarchy
Apr 03, 2019 3:16:04 PM jenkins.InitReactorRunner$1 onAttained
INFO: Completed initialization
Apr 03, 2019 3:16:04 PM hudson.WebAppMain$3 run
INFO: Jenkins is fully up and running
--> setting agent port for jnlp
--> setting agent port for jnlp... done
Apr 03, 2019 3:16:19 PM hudson.model.UpdateSite updateData
INFO: Obtained the latest update center data file for UpdateSource default
Apr 03, 2019 3:16:20 PM hudson.model.DownloadService$Downloadable load
INFO: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
Apr 03, 2019 3:16:21 PM hudson.model.DownloadService$Downloadable load
INFO: Obtained the updated data file for hudson.tasks.Ant.AntInstaller
Apr 03, 2019 3:16:21 PM hudson.model.DownloadService$Downloadable load
INFO: Obtained the updated data file for hudson.plugins.gradle.GradleInstaller
Apr 03, 2019 3:16:23 PM hudson.model.DownloadService$Downloadable load
INFO: Obtained the updated data file for hudson.tools.JDKInstaller
Apr 03, 2019 3:16:23 PM hudson.util.Retrier start
INFO: Performed the action check updates server successfully at the attempt #1
Apr 03, 2019 3:16:23 PM hudson.model.AsyncPeriodicWork$1 run
INFO: Finished Download metadata. 20,136 ms


できた
次はJenkinsとGitHub連携をためす

参考URL
Amazon Linux2にDockerをインストールする - Qiita
Amazon Linuxで nginx + php7 環境構築 | // sakura note
Dockerインストールメモ - Qiita