Skip to content
This repository has been archived by the owner on Jun 22, 2018. It is now read-only.

Commit

Permalink
Moving to consul-server:0.6-1; printing out MINIMESOS_NETWORK_GATEWAY
Browse files Browse the repository at this point in the history
  • Loading branch information
sadovnikov committed May 2, 2016
1 parent a32e23c commit b11a362
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ install:
- sudo apt-key update
- sudo apt-get -qqy install docker-engine=1.9.1-0~precise
# Has to run this script with sudo because custom installation does not allow $USER to use docker and it's not possible to relogin
- chmod +x pull-containers.sh && sudo ./pull-containers.sh
- make deps

# Has to run the build script with sudo because custom installation does not allow $USER to use docker and it's not possible to relogin
script: chmod +x travis.sh && sudo ./travis.sh
Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ setup:
sudo route delete 172.17.0.0/16; sudo route -n add 172.17.0.0/16 $(shell docker-machine ip ${shell DOCKER_MACHINE_NAME})

deps:
docker pull alpine:3.3
docker pull jplock/zookeeper:3.4.6
docker pull containersol/mesos-master:0.25.0-0.2.70.ubuntu1404
docker pull containersol/mesos-agent:0.25.0-0.2.70.ubuntu1404
docker pull mesosphere/marathon:v0.13.0
docker pull tutum/hello-world
docker pull containersol/consul-server:0.6
docker pull gliderlabs/registrator:v6
docker pull containersol/mesos-agent:0.25.0-0.2.70.ubuntu1404
docker pull containersol/mesos-master:0.25.0-0.2.70.ubuntu1404
docker pull gliderlabs/registrator:v6
docker pull containersol/consul-server:0.6-1
docker pull mesosphere/marathon:v0.15.3
docker pull jplock/zookeeper:3.4.6
docker pull containersol/alpine3.3-java8-jre:v1
docker pull tutum/hello-world:latest

