Skip to content

Commit

Permalink
Split IPv6 network and host network mode config into multiple compose…
Browse files Browse the repository at this point in the history
… files
  • Loading branch information
alco committed Jun 22, 2024
1 parent 528aa25 commit e1f75a5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 45 deletions.
18 changes: 12 additions & 6 deletions clients/typescript/src/cli/docker-commands/docker-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { spawn } from 'child_process'
import path from 'path'
import { fileURLToPath } from 'url'

const composeFile = path.join(
path.dirname(fileURLToPath(import.meta.url)),
'docker',
'compose.yaml'
)
const composeFilePath = (filename: string) =>
path.join(path.dirname(fileURLToPath(import.meta.url)), 'docker', filename)

const composeFile = 'compose.yaml'

const extraComposeFile =
process.env.DOCKER_NETWORK_USE_EXTERNAL === 'host'
? 'compose.hostnet.yaml'
: 'compose.ip6net.yaml'

export function dockerCompose(
command: string,
Expand All @@ -19,7 +23,9 @@ export function dockerCompose(
'--ansi',
'always',
'-f',
composeFile,
composeFilePath(composeFile),
'-f',
composeFilePath(extraComposeFile),
command,
...userArgs,
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
electric:
network_mode: host
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
networks:
# An IPv6-enabled network is necessary for the sync service to connect to
# databases that are only reachable at IPv6 addresses. IPv4 can also be used as usual with
# this network.
ip6net:
enable_ipv6: true
# These two options provide an escape hatch that allows users to define their own Docker
# network using `docker network create` and make the services defined in this compose file
# use that.
external: ${${DOCKER_NETWORK_USE_EXTERNAL:+true}:-false}
name: '${DOCKER_NETWORK_USE_EXTERNAL}'
ipam:
config:
# Subnet definition isn't required if the Docker daemon has a default address pool for
# IPv6 addresses configured. However, since that's not the case for Docker
# out-of-the-box and since we want to free our users from additional manual
# configuration when possible, we include a default subnet definition here that should
# work with any Docker daemon configuration.
#
# The fd00:: prefix is part of the address space reserved for Unique Local Addresses,
# i.e. private networks. This is analogous to 192.168.x.x in the IPv4 land.
#
# There is a possibility that this subnet overlaps with another network configured
# separately for the same Docker daemon. That situation would result in `docker compose
# up` failing with the error message
#
# Error response from daemon: Pool overlaps with other one on this address space
#
# Users can specify a different subnet via the DOCKER_NETWORK_SUBNET variable to
# address such conflicts.
#
# The default subnet here has 2 randomly generated bytes in the 2nd and the 6th groups,
# it can accommodate 4 addresses which is small enough to further reduce any chance of conflicts.
- subnet: 'fd00:56f0::4acd:f0fc/126'

services:
electric:
networks:
# Despite the name, assigning this network to the sync service does not preclude the use
# of IPv4.
- ip6net
39 changes: 0 additions & 39 deletions clients/typescript/src/cli/docker-commands/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,6 @@ configs:
volumes:
pg_data:

networks:
# An IPv6-enabled network is necessary for the sync service to connect to
# databases that are only reachable at IPv6 addresses. IPv4 can also be used as usual with
# this network.
ip6net:
enable_ipv6: true
# These two options provide an escape hatch that allows users to define their own Docker
# network using `docker network create` and make the services defined in this compose file
# use that.
external: '${DOCKER_NETWORK_USE_EXTERNAL:-false}'
name: '${DOCKER_NETWORK_NAME-}'
ipam:
config:
# Subnet definition isn't required if the Docker daemon has a default address pool for
# IPv6 addresses configured. However, since that's not the case for Docker
# out-of-the-box and since we want to free our users from additional manual
# configuration when possible, we include a default subnet definition here that should
# work with any Docker daemon configuration.
#
# The fd00:: prefix is part of the address space reserved for Unique Local Addresses,
# i.e. private networks. This is analogous to 192.168.x.x in the IPv4 land.
#
# There is a possibility that this subnet overlaps with another network configured
# separately for the same Docker daemon. That situation would result in `docker compose
# up` failing with the error message
#
# Error response from daemon: Pool overlaps with other one on this address space
#
# Users can specify a different subnet via the DOCKER_NETWORK_SUBNET variable to
# address such conflicts.
#
# The default subnet here has 2 randomly generated bytes in the 2nd and the 6th groups,
# it can accommodate 4 addresses which is small enough to further reduce any chance of conflicts.
- subnet: '${DOCKER_NETWORK_SUBNET:-fd00:56f0::4acd:f0fc/126}'

services:
postgres:
profiles: ['with-postgres']
Expand Down Expand Up @@ -107,7 +72,3 @@ services:
AUTH_JWT_KEY: ${AUTH_JWT_KEY:-}
AUTH_JWT_NAMESPACE: ${AUTH_JWT_NAMESPACE:-}
ELECTRIC_FEATURES: ${ELECTRIC_FEATURES:-}
networks:
# Despite the name, assigning this network to the sync service does not preclude the use
# of IPv4.
- ip6net

0 comments on commit e1f75a5

Please sign in to comment.