Browse Source

move docker run scripts to resources. allow fork without name. more docker fixes.

tags/v1.5.4
Jonathan Cobb 4 years ago
parent
commit
6bb72e1dd3
19 changed files with 102 additions and 20 deletions
  1. +3
    -3
      Dockerfile
  2. +3
    -3
      Dockerfile.slim
  3. +2
    -2
      bubble-server/pom.xml
  4. +3
    -0
      bubble-server/src/main/java/bubble/cloud/compute/ComputeServiceDriver.java
  5. +39
    -5
      bubble-server/src/main/java/bubble/cloud/compute/docker/DockerComputeDriver.java
  6. +1
    -1
      bubble-server/src/main/java/bubble/model/bill/AccountPlan.java
  7. +1
    -1
      bubble-server/src/main/java/bubble/resources/bill/AccountPlansResource.java
  8. +3
    -0
      bubble-server/src/main/java/bubble/service/packer/PackerJob.java
  9. +1
    -1
      bubble-server/src/main/resources/META-INF/bubble/bubble.properties
  10. +0
    -0
      bubble-server/src/main/resources/docker/run_bubble.sh
  11. +0
    -0
      bubble-server/src/main/resources/docker/run_bubble_slim.sh
  12. +0
    -0
      bubble-server/src/main/resources/docker/run_postgresql.sh
  13. +0
    -0
      bubble-server/src/main/resources/docker/run_redis.sh
  14. +3
    -0
      bubble-server/src/main/resources/docker/run_supervisor.sh
  15. +1
    -1
      bubble-server/src/main/resources/models/defaults/cloudService.json
  16. +39
    -0
      bubble-server/src/main/resources/packer/roles/common/tasks/docker.yml
  17. +1
    -1
      bubble-server/src/test/resources/models/system/cloudService.json
  18. +1
    -1
      pom.xml
  19. +1
    -1
      utils/pom.xml

+ 3
- 3
Dockerfile View File

@@ -29,7 +29,7 @@ RUN bash -c "sed -i -e 's/daemonize yes/daemonize no/g' /etc/redis/redis.conf"

# Setup redis service
RUN mkdir /etc/service/redis
COPY docker/run_redis.sh /etc/service/redis/run
COPY bubble-server/src/main/resources/docker/run_redis.sh /etc/service/redis/run

#################
### PostgreSQL
@@ -44,7 +44,7 @@ RUN bash -c "service postgresql start && sleep 5s && service postgresql status &

# Setup PostgreSQL service
RUN mkdir /etc/service/postgresql
COPY docker/run_postgresql.sh /etc/service/postgresql/run
COPY bubble-server/src/main/resources/docker/run_postgresql.sh /etc/service/postgresql/run

#################
### Bubble
@@ -60,7 +60,7 @@ COPY docker/bubble.env /bubble/bubble.env

# Setup Bubble service
RUN mkdir /etc/service/bubble
COPY docker/run_bubble.sh /etc/service/bubble/run
COPY bubble-server/src/main/resources/docker/run_bubble.sh /etc/service/bubble/run

#################
### Main stuff


+ 3
- 3
Dockerfile.slim View File

@@ -29,7 +29,7 @@ RUN bash -c "sed -i -e 's/daemonize yes/daemonize no/g' /etc/redis/redis.conf"

# Setup redis service
RUN mkdir /etc/service/redis
COPY docker/run_redis.sh /etc/service/redis/run
COPY bubble-server/src/main/resources/docker/run_redis.sh /etc/service/redis/run

#################
### PostgreSQL
@@ -44,7 +44,7 @@ RUN bash -c "service postgresql start && sleep 5s && service postgresql status &

# Setup PostgreSQL service
RUN mkdir /etc/service/postgresql
COPY docker/run_postgresql.sh /etc/service/postgresql/run
COPY bubble-server/src/main/resources/docker/run_postgresql.sh /etc/service/postgresql/run

#################
### Bubble
@@ -60,7 +60,7 @@ COPY docker/bubble.env /bubble/bubble.env

