Skip to content

Commit

Permalink
Add instructions and script for converting compose to k8.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Apr 25, 2017
1 parent 75b705d commit 6dc170c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions compose/k8/convert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python

# Install kompose (e.g. brew install kompose).
# Install minikube (e.g. brew install minikube).
# $ minikube start # Build a k8 cluster in a VM.
# $ eval $(minikube docker-env) # Target Docker commands at the VM's Docker host.
# $ cd ..; bash buildlocal.sh; cd k8 # Build Docker containers required for k8 setup.
# $ python convert.py # Execute this wrapper around kompose to build native k8 artifacts.

import os
import subprocess
import yaml

DIRECTORY = os.path.abspath(os.path.dirname(__file__))
COMPOSE_TARGET = os.path.abspath(os.path.join(DIRECTORY, "..", "docker-compose.yml"))
KOMPOSE_TARGET = os.path.join(DIRECTORY, "docker-compose-for-kompose.yml")


def main():
with open(COMPOSE_TARGET, "r") as f:
raw_compose_def = yaml.load(f)

_hack_for_kompose(raw_compose_def)
with open(KOMPOSE_TARGET, "w") as f:
yaml.dump(raw_compose_def, f)

subprocess.check_call(["kompose", "-f", KOMPOSE_TARGET, "convert"])


def _hack_for_kompose(raw_compose_def):
ftp_ports = raw_compose_def["services"]["proftpd"]["ports"]
del ftp_ports[2]
for i in range(10):
# Replace "30000-30010:30000-30010" with individual entries.
ftp_ports.append("%d:%d" % (30000 + i, 30000 + i))


if __name__ == "__main__":
main()

0 comments on commit 6dc170c

Please sign in to comment.