add e2e tests for bridge convert and transformers ls commands

Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
Guillaume Lours 2025-05-26 15:16:40 +02:00 committed by Nicolas De loof
parent 9a9227ce64
commit be83f63f26
33 changed files with 686 additions and 0 deletions

59
pkg/e2e/bridge_test.go Normal file
View File

@ -0,0 +1,59 @@
/*
Copyright 2020 Docker Compose CLI authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package e2e
import (
"fmt"
"strings"
"testing"
"gotest.tools/v3/assert"
)
func TestConvertAndTransformList(t *testing.T) {
c := NewParallelCLI(t)
const projectName = "bridge"
tmpDir := t.TempDir()
t.Run("kubernetes manifests", func(t *testing.T) {
kubedir := fmt.Sprintf("%s/kubernetes", tmpDir)
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/bridge/compose.yaml", "--project-name", projectName, "bridge", "convert",
"--output", kubedir)
assert.NilError(t, res.Error)
assert.Equal(t, res.ExitCode, 0)
res = c.RunCmd(t, "diff", "-r", kubedir, "./fixtures/bridge/expected-kubernetes")
assert.NilError(t, res.Error, res.Combined())
})
t.Run("helm charts", func(t *testing.T) {
helmDir := fmt.Sprintf("%s/helm", tmpDir)
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/bridge/compose.yaml", "--project-name", projectName, "bridge", "convert",
"--output", helmDir, "--transformation", "docker/compose-bridge-helm")
assert.NilError(t, res.Error)
assert.Equal(t, res.ExitCode, 0)
res = c.RunCmd(t, "diff", "-r", helmDir, "./fixtures/bridge/expected-helm")
assert.NilError(t, res.Error, res.Combined())
})
t.Run("list transformers images", func(t *testing.T) {
res := c.RunDockerComposeCmd(t, "--project-name", projectName, "bridge", "transformations",
"ls")
assert.Assert(t, strings.Contains(res.Stdout(), "docker/compose-bridge-helm"), res.Combined())
assert.Assert(t, strings.Contains(res.Stdout(), "docker/compose-bridge-kubernetes"), res.Combined())
})
}

View File

@ -0,0 +1,18 @@
# Copyright 2020 Docker Compose CLI authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM alpine
ENV ENV_FROM_DOCKERFILE=1
EXPOSE 8081
CMD ["echo", "Hello from Dockerfile"]

View File

@ -0,0 +1,31 @@
services:
serviceA:
image: alpine
build: .
ports:
- 80:8080
networks:
- private-network
configs:
- source: my-config
target: /etc/my-config1.txt
serviceB:
image: alpine
build: .
ports:
- 8081:8082
secrets:
- my-secrets
networks:
- private-network
- public-network
configs:
my-config:
file: my-config.txt
secrets:
my-secrets:
file: not-so-secret.txt
networks:
private-network:
internal: true
public-network: {}

View File

@ -0,0 +1,12 @@
#! Chart.yaml
apiVersion: v2
name: bridge
version: 0.0.1
# kubeVersion: >= 1.29.1
description: A generated Helm Chart for bridge generated via compose-bridge.
type: application
keywords:
- bridge
appVersion: 'v0.0.1'
sources:
annotations:

View File

@ -0,0 +1,8 @@
#! 0-bridge-namespace.yaml
# Generated code, do not edit
apiVersion: v1
kind: Namespace
metadata:
name: bridge
labels:
com.docker.compose.project: bridge

View File

@ -0,0 +1,12 @@
#! bridge-configs.yaml
# Generated code, do not edit
apiVersion: v1
kind: ConfigMap
metadata:
name: bridge
namespace: bridge
labels:
com.docker.compose.project: bridge
data:
my-config: |
My config file

View File

@ -0,0 +1,13 @@
#! my-secrets-secret.yaml
# Generated code, do not edit
apiVersion: v1
kind: Secret
metadata:
name: my-secrets
namespace: {{ .Values.namespace }}
labels:
com.docker.compose.project: bridge
com.docker.compose.secret: my-secrets
data:
my-secrets: bm90LXNlY3JldA==
type: Opaque

View File

@ -0,0 +1,24 @@
#! private-network-network-policy.yaml
# Generated code, do not edit
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: private-network-network-policy
namespace: {{ .Values.namespace }}
spec:
podSelector:
matchLabels:
com.docker.compose.network.private-network: "true"
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
com.docker.compose.network.private-network: "true"
egress:
- to:
- podSelector:
matchLabels:
com.docker.compose.network.private-network: "true"

View File

@ -0,0 +1,24 @@
#! public-network-network-policy.yaml
# Generated code, do not edit
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: public-network-network-policy
namespace: {{ .Values.namespace }}
spec:
podSelector:
matchLabels:
com.docker.compose.network.public-network: "true"
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
com.docker.compose.network.public-network: "true"
egress:
- to:
- podSelector:
matchLabels:
com.docker.compose.network.public-network: "true"

View File

@ -0,0 +1,45 @@
#! serviceA-deployment.yaml
# Generated code, do not edit
apiVersion: apps/v1
kind: Deployment
metadata:
name: servicea
namespace: {{ .Values.namespace }}
labels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceA
app.kubernetes.io/managed-by: Helm
spec:
replicas: 1
selector:
matchLabels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceA
strategy:
type: Recreate
template:
metadata:
labels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceA
com.docker.compose.network.private-network: "true"
spec:
containers:
- name: servicea
image: {{ .Values.serviceA.image }}
imagePullPolicy: {{ .Values.serviceA.imagePullPolicy }}
ports:
- name: servicea-8080
containerPort: 8080
volumeMounts:
- name: etc-my-config1-txt
mountPath: /etc/my-config1.txt
subPath: my-config
readOnly: true
volumes:
- name: etc-my-config1-txt
configMap:
name: bridge
items:
- key: my-config
path: my-config

View File

@ -0,0 +1,19 @@
#! serviceA-expose.yaml
# Generated code, do not edit
apiVersion: v1
kind: Service
metadata:
name: servicea
namespace: {{ .Values.namespace }}
labels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceA
app.kubernetes.io/managed-by: Helm
spec:
selector:
com.docker.compose.project: bridge
com.docker.compose.service: serviceA
ports:
- name: servicea-8080
port: 8080
targetPort: servicea-8080

View File

@ -0,0 +1,25 @@
# check if there is at least one published port
#! serviceA-service.yaml
# Generated code, do not edit
apiVersion: v1
kind: Service
metadata:
name: servicea-published
namespace: {{ .Values.namespace }}
labels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceA
app.kubernetes.io/managed-by: Helm
spec:
type: LoadBalancer
selector:
com.docker.compose.project: bridge
com.docker.compose.service: serviceA
ports:
- name: servicea-80
port: 80
protocol: TCP
targetPort: servicea-8080
# check if there is at least one published port

View File

@ -0,0 +1,46 @@
#! serviceB-deployment.yaml
# Generated code, do not edit
apiVersion: apps/v1
kind: Deployment
metadata:
name: serviceb
namespace: {{ .Values.namespace }}
labels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceB
app.kubernetes.io/managed-by: Helm
spec:
replicas: 1
selector:
matchLabels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceB
strategy:
type: Recreate
template:
metadata:
labels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceB
com.docker.compose.network.private-network: "true"
com.docker.compose.network.public-network: "true"
spec:
containers:
- name: serviceb
image: {{ .Values.serviceB.image }}
imagePullPolicy: {{ .Values.serviceB.imagePullPolicy }}
ports:
- name: serviceb-8082
containerPort: 8082
volumeMounts:
- name: run-secrets-my-secrets
mountPath: /run/secrets/my-secrets
subPath: my-secrets
readOnly: true
volumes:
- name: run-secrets-my-secrets
secret:
secretName: my-secrets
items:
- key: my-secrets
path: my-secrets

View File

@ -0,0 +1,19 @@
#! serviceB-expose.yaml
# Generated code, do not edit
apiVersion: v1
kind: Service
metadata:
name: serviceb
namespace: {{ .Values.namespace }}
labels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceB
app.kubernetes.io/managed-by: Helm
spec:
selector:
com.docker.compose.project: bridge
com.docker.compose.service: serviceB
ports:
- name: serviceb-8082
port: 8082
targetPort: serviceb-8082

View File

@ -0,0 +1,21 @@
#! serviceB-service.yaml
# Generated code, do not edit
apiVersion: v1
kind: Service
metadata:
name: serviceb-published
namespace: {{ .Values.namespace }}
labels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceB
app.kubernetes.io/managed-by: Helm
spec:
type: LoadBalancer
selector:
com.docker.compose.project: bridge
com.docker.compose.service: serviceB
ports:
- name: serviceb-8081
port: 8081
protocol: TCP
targetPort: serviceb-8082

View File

@ -0,0 +1,13 @@
#! values.yaml
# Namespace
namespace: bridge
# Services variables
serviceA:
image: alpine
imagePullPolicy: IfNotPresent
serviceB:
image: alpine
imagePullPolicy: IfNotPresent
# You can apply the same logic to loop on networks, volumes, secrets and configs...

View File

@ -0,0 +1,8 @@
#! 0-bridge-namespace.yaml
# Generated code, do not edit
apiVersion: v1
kind: Namespace
metadata:
name: bridge
labels:
com.docker.compose.project: bridge

View File

@ -0,0 +1,12 @@
#! bridge-configs.yaml
# Generated code, do not edit
apiVersion: v1
kind: ConfigMap
metadata:
name: bridge
namespace: bridge
labels:
com.docker.compose.project: bridge
data:
my-config: |
My config file

View File

@ -0,0 +1,16 @@
#! kustomization.yaml
# Generated code, do not edit
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- 0-bridge-namespace.yaml
- bridge-configs.yaml
- my-secrets-secret.yaml
- private-network-network-policy.yaml
- public-network-network-policy.yaml
- serviceA-deployment.yaml
- serviceA-expose.yaml
- serviceA-service.yaml
- serviceB-deployment.yaml
- serviceB-expose.yaml
- serviceB-service.yaml

View File

@ -0,0 +1,13 @@
#! my-secrets-secret.yaml
# Generated code, do not edit
apiVersion: v1
kind: Secret
metadata:
name: my-secrets
namespace: bridge
labels:
com.docker.compose.project: bridge
com.docker.compose.secret: my-secrets
data:
my-secrets: bm90LXNlY3JldA==
type: Opaque

View File

@ -0,0 +1,24 @@
#! private-network-network-policy.yaml
# Generated code, do not edit
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: private-network-network-policy
namespace: bridge
spec:
podSelector:
matchLabels:
com.docker.compose.network.private-network: "true"
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
com.docker.compose.network.private-network: "true"
egress:
- to:
- podSelector:
matchLabels:
com.docker.compose.network.private-network: "true"

View File

@ -0,0 +1,24 @@
#! public-network-network-policy.yaml
# Generated code, do not edit
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: public-network-network-policy
namespace: bridge
spec:
podSelector:
matchLabels:
com.docker.compose.network.public-network: "true"
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
com.docker.compose.network.public-network: "true"
egress:
- to:
- podSelector:
matchLabels:
com.docker.compose.network.public-network: "true"

View File

@ -0,0 +1,44 @@
#! serviceA-deployment.yaml
# Generated code, do not edit
apiVersion: apps/v1
kind: Deployment
metadata:
name: servicea
namespace: bridge
labels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceA
spec:
replicas: 1
selector:
matchLabels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceA
strategy:
type: Recreate
template:
metadata:
labels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceA
com.docker.compose.network.private-network: "true"
spec:
containers:
- name: servicea
image: alpine
imagePullPolicy: IfNotPresent
ports:
- name: servicea-8080
containerPort: 8080
volumeMounts:
- name: etc-my-config1-txt
mountPath: /etc/my-config1.txt
subPath: my-config
readOnly: true
volumes:
- name: etc-my-config1-txt
configMap:
name: bridge
items:
- key: my-config
path: my-config

View File

@ -0,0 +1,18 @@
#! serviceA-expose.yaml
# Generated code, do not edit
apiVersion: v1
kind: Service
metadata:
name: servicea
namespace: bridge
labels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceA
spec:
selector:
com.docker.compose.project: bridge
com.docker.compose.service: serviceA
ports:
- name: servicea-8080
port: 8080
targetPort: servicea-8080

View File

@ -0,0 +1,23 @@
# check if there is at least one published port
#! serviceA-service.yaml
# Generated code, do not edit
apiVersion: v1
kind: Service
metadata:
name: servicea-published
namespace: bridge
labels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceA
spec:
selector:
com.docker.compose.project: bridge
com.docker.compose.service: serviceA
ports:
- name: servicea-80
port: 80
protocol: TCP
targetPort: servicea-8080
# check if there is at least one published port

View File

@ -0,0 +1,45 @@
#! serviceB-deployment.yaml
# Generated code, do not edit
apiVersion: apps/v1
kind: Deployment
metadata:
name: serviceb
namespace: bridge
labels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceB
spec:
replicas: 1
selector:
matchLabels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceB
strategy:
type: Recreate
template:
metadata:
labels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceB
com.docker.compose.network.private-network: "true"
com.docker.compose.network.public-network: "true"
spec:
containers:
- name: serviceb
image: alpine
imagePullPolicy: IfNotPresent
ports:
- name: serviceb-8082
containerPort: 8082
volumeMounts:
- name: run-secrets-my-secrets
mountPath: /run/secrets/my-secrets
subPath: my-secrets
readOnly: true
volumes:
- name: run-secrets-my-secrets
secret:
secretName: my-secrets
items:
- key: my-secrets
path: my-secrets

View File

@ -0,0 +1,18 @@
#! serviceB-expose.yaml
# Generated code, do not edit
apiVersion: v1
kind: Service
metadata:
name: serviceb
namespace: bridge
labels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceB
spec:
selector:
com.docker.compose.project: bridge
com.docker.compose.service: serviceB
ports:
- name: serviceb-8082
port: 8082
targetPort: serviceb-8082

View File

@ -0,0 +1,19 @@
#! serviceB-service.yaml
# Generated code, do not edit
apiVersion: v1
kind: Service
metadata:
name: serviceb-published
namespace: bridge
labels:
com.docker.compose.project: bridge
com.docker.compose.service: serviceB
spec:
selector:
com.docker.compose.project: bridge
com.docker.compose.service: serviceB
ports:
- name: serviceb-8081
port: 8081
protocol: TCP
targetPort: serviceb-8082

View File

@ -0,0 +1,9 @@
#! kustomization.yaml
# Generated code, do not edit
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
patches:
- path: serviceA-service.yaml
- path: serviceB-service.yaml

View File

@ -0,0 +1,13 @@
# check if there is at least one published port
#! serviceA-service.yaml
# Generated code, do not edit
apiVersion: v1
kind: Service
metadata:
name: servicea-published
namespace: bridge
spec:
type: LoadBalancer
# check if there is at least one published port

View File

@ -0,0 +1,9 @@
#! serviceB-service.yaml
# Generated code, do not edit
apiVersion: v1
kind: Service
metadata:
name: serviceb-published
namespace: bridge
spec:
type: LoadBalancer

View File

@ -0,0 +1 @@
My config file

View File

@ -0,0 +1 @@
not-secret