Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
using macvlan driver for default network
Browse files Browse the repository at this point in the history
  • Loading branch information
greyarch committed Jul 4, 2017
1 parent 1fb3a63 commit 8892c30
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
3 changes: 2 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ services:
DOCKER_HOST: tcp://10.19.88.248:2375
AUTH_TOKEN: innovation
HTTP_PORT: 8080
PIPEWORKS_CMD: eth1 -i eth0 @CONTAINER_NAME@ 0/0 @3080
MQTT_URL: mqtt://localhost
MQTT_USER: user
MQTT_PASS: pass
Expand All @@ -18,6 +17,8 @@ services:
SCRIPT_BASE_DIR: /local/data/scripts
DATA_DIR: /local/data
REMOTEFS_URL: http://10.19.88.248:8000
NETWORK_VLAN: 3080
NETWORK_PARENT_INTERFACE: eth0.3080
NETWORK_HEALTHCHECK_INTERVAL: 2s
NETWORK_HEALTHCHECK_TIMEOUT: 35s \
NETWORK_HEALTHCHECK_RETRIES: 10 \
Expand Down
6 changes: 3 additions & 3 deletions index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ ENABLE_NETWORK_HEALTHCHECK = env.get 'ENABLE_NETWORK_HEALTHCHECK', false
NETWORK_HEALTHCHECK_TEST_INTERFACE = env.get 'NETWORK_HEALTHCHECK_TEST_INTERFACE', 'eth0'
NETWORK_HEALTHCHECK_TEST_IP_PREFIX = env.get 'NETWORK_HEALTHCHECK_TEST_IP_PREFIX', '10.25'

pipeworksCmd = env.get 'PIPEWORKS_CMD', 'eth1 -i eth0 @CONTAINER_NAME@ 0/0 @3055'
vlan = parseInt(pipeworksCmd.slice(-4)) - 3000
vlan = env.assert 'NETWORK_VLAN'
scanCmd = env.get 'NETWORK_SCAN_CMD', "nmap -sP -n 10.25.#{vlan}.51-240"

datastoreScanEnabled = env.get 'DATASTORE_SCAN_ENABLED', true
Expand All @@ -31,6 +30,8 @@ config =
compose:
scriptBaseDir: env.assert 'SCRIPT_BASE_DIR'
network:
vlan: vlan
parentInterface: env.get 'NETWORK_PARENT_INTERFACE', "eth0.#{vlan}"
scanCmd: scanCmd
scanInterval: parseInt(env.get 'NETWORK_SCAN_INTERVAL', '60000')
scanEnabled: env.get 'NETWORK_SCAN_ENABLED', 'true'
Expand All @@ -39,7 +40,6 @@ config =
scanEnabled: env.get 'DHCP_SCAN_ENABLED', 'true'
net_container:
image: env.get 'NETWORK_IMAGE', 'ictu/pipes:2'
pipeworksCmd: pipeworksCmd
startcheck:
test: "ifconfig #{NETWORK_HEALTHCHECK_TEST_INTERFACE} | grep inet | grep #{NETWORK_HEALTHCHECK_TEST_IP_PREFIX}"
datastore:
Expand Down
20 changes: 13 additions & 7 deletions src/coffee/compose.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ resolvep = require 'resolve-path'
composeLib = require './compose/lib.coffee'

module.exports = (config) ->
networkValue = config.net_container.pipeworksCmd

_restrictCompose: restrictCompose = (serviceName, service) ->
delete service.cap_add
delete service.cap_drop
delete service.cgroup_parent
delete service.devices
delete service.dns
delete service.dns_search
delete service.networks
delete service.ports
delete service.privileged
delete service.tmpfs
Expand Down Expand Up @@ -75,10 +72,8 @@ module.exports = (config) ->
subDomain = "#{instance}.#{config.domain}.#{config.tld}"
netcontainer =
image: config.net_container.image
environment: eth0_pipework_cmd: networkValue
hostname: "#{serviceName}.#{subDomain}"
dns_search: subDomain
network_mode: 'none'
cap_add: ["NET_ADMIN"]
labels: labels
stop_signal: 'SIGKILL'
Expand Down Expand Up @@ -106,7 +101,20 @@ module.exports = (config) ->

else service.network_mode = "service:bb-net-#{service.labels['bigboat.service.name']}"

_addDefaultNetwork: addDefaultNetwork = (doc) ->
doc.networks =
default:
driver: 'macvlan'
driver_opts:
parent: config.network.parentInterface
ipam:
config: [{
subnet: '192.168.0.0/24'
gateway: '192.168.0.1'
}]

augmentCompose: (instance, options, doc) ->
addDefaultNetwork doc
for serviceName, service of doc.services
migrateLinksToDependsOn serviceName, service
addExtraLabels serviceName, service
Expand All @@ -117,7 +125,5 @@ module.exports = (config) ->
restrictCompose serviceName, service

doc.version = '2.1'

delete doc.volumes
delete doc.networks
doc
19 changes: 13 additions & 6 deletions tests/coffee/compose.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ compose = require '../../src/coffee/compose.coffee'
standardCfg =
net_container:
image: 'ictu/pipes:2'
pipeworksCmd: 'eth12 -i eth0 @CONTAINER_NAME@ 0/0 @1234'
network:
vlan: '1234'
parentInterface: 'eth2.1234'

describe 'Compose', ->
describe 'augmentCompose', ->
Expand All @@ -17,11 +19,19 @@ describe 'Compose', ->
assert.equal doc.volumes?, true
compose(standardCfg).augmentCompose '', {}, doc
assert.equal doc.volumes?, false
it 'should delete the networks section from the compose file', ->
it 'should set the default macvlan network the compose file', ->
doc = networks: {}
assert.equal doc.networks?, true
compose(standardCfg).augmentCompose '', {}, doc
assert.equal doc.networks?, false
assert.deepEqual doc.networks.default,
driver: 'macvlan'
driver_opts:
parent: 'eth2.1234'
ipam:
config: [{
subnet: '192.168.0.0/24'
gateway: '192.168.0.1'
}]

describe '_restrictCompose', ->
it 'should drop certain service capabilities', ->
Expand All @@ -32,7 +42,6 @@ describe 'Compose', ->
devices: 1
dns: 1
dns_search: 1
networks: 1
ports: 1
privileged: 1
tmpfs: 1
Expand Down Expand Up @@ -172,10 +181,8 @@ describe 'Compose', ->
assert.deepEqual service.depends_on, 'bb-net-service1': condition: 'service_started'
assert.deepEqual doc.services['bb-net-service1'],
image: 'ictu/pipes:2'
environment: eth0_pipework_cmd: "eth12 -i eth0 @CONTAINER_NAME@ 0/0 @1234"
hostname: 'service1.instance2.google.com'
dns_search: 'instance2.google.com'
network_mode: 'none'
cap_add: ['NET_ADMIN']
labels: 'bigboat.service.type': 'net'
stop_signal: 'SIGKILL'
Expand Down
3 changes: 0 additions & 3 deletions tests/js/network.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ td = require("testdouble");
var shelljs, network;

conf = {
net_container: {
pipeworksCmd: "eth1 -i eth0 @CONTAINER_NAME@ dhclient @3181"
},
network: {
scanCmd: "nmap -sP -n 10.25.181.51-240",
scanInterval: 1234
Expand Down

0 comments on commit 8892c30

Please sign in to comment.