diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index dd39713..68154e8 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -83,6 +83,18 @@ jobs: cache-from: type=registry,ref=ghcr.io/${{ env.REPO }}:buildcache cache-to: type=registry,ref=ghcr.io/${{ env.REPO }}:buildcache,mode=max + - name: Build and push integration tests docker image + uses: docker/build-push-action@v3 + with: + context: . + file: ./jest.integration.Dockerfile + push: true + tags: | + ghcr.io/${{ env.REPO }}-integration-tests:pr-${{ github.event.pull_request.number }}-${{ github.sha }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=ghcr.io/${{ env.REPO }}-integration-tests:buildcache + cache-to: type=registry,ref=ghcr.io/${{ env.REPO }}-integration-tests:buildcache,mode=max + - name: Setup Helm uses: azure/setup-helm@v3 diff --git a/.github/workflows/publish-and-promote.yaml b/.github/workflows/publish-and-promote.yaml index 9b23805..93aaaaa 100644 --- a/.github/workflows/publish-and-promote.yaml +++ b/.github/workflows/publish-and-promote.yaml @@ -56,6 +56,18 @@ jobs: cache-from: type=registry,ref=ghcr.io/${{ env.REPO }}:buildcache cache-to: type=registry,ref=ghcr.io/${{ env.REPO }}:buildcache,mode=max + - name: Build and push integration tests docker image + uses: docker/build-push-action@v3 + with: + context: . + file: ./jest.integration.Dockerfile + push: true + tags: | + ghcr.io/${{ env.REPO }}-integration-tests:${{ github.ref_name }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=ghcr.io/${{ env.REPO }}-integration-tests:buildcache + cache-to: type=registry,ref=ghcr.io/${{ env.REPO }}-integration-tests:buildcache,mode=max + promote: needs: publish runs-on: ubuntu-latest diff --git a/__tests__/integration/test.ts b/__tests__/integration/test.ts index 979a314..2825f3b 100644 --- a/__tests__/integration/test.ts +++ b/__tests__/integration/test.ts @@ -108,7 +108,7 @@ describe("todo model integration tests", () => { } ); - expect(initializeTodoResponse.status).toBe(201); + expect(initializeTodoResponse.status).toBe(200); expect(initializeTodoResponse.data.id).toBeDefined(); expect(initializeTodoResponse.data.todo).toBe("integration tests"); @@ -123,6 +123,6 @@ describe("todo model integration tests", () => { } ); - expect(completeTodoResponse.status).toBe(201); + expect(completeTodoResponse.status).toBe(200); }); }); diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 13b0c09..2dd1ee6 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,4 +2,4 @@ apiVersion: v1 description: A Helm chart for Kubernetes icon: https://raw.githubusercontent.com/jenkins-x/jenkins-x-platform/d273e09/images/nodejs.png name: example-todo-model-service -version: 0.1.0-SNAPSHOT +version: 0.0.0-dev diff --git a/helm/templates/integration-tests-role.yaml b/helm/templates/integration-tests-role.yaml index 2c7a267..8ade947 100644 --- a/helm/templates/integration-tests-role.yaml +++ b/helm/templates/integration-tests-role.yaml @@ -1,9 +1,12 @@ {{- if .Values.local }} {{- else }} +{{- if .Values.runIntegrationTests }} apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: {{ .Values.service.name }}-integration-tests + annotations: + argocd.argoproj.io/sync-wave: "-1" rules: - apiGroups: - "" @@ -26,4 +29,5 @@ rules: - get - list - watch +{{- end }} {{- end }} \ No newline at end of file diff --git a/helm/templates/integration-tests-rolebinding.yaml b/helm/templates/integration-tests-rolebinding.yaml index 8c880ae..92692bf 100644 --- a/helm/templates/integration-tests-rolebinding.yaml +++ b/helm/templates/integration-tests-rolebinding.yaml @@ -1,9 +1,12 @@ {{- if .Values.local }} {{- else }} +{{- if .Values.runIntegrationTests }} apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: {{ .Values.service.name }}-integration-tests + annotations: + argocd.argoproj.io/sync-wave: "-1" roleRef: apiGroup: rbac.authorization.k8s.io kind: Role @@ -12,3 +15,4 @@ subjects: - kind: ServiceAccount name: {{ .Values.service.name }}-integration-tests {{- end }} +{{- end }} diff --git a/helm/templates/integration-tests-sa.yaml b/helm/templates/integration-tests-sa.yaml index 56e1d0b..8d212f6 100644 --- a/helm/templates/integration-tests-sa.yaml +++ b/helm/templates/integration-tests-sa.yaml @@ -1,7 +1,15 @@ {{- if .Values.local }} {{- else }} +{{- if .Values.runIntegrationTests }} apiVersion: v1 kind: ServiceAccount metadata: name: {{ .Values.service.name }}-integration-tests + annotations: + argocd.argoproj.io/sync-wave: "-1" +{{- if .Values.imagePullSecrets }} +imagePullSecrets: + - name: {{ .Values.imagePullSecrets }} +{{- end }} +{{- end }} {{- end }} \ No newline at end of file diff --git a/helm/templates/integration-tests.yaml b/helm/templates/integration-tests.yaml index 0ad7f34..94395de 100644 --- a/helm/templates/integration-tests.yaml +++ b/helm/templates/integration-tests.yaml @@ -4,11 +4,11 @@ apiVersion: batch/v1 kind: Job metadata: - name: {{ .Values.service.name }}-integration-tests-{{ lower .Values.image.tag }} + name: {{ .Values.service.name }}-itest-{{ .Values.image.tag | substr 0 11 | lower }} labels: chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" annotations: - argocd.argoproj.io/sync-wave: "2" + argocd.argoproj.io/hook: PostSync spec: template: metadata: @@ -17,13 +17,6 @@ spec: spec: serviceAccountName: {{ .Values.service.name }}-integration-tests initContainers: - - name: wait-for-resources - image: bitnami/kubectl:1.24 - command: [ - 'sh', - '-c', - "kubectl wait --for=condition=ready pod --selector=cluster-name={{ .Values.sourced.psql.name }} --timeout=600s -n {{ .Release.Namespace }}; REVISION=`kubectl get revisions -n {{ .Release.Namespace }} | grep example-hasura-0 | tail -1 | awk '$1 {print$1}-deployment'`; kubectl rollout status -n {{ .Release.Namespace }} deployment $REVISION-deployment" - ] - name: wait-for-new-revision image: bitnami/kubectl:1.24 command: ['sh', '-c', "REVISION=`kubectl get revisions -n {{ .Release.Namespace }} | tail -1 | awk '$1 {print$1}-deployment'`; kubectl rollout status -n {{ .Release.Namespace }} deployment $REVISION-deployment"] diff --git a/helm/templates/ksvc.yaml b/helm/templates/ksvc.yaml index 58e14c4..06fe2fc 100755 --- a/helm/templates/ksvc.yaml +++ b/helm/templates/ksvc.yaml @@ -11,7 +11,7 @@ metadata: {{ toYaml .Values.service.labels | indent 4 }} {{- end }} annotations: - argocd.argoproj.io/sync-wave: "1" + argocd.argoproj.io/sync-wave: "0" spec: template: metadata: diff --git a/helm/values.yaml b/helm/values.yaml index 3e742f0..a7c6a05 100755 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -8,67 +8,28 @@ podAnnotations: {} podsLabels: {} # Add labels to the deployment deploymentLabels: {} - image: repository: ghcr.io/cloudnativeentrepreneur/example-todo-model-service tag: latest pullPolicy: IfNotPresent - # define environment variables here as a map of key: value env: - -runIntegrationTests: false +runIntegrationTests: true # enable this flag to use knative serve to deploy the app knativeDeploy: true knative: minScale: 1 maxScale: 1 concurrencyTarget: 100 - local: false localKnativeSubscriber: http://host.docker.internal:5002 localKnativeDlqSubscriber: http://host.docker.internal:3999 - -# HorizontalPodAutoscaler -hpa: - enabled: false - minReplicas: 2 - maxReplicas: 6 - cpuTargetAverageUtilization: 80 - memoryTargetAverageUtilization: 80 - # Add labels to the HPA - labels: {} - -# Canary deployments -# If enabled, Istio and Flagger need to be installed in the cluster -canary: - enabled: false - progressDeadlineSeconds: 60 - analysis: - interval: "1m" - threshold: 5 - maxWeight: 60 - stepWeight: 20 - # WARNING: Canary deployments will fail and rollback if there is no traffic that will generate the below specified metrics. - metrics: - latency: - threshold: 500 - interval: "1m" - # The host is using Istio Gateway or the underlying ingress mechanism - # This value is defaulted from the environments jx-requirements.yml ingress configuration - host: "" - # Add labels to the canary - labels: {} - # Add labels to the canary gateway - gatewayLabels: {} - service: name: example-todo-model-service type: ClusterIP internalPort: 5002 externalPort: 80 annotations: {} - # Add labels to the service labels: {} resources: limits: @@ -88,47 +49,9 @@ readinessProbe: periodSeconds: 1 successThreshold: 1 timeoutSeconds: 1 - sourced: psql: name: example-sourced-db-postgresql hostname: example-sourced-db-postgresql -# custom ingress annotations on this service -ingress: - annotations: {} - # defaults to nginx if no other ingress class annotation specified - classAnnotation: "" - # Add labels to the ingress - labels: {} - - # ingress path type - pathType: ImplementationSpecific - -serviceAccount: - enabled: true - name: "" - annotations: {} -# iam.gke.io/gcp-service-account: my-sa-in-gke - # Add labels to the SA - labels: {} -# my-custom-label: value - -# values we use from the `jx-requirements.yml` file if we are using helmfile and helm 3 -jxRequirements: - ingress: - # shared ingress annotations on all services - annotations: {} - # kubernetes.io/ingress.class: nginx - - apiVersion: "networking.k8s.io/v1" - # the domain for hosts - domain: "" - externalDNS: false - namespaceSubDomain: -jx. - serviceType: "" - tls: - email: "" - enabled: false - production: false - secretName: "" +imagePullSecrets: ghcr \ No newline at end of file diff --git a/preview/helm/templates/app.yaml b/preview/helm/templates/app.yaml index 8bd2e2a..fa00234 100644 --- a/preview/helm/templates/app.yaml +++ b/preview/helm/templates/app.yaml @@ -18,6 +18,9 @@ spec: values: | image: tag: {{ .Values.tag }} + env: + EXAMPLE_HASURA_PROJECTIONS_URL: http://example-hasura-projections-service.example-prod-env.svc.cluster.local + TODO_EVENTS_BROKER_URL: "http://broker-ingress.knative-eventing.svc.cluster.local/example-prod-env/todo-events" destination: namespace: {{ .Values.repository.name }}-{{ .Values.pr }}-preview server: https://kubernetes.default.svc