From 315161c8d79b2ce3f63ef2d514fa194d16acbe9b Mon Sep 17 00:00:00 2001 From: Desoindx Date: Wed, 5 Jan 2022 17:34:50 +0100 Subject: [PATCH] Add a healthz route --- .../__tests__/__snapshots__/deploy.js.snap | 204 ------------------ .socialgouv/__tests__/deploy.js | 27 --- .socialgouv/config.json | 9 +- src/pages/healthz.ts | 7 + 4 files changed, 9 insertions(+), 238 deletions(-) delete mode 100644 .socialgouv/__tests__/__snapshots__/deploy.js.snap delete mode 100644 .socialgouv/__tests__/deploy.js create mode 100644 src/pages/healthz.ts diff --git a/.socialgouv/__tests__/__snapshots__/deploy.js.snap b/.socialgouv/__tests__/__snapshots__/deploy.js.snap deleted file mode 100644 index 7cafab6d..00000000 --- a/.socialgouv/__tests__/__snapshots__/deploy.js.snap +++ /dev/null @@ -1,204 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`deploy dev 2 1`] = ` -"--- -apiVersion: networking.k8s.io/v1 -kind: NetworkPolicy -metadata: - name: netpol-monpsy - namespace: monpsy -spec: - ingress: - - from: - - podSelector: {} - - from: - - namespaceSelector: - matchLabels: - network-policy/source: ingress-controller - - from: - - namespaceSelector: - matchLabels: - network-policy/source: monitoring - podSelector: {} - policyTypes: - - Ingress ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - kapp.k14s.io/disable-default-ownership-label-rules: '' - kapp.k14s.io/disable-default-label-scoping-rules: '' - app.github.com/job: '5678' - app.github.com/ref: refs/tags/v1.2.3 - app.github.com/repo: socialgouv/monpsy - app.github.com/run: '1234' - app.github.com/sha: '0123456' - labels: - app: app - application: monpsy - component: nginx - owner: monpsy - team: monpsy - name: app - namespace: monpsy -spec: - replicas: 1 - selector: - matchLabels: - app: app - template: - metadata: - annotations: - kapp.k14s.io/disable-default-ownership-label-rules: '' - kapp.k14s.io/disable-default-label-scoping-rules: '' - app.github.com/job: '5678' - app.github.com/ref: refs/tags/v1.2.3 - app.github.com/repo: socialgouv/monpsy - app.github.com/run: '1234' - app.github.com/sha: '0123456' - labels: - app: app - application: monpsy - component: nginx - owner: monpsy - team: monpsy - spec: - containers: - - image: ghcr.io/socialgouv/mon-psy-sante/app:1.2.3 - livenessProbe: - failureThreshold: 6 - httpGet: - path: /index.html - port: http - initialDelaySeconds: 30 - periodSeconds: 5 - timeoutSeconds: 5 - name: app - ports: - - containerPort: 80 - name: http - readinessProbe: - failureThreshold: 15 - httpGet: - path: /index.html - port: http - initialDelaySeconds: 0 - periodSeconds: 5 - successThreshold: 1 - timeoutSeconds: 1 - resources: - limits: - cpu: 500m - memory: 128Mi - requests: - cpu: 5m - memory: 32Mi - startupProbe: - failureThreshold: 12 - httpGet: - path: /index.html - port: http - periodSeconds: 5 ---- -apiVersion: v1 -kind: Service -metadata: - labels: - app: app - application: monpsy - component: nginx - owner: monpsy - team: monpsy - name: app - annotations: - kapp.k14s.io/disable-default-ownership-label-rules: '' - kapp.k14s.io/disable-default-label-scoping-rules: '' - app.github.com/job: '5678' - app.github.com/ref: refs/tags/v1.2.3 - app.github.com/repo: socialgouv/monpsy - app.github.com/run: '1234' - app.github.com/sha: '0123456' - namespace: monpsy -spec: - ports: - - name: http - port: 80 - targetPort: 80 - selector: - app: app - type: ClusterIP ---- -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - annotations: - kubernetes.io/ingress.class: nginx - cert-manager.io/cluster-issuer: letsencrypt-prod - kubernetes.io/tls-acme: 'true' - kapp.k14s.io/disable-default-ownership-label-rules: '' - kapp.k14s.io/disable-default-label-scoping-rules: '' - app.github.com/job: '5678' - app.github.com/ref: refs/tags/v1.2.3 - app.github.com/repo: socialgouv/monpsy - app.github.com/run: '1234' - app.github.com/sha: '0123456' - nginx.ingress.kubernetes.io/configuration-snippet: >- - more_set_headers \\"Content-Security-Policy: default-src 'none'; connect-src - 'self' https://*.gouv.fr https://services.sarbacane.com; font-src 'self' - data:; img-src 'self' data: https://forms.sbc08.com; prefetch-src 'self' - https://*.gouv.fr; script-src 'self' https://*.gouv.fr - https://*.sbc08.com; frame-src 'self' https://*.gouv.fr; style-src 'self' - 'unsafe-inline'\\"; - - more_set_headers \\"X-Frame-Options: deny\\"; - - more_set_headers \\"X-XSS-Protection: 1; mode=block\\"; - - more_set_headers \\"X-Content-Type-Options: nosniff\\"; - labels: - app: app - application: monpsy - component: nginx - owner: monpsy - team: monpsy - name: app - namespace: monpsy -spec: - rules: - - host: monpsy.fabrique.social.gouv.fr - http: - paths: - - backend: - service: - name: app - port: - name: http - path: / - pathType: Prefix - tls: - - hosts: - - monpsy.fabrique.social.gouv.fr - secretName: app-crt ---- -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - annotations: - kubernetes.io/ingress.class: nginx - nginx.ingress.kubernetes.io/permanent-redirect: https://monpsy.sante.gouv.fr$request_uri - cert-manager.io/cluster-issuer: letsencrypt-prod - kubernetes.io/tls-acme: 'true' - labels: - app.kubernetes.io/component: redirect - app.kubernetes.io/name: www - name: monpsy-redirect -spec: - rules: - - host: www.monpsy.sante.gouv.fr - tls: - - hosts: - - www.monpsy.sante.gouv.fr - secretName: monpsy-redirect -" -`; diff --git a/.socialgouv/__tests__/deploy.js b/.socialgouv/__tests__/deploy.js deleted file mode 100644 index e2acd108..00000000 --- a/.socialgouv/__tests__/deploy.js +++ /dev/null @@ -1,27 +0,0 @@ -import util from "util"; -import { directory } from "tempy"; -import { project } from "@socialgouv/kosko-charts/testing/fake/github-actions.env"; - -const exec = util.promisify(require("child_process").exec); - -jest.setTimeout(1000 * 60); - -test("deploy dev 2", async () => { - const dir = directory(); - const env = project("monpsy").prod; - - env.SOCIALGOUV_CONFIG_PATH = `${dir}/autodevops/config.json`; - - Object.assign(process.env, env); - - const cmd = ` - npx degit SocialGouv/kosko-charts/templates/autodevops ${dir}/autodevops; \ - yarn --cwd ${dir}/autodevops --silent; \ - cp -r ${__dirname}/../environments ${__dirname}/../config.json ${dir}/autodevops/; \ - yarn --cwd ${dir}/autodevops --silent generate --env prod - `; - - const { stdout: manifest } = await exec(cmd, { env: process.env }); - - expect(manifest).toMatchSnapshot(); -}); diff --git a/.socialgouv/config.json b/.socialgouv/config.json index 81237a9a..9bf86829 100644 --- a/.socialgouv/config.json +++ b/.socialgouv/config.json @@ -1,12 +1,7 @@ { "name": "app", - "type": "static", + "type": "app", "subdomain": "monpsy", "registry": "ghcr", - "project": "mon-psy-sante", - "ingress": { - "annotations": { - "nginx.ingress.kubernetes.io/configuration-snippet": "more_set_headers \"Content-Security-Policy: default-src 'none'; connect-src 'self' https://*.gouv.fr https://services.sarbacane.com; font-src 'self' data:; img-src 'self' data: https://forms.sbc08.com; prefetch-src 'self' https://*.gouv.fr; script-src 'self' https://*.gouv.fr https://*.sbc08.com; frame-src 'self' https://*.gouv.fr; style-src 'self' 'unsafe-inline'\";\nmore_set_headers \"X-Frame-Options: deny\";\nmore_set_headers \"X-XSS-Protection: 1; mode=block\";\nmore_set_headers \"X-Content-Type-Options: nosniff\";" - } - } + "project": "mon-psy-sante" } diff --git a/src/pages/healthz.ts b/src/pages/healthz.ts new file mode 100644 index 00000000..e8c13478 --- /dev/null +++ b/src/pages/healthz.ts @@ -0,0 +1,7 @@ +import { NextApiRequest, NextApiResponse } from "next"; + +const healthz = async (req: NextApiRequest, res: NextApiResponse) => { + return res.status(200); +}; + +export default healthz;