-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use docker compose v2 #163
base: master
Are you sure you want to change the base?
Changes from 20 commits
a361a02
7cda8d3
f6c595e
a439c4c
03fee73
b2958d3
70ed8ef
696efb3
fc59bbf
3a4c3fe
add0755
f594288
eb53740
9ff20c1
8e7b32c
4da3de5
b9cc5a4
7a8b920
bddb7ea
700658a
2a39579
0f3b1bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,9 +248,8 @@ def create_compose_config(kubetools_config): | |
if dev_network: | ||
compose_config['networks'] = { | ||
'default': { | ||
'external': { | ||
'name': 'dev', | ||
}, | ||
'name': 'dev', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we should take this opportunity to rename this "default" network used by
I think we should replace Also, from a few tests I've run, it seems like other "environments" as created with |
||
'external': True, | ||
}, | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import sys | ||
|
||
from functools import lru_cache | ||
|
||
import docker | ||
|
@@ -138,8 +136,7 @@ def get_containers_status( | |
if not env: | ||
env = compose_project.replace(docker_name, '') | ||
|
||
# Where the name is compose-name_container_N, get container | ||
name = container.name.split('_')[1] | ||
name = _get_container_name_from_full_name(container.name) | ||
|
||
status = container.status == 'running' | ||
ports = [] | ||
|
@@ -194,6 +191,17 @@ def get_containers_status( | |
return env_to_containers.get(kubetools_config['env'], {}) | ||
|
||
|
||
def _get_container_name_from_full_name(full_name): | ||
# if the container was made in v1, it will be composename_container_N | ||
converted_name = full_name.replace('_', '-') | ||
Comment on lines
+195
to
+196
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to check, are we trying to create logic that is backwards compatible with compose V2? I think that, in line with the change to README and with the major version change, we don´t need to support any backwards compatible logic here. |
||
|
||
# we need to keep the middle part of the name | ||
# for example if we have a container called `composename-container-1-N` | ||
# we want to keep `container-1` | ||
middle_names = converted_name.split('-')[1:-1] | ||
return '-'.join(middle_name for middle_name in middle_names) | ||
|
||
|
||
def get_container_status(kubetools_config, name): | ||
containers = get_containers_status(kubetools_config, container_name=name) | ||
return containers.get(name) | ||
|
@@ -204,8 +212,7 @@ def run_compose_process(kubetools_config, command_args, **kwargs): | |
create_compose_config(kubetools_config) | ||
|
||
compose_command = [ | ||
# Use current interpreter to run the docker-compose module installed in the same venv | ||
sys.executable, '-m', 'compose', | ||
'docker', 'compose', | ||
# Force us to look at the current directory, not relative to the compose | ||
# filename (ie .kubetools/compose-name.yml). | ||
'--project-directory', '.', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
kind: CronJob | ||
metadata: | ||
name: generic-cronjob | ||
labels: { | ||
kubetools/name: generic-cronjob, | ||
kubetools/project_name: complex-named-app, | ||
kubetools/role: cronjob | ||
} | ||
annotations: { | ||
app.kubernetes.io/managed-by: kubetools, | ||
description: 'Run: [''generic-command'']' | ||
} | ||
spec: | ||
schedule: "*/1 * * * *" | ||
startingDeadlineSeconds: 10 | ||
concurrencyPolicy: "Allow" | ||
jobTemplate: | ||
spec: | ||
template: | ||
metadata: | ||
name: generic-cronjob | ||
labels: { | ||
kubetools/name: generic-cronjob, | ||
kubetools/project_name: complex-named-app, | ||
kubetools/role: cronjob | ||
} | ||
annotations: { | ||
app.kubernetes.io/managed-by: kubetools, | ||
description: 'Run: [''generic-command'']' | ||
} | ||
spec: | ||
containers: | ||
- command: [generic-command] | ||
containerContext: generic-context | ||
env: | ||
- {name: KUBE, value: 'true'} | ||
image: generic-image | ||
imagePullPolicy: 'Always' | ||
name: generic-container | ||
restartPolicy: OnFailure |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
annotations: {app.kubernetes.io/managed-by: kubetools} | ||
labels: {kubetools/name: complex-named-app, kubetools/project_name: complex-named-app, kubetools/role: app} | ||
name: complex-named-app | ||
spec: | ||
replicas: 1 | ||
revisionHistoryLimit: 5 | ||
selector: | ||
matchLabels: {kubetools/name: complex-named-app, kubetools/project_name: complex-named-app, | ||
kubetools/role: app} | ||
template: | ||
metadata: | ||
labels: {kubetools/name: complex-named-app, kubetools/project_name: complex-named-app, kubetools/role: app} | ||
spec: | ||
containers: | ||
- command: [generic-command] | ||
containerContext: generic-context | ||
env: | ||
- {name: KUBE, value: 'true'} | ||
image: generic-image | ||
imagePullPolicy: Always | ||
livenessProbe: | ||
httpGet: {path: /ping, port: 80} | ||
timeoutSeconds: 5 | ||
name: complex-webserver | ||
readinessProbe: | ||
httpGet: {path: /ping, port: 80} | ||
timeoutSeconds: 5 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
annotations: {app.kubernetes.io/managed-by: kubetools, description: 'Run: [''generic-command'']'} | ||
labels: {job-id: UUID, kubetools/project_name: complex-named-app, | ||
kubetools/role: job} | ||
name: UUID | ||
spec: | ||
completions: 1 | ||
parallelism: 1 | ||
selector: {job-id: UUID, kubetools/project_name: complex-named-app, | ||
kubetools/role: job} | ||
template: | ||
metadata: | ||
labels: {job-id: UUID, kubetools/project_name: complex-named-app, | ||
kubetools/role: job} | ||
spec: | ||
containers: | ||
- chdir: / | ||
command: [generic-command] | ||
env: | ||
- {name: KUBE, value: 'true'} | ||
- {name: KUBE_JOB_ID, value: UUID} | ||
image: generic-image | ||
imagePullPolicy: Always | ||
name: upgrade | ||
resources: | ||
requests: | ||
memory: "1Gi" | ||
restartPolicy: Never |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
annotations: {app.kubernetes.io/managed-by: kubetools} | ||
labels: {kubetools/name: complex-named-app, kubetools/project_name: complex-named-app, kubetools/role: app} | ||
name: complex-named-app | ||
spec: | ||
ports: | ||
- {port: 80, targetPort: 80} | ||
selector: {kubetools/name: complex-named-app, kubetools/project_name: complex-named-app, kubetools/role: app} | ||
type: NodePort |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: complex-named-app | ||
|
||
|
||
containerContexts: | ||
generic-context: | ||
image: generic-image | ||
command: [generic-command] | ||
ports: | ||
- 80 | ||
|
||
upgrades: | ||
- name: Upgrade the database | ||
containerContext: generic-context | ||
command: [generic-command, generic-arg] | ||
resources: | ||
requests: | ||
memory: "1Gi" | ||
|
||
|
||
deployments: | ||
complex-named-app: | ||
containers: | ||
complex-webserver: | ||
command: [uwsgi, --ini, /etc/uwsgi.conf] | ||
containerContext: generic-context | ||
probes: | ||
timeoutSeconds: 5 | ||
httpGet: | ||
path: /ping | ||
|
||
|
||
cronjobs: | ||
generic-cronjob: | ||
schedule: "*/1 * * * *" | ||
concurrency_policy: "Allow" | ||
containers: | ||
generic-container: | ||
containerContext: generic-context |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,37 @@ | ||||
from string import ascii_lowercase | ||||
from unittest import TestCase | ||||
|
||||
from kubetools.dev.backends.docker_compose.config import dockerise_label | ||||
from kubetools.dev.backends.docker_compose.docker_util import _get_container_name_from_full_name | ||||
|
||||
|
||||
def generate_long_names(number_of_separators, separator): | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment below, this function probably will disappear. But if it had to stay, then it needs to be renamed because it's confusing::
|
||||
return separator.join([ | ||||
ch for ch in ascii_lowercase[:number_of_separators+1]]) | ||||
|
||||
|
||||
class TestDockerComposeNameConversion(TestCase): | ||||
# we need to check this works for dashes and underscores | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
def test_dockerise_label_dashes(self): | ||||
for i in range(5): | ||||
long_name = generate_long_names(i, '-') | ||||
dockerised_name = dockerise_label(long_name) | ||||
self.assertEqual(dockerised_name, ascii_lowercase[:i+1]) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not quite sure but I have a feeling that we're using |
||||
|
||||
def test_dockerise_label_underscores(self): | ||||
for i in range(5): | ||||
long_name = generate_long_names(i, '_') | ||||
dockerised_name = dockerise_label(long_name) | ||||
self.assertEqual(dockerised_name, ascii_lowercase[:i+1]) | ||||
|
||||
def test_container_name_from_full_name_dashes(self): | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These test names don't explain the scenario that we're testing here. |
||||
for i in range(5): | ||||
container_name = generate_long_names(i, '-') | ||||
full_name = '-'.join([ascii_lowercase[:i+1], container_name, '1']) | ||||
self.assertEqual(_get_container_name_from_full_name(full_name), container_name) | ||||
|
||||
def test_container_name_from_full_name_underscores(self): | ||||
for i in range(5): | ||||
container_name = generate_long_names(i, '-') | ||||
full_name = '_'.join([ascii_lowercase[:i+1], container_name, '1']) | ||||
self.assertEqual(_get_container_name_from_full_name(full_name), container_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.