# Setup Bubble service
RUN mkdir /etc/service/bubble
COPY docker/run_bubble_slim.sh /etc/service/bubble/run
COPY bubble-server/src/main/resources/docker/run_bubble_slim.sh /etc/service/bubble/run

#################
### Main stuff


+ 2
- 2
bubble-server/pom.xml View File

@@ -11,12 +11,12 @@
<groupId>bubble</groupId>
<artifactId>bubble</artifactId>
<!-- @@BUBBLE_VERSION@@ this comment must remain above the version tag so that _set_version can update it -->
<version>1.4.51</version>
<version>1.4.52</version>
</parent>

<artifactId>bubble-server</artifactId>
<!-- @@BUBBLE_VERSION@@ this comment must remain above the version tag so that _set_version can update it -->
<version>1.4.51</version>
<version>1.4.52</version>

<repositories>
<repository>


+ 3
- 0
bubble-server/src/main/java/bubble/cloud/compute/ComputeServiceDriver.java View File

@@ -11,6 +11,7 @@ import bubble.model.cloud.AnsibleInstallType;
import bubble.model.cloud.BubbleNode;
import bubble.model.cloud.RegionalServiceDriver;
import bubble.service.packer.PackerBuild;
import org.cobbzilla.util.io.TempDir;
import org.cobbzilla.util.system.CommandResult;

import java.util.List;
@@ -66,4 +67,6 @@ public interface ComputeServiceDriver extends CloudServiceDriver, RegionalServic

default int getSshPort(BubbleNode node) { return 1202; }

default void prepPackerDir(TempDir tempDir) {}

}

+ 39
- 5
bubble-server/src/main/java/bubble/cloud/compute/docker/DockerComputeDriver.java View File

@@ -12,10 +12,7 @@ import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.CreateContainerCmd;
import com.github.dockerjava.api.command.CreateContainerResponse;
import com.github.dockerjava.api.command.InspectContainerResponse;
import com.github.dockerjava.api.model.Capability;
import com.github.dockerjava.api.model.Container;
import com.github.dockerjava.api.model.HostConfig;
import com.github.dockerjava.api.model.Image;
import com.github.dockerjava.api.model.*;
import com.github.dockerjava.core.DefaultDockerClientConfig;
import com.github.dockerjava.core.DockerClientConfig;
import com.github.dockerjava.core.DockerClientImpl;
@@ -23,20 +20,30 @@ import com.github.dockerjava.transport.DockerHttpClient;
import com.github.dockerjava.zerodep.ZerodepDockerHttpClient;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.cobbzilla.util.collection.ArrayUtil;
import org.cobbzilla.util.collection.MapBuilder;
import org.cobbzilla.util.io.TempDir;

