Skip to content

Commit

Permalink
Test - set service resource request label via env var in compose
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxCWhitehead committed Sep 26, 2024
1 parent 3dede15 commit 3d6a08c
Show file tree
Hide file tree
Showing 7 changed files with 436 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cmd/template_lagoonservices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,31 @@ func TestTemplateLagoonServices(t *testing.T) {
templatePath: "testoutput",
want: "internal/testdata/basic/service-templates/test-basic-spot-affinity",
},
{
name: "test16-nginx-php-resource-requests-from-env",
description: "tests an nginx-php deployment with service label resource requests set from env var",
args: testdata.GetSeedData(
testdata.TestData{
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "internal/testdata/complex/lagoon.resources.yml",
EnvVariables: []lagoon.EnvironmentVariable{
{
Name: "NGINX_CPU_REQUEST",
Value: "50m",
Scope: "global",
},
},
ImageReferences: map[string]string{
"nginx": "harbor.example/example-project/main/nginx@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8",
"php": "harbor.example/example-project/main/php@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8",
"cli": "harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8",
},
}, true),
templatePath: "testoutput",
want: "internal/testdata/complex/service-templates/test16-nginx-php-resources",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
105 changes: 105 additions & 0 deletions internal/testdata/complex/docker-compose.resources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
version: '2.3'

x-example-image-version:
&example-image-version ${EXAMPLE_IMAGE_VERSION:-4.x}

x-project:
&project ${PROJECT_NAME:-mysite}

x-volumes:
&default-volumes
volumes:
- .:/app:${VOLUME_FLAGS:-delegated} ### Local overrides to mount host filesystem. Automatically removed in CI and PROD.
- ./docroot/sites/default/files:/app/docroot/sites/default/files:${VOLUME_FLAGS:-delegated} ### Local overrides to mount host filesystem. Automatically removed in CI and PROD.

x-environment:
&default-environment
LAGOON_PROJECT: *project
DRUPAL_HASH_SALT: fakehashsaltfakehashsaltfakehashsalt
LAGOON_LOCALDEV_URL: ${LOCALDEV_URL:-http://mysite.docker.amazee.io}
LAGOON_ROUTE: ${LOCALDEV_URL:-http://mysite.docker.amazee.io}
GITHUB_TOKEN: ${GITHUB_TOKEN:-}
EXAMPLE_KEY: ${EXAMPLE_KEY:-}
EXAMPLE_IMAGE_VERSION: ${EXAMPLE_IMAGE_VERSION:-latest}
LAGOON_ENVIRONMENT_TYPE: ${LAGOON_ENVIRONMENT_TYPE:-local}
DRUPAL_REFRESH_SEARCHAPI: ${DRUPAL_REFRESH_SEARCHAPI:-}
EXAMPLE_INGRESS_PSK: ${EXAMPLE_INGRESS_PSK:-}
EXAMPLE_INGRESS_HEADER: ${EXAMPLE_INGRESS_HEADER:-}
EXAMPLE_INGRESS_ENABLED: ${EXAMPLE_INGRESS_ENABLED:-}
DB_ALIAS: ${DB_ALIAS:-bay.production}


services:

cli:
build:
context: internal/testdata/complex/docker
dockerfile: .docker/Dockerfile.cli
args:
COMPOSER: ${COMPOSER:-composer.json}
EXAMPLE_IMAGE_VERSION: *example-image-version
image: *project
environment:
<< : *default-environment
<< : *default-volumes
volumes_from: ### Local overrides to mount host SSH keys. Automatically removed in CI.
- container:amazeeio-ssh-agent ### Local overrides to mount host SSH keys. Automatically removed in CI.
labels:
lagoon.type: cli-persistent
lagoon.persistent: /app/docroot/sites/default/files/
lagoon.persistent.name: nginx-php
lagoon.persistent.size: 5Gi

nginx:
build:
context: internal/testdata/complex/docker
dockerfile: .docker/Dockerfile.nginx-drupal
args:
CLI_IMAGE: *project
EXAMPLE_IMAGE_VERSION: *example-image-version
<< : *default-volumes
environment:
<< : *default-environment
depends_on:
- cli
networks:
- amazeeio-network
- default
labels:
lagoon.type: nginx-php-persistent
lagoon.persistent: /app/docroot/sites/default/files/
lagoon.persistent.size: 5Gi
lagoon.name: nginx-php
# NGINX_CPU_REQUEST is injected as project env in test
lagoon.resources.requests.cpu: ${NGINX_CPU_REQUEST}
lagoon.resources.limits.cpu: 100m
expose:
- "8080"
php:
build:
context: internal/testdata/complex/docker
dockerfile: .docker/Dockerfile.php
args:
CLI_IMAGE: *project
EXAMPLE_IMAGE_VERSION: *example-image-version
environment:
<< : *default-environment
<< : *default-volumes
depends_on:
- cli
labels:
lagoon.type: nginx-php-persistent
lagoon.persistent: /app/docroot/sites/default/files/
lagoon.persistent.size: 5Gi
lagoon.name: nginx-php
lagon.resources.requests.cpu: 20m
lagoon.resources.limits.cpu: 200m


networks:
amazeeio-network:
external: true

volumes:
app: {}
files: {}
10 changes: 10 additions & 0 deletions internal/testdata/complex/lagoon.resources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
docker-compose-yaml: internal/testdata/complex/docker-compose.resources.yml

project: example-com

environments:
main:
routes:
- nginx:
- example.com
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: cli
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: cli-persistent
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: cli
lagoon.sh/service-type: cli-persistent
lagoon.sh/template: cli-persistent-0.1.0
name: cli
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/instance: cli
app.kubernetes.io/name: cli-persistent
strategy: {}
template:
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/configMapSha: abcdefg1234567890
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: cli
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: cli-persistent
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: cli
lagoon.sh/service-type: cli-persistent
lagoon.sh/template: cli-persistent-0.1.0
spec:
containers:
- env:
- name: LAGOON_GIT_SHA
value: "0000000000000000000000000000000000000000"
- name: CRONJOBS
- name: SERVICE_NAME
value: cli
envFrom:
- configMapRef:
name: lagoon-env
image: harbor.example/example-project/main/cli@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8
imagePullPolicy: Always
name: cli
readinessProbe:
exec:
command:
- /bin/sh
- -c
- if [ -x /bin/entrypoint-readiness ]; then /bin/entrypoint-readiness;
fi
failureThreshold: 3
initialDelaySeconds: 5
periodSeconds: 2
resources:
requests:
cpu: 10m
memory: 10Mi
securityContext: {}
volumeMounts:
- mountPath: /var/run/secrets/lagoon/sshkey/
name: lagoon-sshkey
readOnly: true
- mountPath: /app/docroot/sites/default/files//php
name: nginx-php-twig
- mountPath: /app/docroot/sites/default/files/
name: nginx-php
enableServiceLinks: false
imagePullSecrets:
- name: lagoon-internal-registry-secret
priorityClassName: lagoon-priority-production
volumes:
- name: lagoon-sshkey
secret:
defaultMode: 420
secretName: lagoon-sshkey
- emptyDir: {}
name: nginx-php-twig
- name: nginx-php
persistentVolumeClaim:
claimName: nginx-php
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: nginx-php
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: nginx-php-persistent
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: nginx-php
lagoon.sh/service-type: nginx-php-persistent
lagoon.sh/template: nginx-php-persistent-0.1.0
name: nginx-php
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/instance: nginx-php
app.kubernetes.io/name: nginx-php-persistent
strategy: {}
template:
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/configMapSha: abcdefg1234567890
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: nginx-php
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: nginx-php-persistent
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: nginx-php
lagoon.sh/service-type: nginx-php-persistent
lagoon.sh/template: nginx-php-persistent-0.1.0
spec:
containers:
- env:
- name: NGINX_FASTCGI_PASS
value: 127.0.0.1
- name: LAGOON_GIT_SHA
value: "0000000000000000000000000000000000000000"
- name: CRONJOBS
- name: SERVICE_NAME
value: nginx-php
envFrom:
- configMapRef:
name: lagoon-env
image: harbor.example/example-project/main/nginx@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8
imagePullPolicy: Always
livenessProbe:
failureThreshold: 5
httpGet:
path: /nginx_status
port: 50000
initialDelaySeconds: 900
timeoutSeconds: 3
name: nginx
ports:
- containerPort: 8080
name: http
protocol: TCP
readinessProbe:
httpGet:
path: /nginx_status
port: 50000
initialDelaySeconds: 1
timeoutSeconds: 3
resources:
limits:
cpu: 100m
requests:
cpu: 50m
memory: 10Mi
securityContext: {}
volumeMounts:
- mountPath: /app/docroot/sites/default/files/
name: nginx-php
- env:
- name: NGINX_FASTCGI_PASS
value: 127.0.0.1
- name: LAGOON_GIT_SHA
value: "0000000000000000000000000000000000000000"
- name: SERVICE_NAME
value: nginx-php
envFrom:
- configMapRef:
name: lagoon-env
image: harbor.example/example-project/main/php@sha256:b2001babafaa8128fe89aa8fd11832cade59931d14c3de5b3ca32e2a010fbaa8
imagePullPolicy: Always
livenessProbe:
initialDelaySeconds: 60
periodSeconds: 10
tcpSocket:
port: 9000
name: php
ports:
- containerPort: 9000
name: php
protocol: TCP
readinessProbe:
initialDelaySeconds: 2
periodSeconds: 10
tcpSocket:
port: 9000
resources:
limits:
cpu: 200m
requests:
cpu: 20m
memory: 100Mi
securityContext: {}
volumeMounts:
- mountPath: /app/docroot/sites/default/files/
name: nginx-php
- mountPath: /app/docroot/sites/default/files//php
name: nginx-php-twig
enableServiceLinks: false
imagePullSecrets:
- name: lagoon-internal-registry-secret
priorityClassName: lagoon-priority-production
volumes:
- name: nginx-php
persistentVolumeClaim:
claimName: nginx-php
- emptyDir: {}
name: nginx-php-twig
status: {}
Loading

0 comments on commit 3d6a08c

Please sign in to comment.