Skip to content

Commit

Permalink
debug docker swarm creation - updating docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Michele Sciabarra committed Oct 19, 2017
1 parent 368007c commit cce3ff4
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 26 deletions.
21 changes: 19 additions & 2 deletions README.md
Expand Up @@ -8,14 +8,31 @@ A starter kit for building a Cloud in AWS
- Ansible for privisioning Docker and Jenkins
- SBT for building a collection of Docker images
- Ammonite Scripts for configuration and management
- Docker-Compose and Docker-Swarm for management

## Prerequisites

This stuff is unixish. So you need Mac or Linux. It may work on Windows bash, but no promises.

Get an AWS account, get Access and Secret keys and place in ~/.aws/credentials.

Something like:

```
[default]
aws_access_key_id = XXXXXXX
aws_secret_access_key = YYYYYYYY
```
Hint: go in the IAM Management Console, create an user and then in the Security Credentials, create an access key.

Then generate an ssh key in `~/.ssh/id_rsa` if you don't have it.
Hint: use `ssh-keygen`.

## Beginning

Start installing `sbt` then

```
cd ammonite
cd scripts
sbt
```

Expand Down
1 change: 1 addition & 0 deletions ansible/roles/jenkins/templates/Dockerfile
Expand Up @@ -14,4 +14,5 @@ RUN apt-get -y update && \
$(lsb_release -cs) \
stable"
RUN apt-get -y update && apt-get -y install docker-ce && adduser jenkins root && adduser jenkins docker
RUN groupadd -g 993 dockerce && adduser jenkins dockerce
USER jenkins
10 changes: 8 additions & 2 deletions ansible/roles/provision/tasks/docker.yml
Expand Up @@ -4,15 +4,21 @@
name: "firewalld"
state: absent

- name: add docker repo
shell: |
yum-config-manager --add-repo \
https://download.docker.com/linux/centos/docker-ce.repo \
&& yum update -y && touch /etc/yum-update.done
- name: install docker
yum:
name: docker
name: docker-ce
state: present

- name: adding user centos to docker group
user:
name: centos
groups: dockerroot
groups: docker
append: yes

- name: enabling docker
Expand Down
10 changes: 3 additions & 7 deletions deploy/docker-compose.yml
@@ -1,9 +1,7 @@
version: '3'
services:
spark-master:
hostname: spark-master
domainname: loc
image: library/spark:0.4-1
image: localhost:5000/spark:0.4-1
ports:
- "8082:8080"
networks:
Expand All @@ -19,9 +17,7 @@ services:
memory: "1g"

spark-worker:
hostname: spark-worker
domainname: loc
image: library/spark:0.4-1
image: localhost:5000/spark:0.4-1
links:
- "spark-master:spark-master.loc"
ports:
Expand All @@ -41,7 +37,7 @@ services:
memory: "2g"

zeppelin:
image: library/zeppelin:0.4-1
image: localhost:5000/zeppelin:0.4-1
ports:
- "8081:8080"
- "4040:4040"
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/scala/mosaico/config/HoconSettings.scala
Expand Up @@ -39,7 +39,7 @@ trait HoconSettings extends FileUtils with MiscUtils {
confName = s"${confPrefix}.${confExt}"
confFile = confDir / confName
} {
println(s"looking for ${confFile}")
//println(s"looking for ${confFile}")
if (confFile.exists) {
println(s"loading ${confFile.getName}")
conf = ConfigFactory.parseFile(confFile).withFallback(conf)
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions ammonite/aws.sc → scripts/aws.sc
Expand Up @@ -16,7 +16,7 @@ def doSsh(tag: (String,String), args: Seq[String]) {
Try(exec(args: _*))
}

@main def ssh(args: String*) = {
@main def awssh(args: String*) = {
if(args.head(0) == '@') {
args.head.tail.split(",").foreach {
host =>
Expand All @@ -36,7 +36,7 @@ def doSsh(tag: (String,String), args: Seq[String]) {
val tags = x.getTags.toList.map {
y => s"${y.getKey}=${y.getValue}"
}.mkString("[", ",", "]")
s"${tags}\t${x.getPublicIpAddress}\t${x.getPublicDnsName}\t${x.getState.getName}\t${x.getPrivateIpAddress}\t${x.getPrivateDnsName}"
s"${tags}\t${x.getState.getName}\t${x.getPublicIpAddress}\t${x.getPublicDnsName}\t${x.getPrivateIpAddress}\t${x.getPrivateDnsName}"
}
println(out.mkString("\n"))
}
Expand Down
10 changes: 3 additions & 7 deletions ammonite/build.sbt → scripts/build.sbt
@@ -1,4 +1,4 @@
val cloud = project in file(".")
val scripts = project in file(".")

enablePlugins(MosaicoAmmonitePlugin,MosaicoConfigPlugin)

Expand All @@ -7,14 +7,10 @@ ammPredef := Some("predef.sc")
prpLookup += baseDirectory.value.getParentFile -> "config"

addCommandAlias("aws", "amm aws.sc")

addCommandAlias("awssh", "amm aws.sc ssh")
addCommandAlias("awssh", "amm aws.sc awssh")

addCommandAlias("cmd", "amm cmd.sc")

addCommandAlias("terraform", "amm cmd.sc terraform")

addCommandAlias("ansible", "amm cmd.sc ansible")

addCommandAlias("jenkins", "amm cmd.sc jenkins")

addCommandAlias("docker", "amm cmd.sc docker")
11 changes: 7 additions & 4 deletions ammonite/cmd.sc → scripts/cmd.sc
Expand Up @@ -3,6 +3,8 @@ import scala.util.Try
import $file.lib.Cmd
import $exec.aws

val defaultUser = Option(sys.props("aws.ssh.user")).getOrElse("centos")

@main def ansible(args: String*) {
val inventory = sys.props("ansible.inventory")
val script = sys.props("ansible.script")
Expand All @@ -21,10 +23,11 @@ import $exec.aws
"sudo docker ps -f name=jenkins | awk '/jenkins/ { print $1 }'" +
"` cat /var/jenkins_home/secrets/initialAdminPassword"
println("Jenkins Initial Password")
ssh(command.split(" "): _*)
awssh(command.split(" "): _*)
}

@main def services() {
Cmd.services("centos", "docker-compose.yml")
ssh("@master")
@main def docker(args: String*) {
Cmd.copyCompose(defaultUser, "docker-compose.yml")
val args1 = "@master sudo docker".split(" ").toSeq++args
awssh(args1: _*)
}
2 changes: 1 addition & 1 deletion ammonite/lib/Cmd.sc → scripts/lib/Cmd.sc
Expand Up @@ -11,7 +11,7 @@ def terraform(args: Seq[String]) = {
%("terraform", if(args.size==0) Seq("apply") else args)(terraformDir)
}

def services(user: String, file: String) = {
def copyCompose(user: String, file: String) = {
val deployDir = pwd/up/'deploy
val master = EC2.ipAddresses(EC2.runningTaggedInstances("Name" -> "master")).head._2
val src = (deployDir/file).toIO.getAbsolutePath
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit cce3ff4

Please sign in to comment.