clean:
./gradlew clean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package com.containersol.minimesos.config;
public class ConsulConfig extends ContainerConfigBlock implements ContainerConfig {

public static final String CONSUL_IMAGE_NAME = "containersol/consul-server"
public static final String CONSUL_TAG_NAME = "0.6"
public static final String CONSUL_TAG_NAME = "0.6-1"

public static final int CONSUL_HTTP_PORT = 8500
public static final int CONSUL_DNS_PORT = 8600
public static final int CONSUL_DNS_PORT = 53

public ConsulConfig() {
imageName = CONSUL_IMAGE_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class MesosCluster {
public static final String MINIMESOS_HOST_DIR_PROPERTY = "minimesos.host.dir";
public static final String MINIMESOS_TOKEN_PREFIX = "MINIMESOS_";

public static final String TOKEN_NETWORK_GATEWAY = MINIMESOS_TOKEN_PREFIX + "NETWORK_GATEWAY";

private String clusterId;

private final ClusterConfig clusterConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.containersol.minimesos.cluster.ClusterRepository;
import com.containersol.minimesos.cluster.ClusterUtil;
import com.containersol.minimesos.cluster.MesosCluster;
import com.containersol.minimesos.docker.DockerContainersUtil;
import com.containersol.minimesos.mesos.MesosClusterContainersFactory;

import java.io.PrintStream;
Expand Down Expand Up @@ -49,8 +50,12 @@ public void execute() {
*/
private void printServiceUrls(MesosCluster cluster) {

List<ClusterProcess> uniqueMembers = ClusterUtil.getDistinctRoleProcesses(cluster.getMemberProcesses());
// print independent from roles variables
String masterContainer = cluster.getMaster().getContainerId();
String gateway = String.format("export %s=%s", MesosCluster.TOKEN_NETWORK_GATEWAY, DockerContainersUtil.getGatewayIpAddress(masterContainer));
output.println(gateway);

List<ClusterProcess> uniqueMembers = ClusterUtil.getDistinctRoleProcesses(cluster.getMemberProcesses());
for (ClusterProcess process : uniqueMembers) {

URI serviceUrl = process.getServiceUrl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class MarathonContainer extends AbstractContainer implements Marathon {

private static final Logger LOGGER = LoggerFactory.getLogger(MarathonContainer.class);

private static final String TOKEN_NETWORK_GATEWAY = "NETWORK_GATEWAY";
private static final String TOKEN_HOST_DIR = "MINIMESOS_HOST_DIR";

private static final String END_POINT_EXT = "/v2/apps";
private static final String HEADER_ACCEPT = "accept";
Expand Down Expand Up @@ -126,8 +126,9 @@ public void deployApp(String marathonJson) {
* @return updated string
*/
public String replaceTokens(String source) {
MesosCluster cluster = getCluster();
// received JSON might contain tokens, which should be replaced before the installation
List<ClusterProcess> uniqueRoles = ClusterUtil.getDistinctRoleProcesses(getCluster().getMemberProcesses());
List<ClusterProcess> uniqueRoles = ClusterUtil.getDistinctRoleProcesses(cluster.getMemberProcesses());
String updatedJson = source;
for (ClusterProcess process : uniqueRoles) {
URI serviceUri = process.getServiceUrl();
Expand All @@ -139,7 +140,9 @@ public String replaceTokens(String source) {
}

// replace independent from roles tokens
updatedJson = replaceToken(updatedJson, TOKEN_NETWORK_GATEWAY, DockerContainersUtil.getGatewayIpAddress(getCluster().getMaster().getContainerId()));
String masterContainer = cluster.getMaster().getContainerId();
updatedJson = replaceToken(updatedJson, MesosCluster.TOKEN_NETWORK_GATEWAY, DockerContainersUtil.getGatewayIpAddress(masterContainer));
updatedJson = replaceToken(updatedJson, TOKEN_HOST_DIR, MesosCluster.getHostDir().getAbsolutePath());

return updatedJson;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import com.containersol.minimesos.config.ConsulConfig;
import com.containersol.minimesos.container.AbstractContainer;
import com.containersol.minimesos.docker.DockerClientFactory;
import com.containersol.minimesos.docker.DockerContainersUtil;
import com.github.dockerjava.api.command.CreateContainerCmd;
import com.github.dockerjava.api.model.ExposedPort;
import com.github.dockerjava.api.model.Ports;

import static com.containersol.minimesos.util.EnvironmentBuilder.newEnvironment;

Expand All @@ -17,7 +15,6 @@
*/
public class ConsulContainer extends AbstractContainer implements Consul {

public static final int DNS_PORT = 53;
private final ConsulConfig config;

public ConsulContainer(ConsulConfig config) {
Expand Down Expand Up @@ -49,17 +46,8 @@ protected CreateContainerCmd dockerCommand() {
ExposedPort consulHTTPPort = ExposedPort.tcp(ConsulConfig.CONSUL_HTTP_PORT);
ExposedPort consulDNSPort = ExposedPort.udp(ConsulConfig.CONSUL_DNS_PORT);

Ports portBindings = new Ports();
if (getCluster().isExposedHostPorts()) {
portBindings.bind(consulHTTPPort, new Ports.Binding(ConsulConfig.CONSUL_HTTP_PORT));
}

String gatewayIpAddress = DockerContainersUtil.getGatewayIpAddress(getCluster().getMaster().getContainerId());
portBindings.bind(consulDNSPort, new Ports.Binding(gatewayIpAddress, DNS_PORT));

return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag())
.withName(getName())
.withPortBindings(portBindings)
.withEnv(newEnvironment()
.withValue("SERVICE_IGNORE", "1")
.createEnvironment())
Expand Down
10 changes: 0 additions & 10 deletions pull-containers.sh

This file was deleted.

0 comments on commit b11a362

Please sign in to comment.