Skip to content

Commit

Permalink
fix: Use kosko-charts azureProjectVolume.
Browse files Browse the repository at this point in the history
  • Loading branch information
gary-van-woerkens committed Jul 1, 2021
1 parent f54203f commit 5510bc5
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 39 deletions.
95 changes: 61 additions & 34 deletions .k8s/components/backend.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import env from "@kosko/env";
import { assert } from "@sindresorhus/is";
import { create } from "@socialgouv/kosko-charts/components/app";
import { addEnv } from "@socialgouv/kosko-charts/utils/addEnv";
import { getIngressHost } from "@socialgouv/kosko-charts/utils/getIngressHost";
import { getManifestByKind } from "@socialgouv/kosko-charts/utils/getManifestByKind";
// import { getHarborImagePath } from "@socialgouv/kosko-charts/utils/getHarborImagePath";
import { ok } from "assert";
import { Deployment } from "kubernetes-models/apps/v1/Deployment";
import { EnvVar } from "kubernetes-models/v1/EnvVar";
import { getManifests as getFrontendManifests } from "./frontend";
import environments from "@socialgouv/kosko-charts/environments"
import { azureProjectVolume } from "@socialgouv/kosko-charts/components/azure-storage/azureProjectVolume";
import { VolumeMount, Volume } from "kubernetes-models/v1";

type AnyObject = {
[any: string]: any;
Expand All @@ -36,6 +36,10 @@ export const getManifests = async () => {
const probesPath = "/healthz";
const subdomain = "domifa-api";

const ciEnv = environments(process.env);

const isDev = !(ciEnv.isPreProduction || ciEnv.isProduction);

const tag = process.env.CI_COMMIT_TAG
? process.env.CI_COMMIT_TAG.slice(1)
: process.env.CI_COMMIT_SHA
Expand All @@ -57,24 +61,42 @@ export const getManifests = async () => {
{}
);

const [persistentVolumeClaim, persistentVolume] = azureProjectVolume("domifa-resource", {
storage: "5Gi",
});

const uploadsVolume = new Volume({
name: "domifa-resource",
persistentVolumeClaim: { claimName: persistentVolumeClaim.metadata!.name! },
});

const uploadsVolumeMount = new VolumeMount({
mountPath: "/mnt/files",
name: "domifa-resource",
});

const emptyDir = new Volume({ name: "domifa-resource", emptyDir: {} });

const manifests = await create(name, {
env,
config: {
subdomain,
ingress: true,
withPostgres: true,
containerPort: 3000,
subDomainPrefix: process.env.PRODUCTION ? `fake-` : `${subdomain}-`,
subDomainPrefix: ciEnv.isProduction ? `fake-` : `${subdomain}-`,
},
deployment: {
image: `ghcr.io/socialgouv/domifa/backend:sha-${tag}`,
volumes: [isDev ? emptyDir : uploadsVolume],
container: {
volumeMounts: [
{
mountPath: "/mnt/files",
name: "domifa-volume",
},
],
volumeMounts: [uploadsVolumeMount],
// volumeMounts: [
// {
// mountPath: "/mnt/files",
// name: "domifa-volume",
// },
// ],
resources: {
requests: {
cpu: "50m",
Expand All @@ -90,7 +112,11 @@ export const getManifests = async () => {
},
});

return manifests;
return manifests.concat(
isDev
? []
: [persistentVolumeClaim, persistentVolume]
);
};

export default async () => {
Expand All @@ -102,6 +128,7 @@ export default async () => {
// const isDev = !isProductionCluster && !isPreProduction;

const manifests = await getManifests();

/* pass dynamic deployment URL as env var to the container */
//@ts-expect-error
const deployment = getManifestByKind(manifests, Deployment) as Deployment;
Expand All @@ -121,30 +148,30 @@ export default async () => {
},
});

const volumes = [
ciEnv.isPreProduction || ciEnv.isProduction
? {
name: "domifa-volume",
azureFile: {
readOnly: false,
shareName: "domifa-resource",
secretName: "azure-storage",
secretNamespace: "domifa-preprod",
},
}
: {
name: "domifa-volume",
emptyDir: {},
}
];

assert.object(deployment.spec);
assert.object(deployment.spec.template.spec);

deployment.spec.template.spec.volumes = [
...(deployment.spec.template.spec.volumes || []),
...volumes,
];
// const volumes = [
// ciEnv.isPreProduction || ciEnv.isProduction
// ? {
// name: "domifa-volume",
// azureFile: {
// readOnly: false,
// shareName: "domifa-resource",
// secretName: "azure-storage",
// secretNamespace: "domifa-preprod",
// },
// }
// : {
// name: "domifa-volume",
// emptyDir: {},
// }
// ];

// assert.object(deployment.spec);
// assert.object(deployment.spec.template.spec);

// deployment.spec.template.spec.volumes = [
// ...(deployment.spec.template.spec.volumes || []),
// ...volumes,
// ];

return manifests;
};
2 changes: 1 addition & 1 deletion .k8s/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dependencies": {
"@kosko/env": "^2.0.1",
"@kubernetes-models/sealed-secrets": "^1.6.3",
"@socialgouv/kosko-charts": "7.0.3",
"@socialgouv/kosko-charts": "7.0.4",
"@types/node": "^15.12.2",
"kosko": "^1.1.5",
"kubernetes-models": "^1.7.1",
Expand Down
8 changes: 4 additions & 4 deletions .k8s/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,10 @@
dependencies:
"@sinonjs/commons" "^1.7.0"

"@socialgouv/kosko-charts@7.0.3":
version "7.0.3"
resolved "https://registry.yarnpkg.com/@socialgouv/kosko-charts/-/kosko-charts-7.0.3.tgz#d9769fff3b7e84782c95d1cddb3318d7c6d929fb"
integrity sha512-961744wcYm4wijtYYABJofh2UX1oIl3UY44FG2I1L8W8+Ug7hAnYGCv7k6OIDY/4RMHy7FbA4sKcECyFgKjrcg==
"@socialgouv/kosko-charts@7.0.4":
version "7.0.4"
resolved "https://registry.yarnpkg.com/@socialgouv/kosko-charts/-/kosko-charts-7.0.4.tgz#1563ec4e8011a063cbccd83d406f91e7e6535aed"
integrity sha512-k3zCHP+S15+txc3fRdSocWW13wqInxJKjV88HRDkqKY1iAd5G94dMZxjNOuFSCUlzzpOVEDK2o2jUJvvv5iA+A==
dependencies:
"@sindresorhus/is" "^4.0.1"
fs-extra "^10.0.0"
Expand Down

0 comments on commit 5510bc5

Please sign in to comment.