import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static bubble.service.packer.PackerJob.PACKER_IMAGE_PREFIX;
import static com.github.dockerjava.api.model.InternetProtocol.UDP;
import static java.lang.Boolean.parseBoolean;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.cobbzilla.util.daemon.ZillaRuntime.*;
import static org.cobbzilla.util.io.FileUtil.abs;
import static org.cobbzilla.util.io.StreamUtil.loadResourceAsStream;
import static org.cobbzilla.util.io.StreamUtil.stream2file;
import static org.cobbzilla.util.json.JsonUtil.json;
import static org.cobbzilla.util.system.OsType.CURRENT_OS;
import static org.cobbzilla.util.system.OsType.linux;
@@ -56,6 +63,17 @@ public class DockerComputeDriver extends ComputeServiceDriverBase {
public static final List<ComputeNodeSize> CLOUD_SIZES = singletonList(LOCAL_SIZE);
public static final Map<String, ComputeNodeSize> NODE_SIZE_MAP = MapBuilder.build(LOCAL, LOCAL_SIZE);

public static final ExposedPort[] SAGE_EXPOSED_PORTS = {
new ExposedPort(22), new ExposedPort(80), new ExposedPort(443), new ExposedPort(1202)
};
public static final ExposedPort[] NODE_EXPOSED_PORTS = ArrayUtil.append(SAGE_EXPOSED_PORTS,
new ExposedPort(1080), new ExposedPort(1443),
new ExposedPort(8888), new ExposedPort(9999),
new ExposedPort(53, UDP),
new ExposedPort(500, UDP), new ExposedPort(4500, UDP),
new ExposedPort(51820, UDP)
);

@Override public Map<String, ComputeNodeSize> getSizesMap() { return NODE_SIZE_MAP; }

@Override public ComputeNodeSize getSize(ComputeNodeSizeType type) { return LOCAL_SIZE; }
@@ -119,6 +137,20 @@ public class DockerComputeDriver extends ComputeServiceDriverBase {
return DockerClientImpl.getInstance(dockerConfig, client);
}

private static final String[] PACKER_FILES = {"run_redis.sh", "run_postgresql.sh", "run_supervisor.sh"};

@Override public void prepPackerDir(TempDir tempDir) {
try {
for (String p : PACKER_FILES) {
final File destFile = new File(abs(tempDir) + "/roles/common/files/" + p);
if (!destFile.getParentFile().exists()) die("prepPackerDir: parent dir does not exist: "+abs(destFile.getParentFile()));
stream2file(loadResourceAsStream("docker/" + p), destFile);
}
} catch (Exception e) {
die("prepPackerDir: "+shortError(e), e);
}
}

@Override public BubbleNode cleanupStart(BubbleNode node) throws Exception { return node; }

@Override public BubbleNode start(BubbleNode node) throws Exception {
@@ -133,12 +165,14 @@ public class DockerComputeDriver extends ComputeServiceDriverBase {
final PackerImage packerImage = getOrCreatePackerImage(node);

final CreateContainerCmd ccr = dc.createContainerCmd(packerImage.getId())
.withExposedPorts(node.getInstallType() == AnsibleInstallType.sage ? SAGE_EXPOSED_PORTS : NODE_EXPOSED_PORTS)
.withLabels(MapBuilder.build(new String[][] {
{LABEL_CLOUD, cloud.getUuid()},
{LABEL_NODE, node.getUuid()}
}))
.withHostConfig(HostConfig.newHostConfig()
.withCapAdd(Capability.NET_ADMIN)
.withCapAdd(Capability.SYS_MODULE)
.withCapAdd(Capability.SYS_ADMIN));
final CreateContainerResponse response = ccr.exec();
final long start = now();


+ 1
- 1
bubble-server/src/main/java/bubble/model/bill/AccountPlan.java View File

@@ -202,7 +202,7 @@ public class AccountPlan extends IdentifiableBase implements HasNetwork {
.setFootprint(getFootprint())
.setComputeSizeType(plan.getComputeSizeType())
.setStorage(storage.getUuid())
.setLaunchType(hasForkHost() && hasLaunchType() ? getLaunchType() : LaunchType.node)
.setLaunchType(hasLaunchType() ? getLaunchType() : LaunchType.node)
.setForkHost(hasForkHost() ? getForkHost() : null)
.setAdminEmail(hasAdminEmail() ? getAdminEmail() : null);
}


+ 1
- 1
bubble-server/src/main/java/bubble/resources/bill/AccountPlansResource.java View File

@@ -168,7 +168,7 @@ public class AccountPlansResource extends AccountOwnedResource<AccountPlan, Acco
} else {
final String forkHost = request.getForkHost();
if (empty(forkHost)) {
request.setName(newNodeHostname()+"."+newNetworkName()+"."+domain.getName());
request.setName(newNetworkName());
request.setDomain(domain.getUuid());

} else {


+ 3
- 0
bubble-server/src/main/java/bubble/service/packer/PackerJob.java View File

@@ -217,6 +217,9 @@ public class PackerJob implements Callable<List<PackerImage>> {
copyFile(jar, new File(abs(bubbleFilesDir)+"/bubble.jar"));
copyScripts(bubbleFilesDir);

// copy assets required by compute driver
computeDriver.prepPackerDir(tempDir);

final String imageName = PACKER_IMAGE_NAME_TEMPLATE
.replace(INSTALL_TYPE_VAR, installType.name())
.replace(SAGE_NET_VAR, truncate(domainname(), 19))


+ 1
- 1
bubble-server/src/main/resources/META-INF/bubble/bubble.properties View File

@@ -1,3 +1,3 @@
# Do not edit this file directly
# Use _set_version to update the Bubble version in all files
bubble.version=Adventure 1.4.51
bubble.version=Adventure 1.4.52

docker/run_bubble.sh → bubble-server/src/main/resources/docker/run_bubble.sh View File


docker/run_bubble_slim.sh → bubble-server/src/main/resources/docker/run_bubble_slim.sh View File


docker/run_postgresql.sh → bubble-server/src/main/resources/docker/run_postgresql.sh View File


docker/run_redis.sh → bubble-server/src/main/resources/docker/run_redis.sh View File


+ 3
- 0
bubble-server/src/main/resources/docker/run_supervisor.sh View File

@@ -0,0 +1,3 @@
#!/bin/bash
supervisord --nodaemon


+ 1
- 1
bubble-server/src/main/resources/models/defaults/cloudService.json View File

@@ -158,7 +158,7 @@
"driverConfig": {
"regions": [{"name": "local", "internalName": "local"}],
"sizes": [{"name": "local", "type": "local", "internalName": "local"}],
"os": "ubuntu:20.04",
"os": "phusion/baseimage:focal-1.0.0alpha1-amd64",
"packer": {
"vars": [],
"sudo": false,


+ 39
- 0
bubble-server/src/main/resources/packer/roles/common/tasks/docker.yml View File

@@ -3,3 +3,42 @@
name: [ 'curl', 'cron', 'iptables', 'openssh-server' ]
state: present
update_cache: yes

- name: Ensure /service/ dirs exists
file:
path: "/service/{{ item }}"
owner: root
group: root
mode: 0755
state: directory
with_items: [ 'redis', 'postgresql', 'supervisor' ]

- name: Create /service/redis/run
copy:
src: run_redis.sh
dest: /service/redis/run
owner: root
group: root
mode: 0755

- name: Ensure redis runs in foreground
shell: bash -c "sed -i -e 's/daemonize yes/daemonize no/g' /etc/redis/redis.conf"

- name: Create /service/postgresql/run
copy:
src: run_postgresql.sh
dest: /service/postgresql/run
owner: root
group: root
mode: 0755

- name: trust local postgresql users
shell: bash -c "sed -i -e 's/ md5/ trust/g' $(find /etc/postgresql -mindepth 1 -maxdepth 1 -type d | sort | tail -1)/main/pg_hba.conf"

- name: Create /service/supervisor/run
copy:
src: run_supervisor.sh
dest: /service/supervisor/run
owner: root
group: root
mode: 0755

+ 1
- 1
bubble-server/src/test/resources/models/system/cloudService.json View File

@@ -125,7 +125,7 @@
"driverConfig": {
"regions": [{"name": "local", "internalName": "local"}],
"sizes": [{"name": "local", "type": "local", "internalName": "local"}],
"os": "ubuntu:20.04",
"os": "phusion/baseimage:focal-1.0.0alpha1-amd64",
"packer": {
"vars": [],
"sudo": false,


+ 1
- 1
pom.xml View File

@@ -14,7 +14,7 @@
<groupId>bubble</groupId>
<artifactId>bubble</artifactId>
<!-- @@BUBBLE_VERSION@@ this comment must remain above the version tag so that _set_version can update it -->
<version>1.4.51</version>
<version>1.4.52</version>
<packaging>pom</packaging>

<licenses>


+ 1
- 1
utils/pom.xml View File

@@ -10,7 +10,7 @@ This code is available under the GNU Affero General Public License, version 3: h
<groupId>bubble</groupId>
<artifactId>utils</artifactId>
<!-- @@BUBBLE_VERSION@@ this comment must remain above the version tag so that _set_version can update it -->
<version>1.4.51</version>
<version>1.4.52</version>
<packaging>pom</packaging>

<licenses>


Loading…
Cancel
Save