Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deploy tts #78

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions dev/create-harbor-pull-secret.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/sh

set -e

harbor_credential_path="$1"

function get_docker_credentials() {
local harbor_credential_path="$1"

local username="$(yq -r '.name' -oj "$harbor_credential_path")"
local secret="$(yq -r '.secret' -oj "$harbor_credential_path")"
echo "$username:$secret"
}

credentials="$(get_docker_credentials "$harbor_credential_path")"
encoded_credentials="$(echo -n "$credentials" | base64)"

auth_settings=$(cat <<EOF
{
"auths": {
"registry.niaefeup.pt": {
"auth": "$encoded_credentials"
}
}
}
EOF
)

encoded_auth_settings="$(echo "$auth_settings" | base64 -w 0)"

cat <<EOF
---
kind: Secret
apiVersion: v1
metadata:
namespace: <FILL-IN>
name: harbor-pull-secret
annotations:
replicator.v1.mittwald.de/replicate-to: "<FILL-IN>"
type: kubernetes.io/dockerconfigjson
data:
.dockerconfigjson: $encoded_auth_settings
EOF
19 changes: 12 additions & 7 deletions services/databases/postgresql/cnpg-cluster.yaml
LuisDuarte1 marked this conversation as resolved.
Show resolved Hide resolved
LuisDuarte1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ metadata:
spec:
instances: 3

bootstrap:
initdb:
database: tts-db
owner: tts
secret:
name: tts-secret

LuisDuarte1 marked this conversation as resolved.
Show resolved Hide resolved
managed:
roles:
- name: ni
Expand All @@ -33,6 +26,18 @@ spec:
login: true
passwordSecret:
name: sinf-website-2023-secret
- name: tts
ensure: present
createdb: false
login: true
passwordSecret:
name: tts-secret
- name: tts-staging
ensure: present
createdb: false
login: true
passwordSecret:
name: tts-staging-secret

storage:
size: 10Gi
Expand Down
9 changes: 9 additions & 0 deletions services/databases/postgresql/cnpg-secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ metadata:
type: kubernetes.io/basic-auth
---
apiVersion: v1
stringData:
password: <FILL-IN>
username: tts-staging
kind: Secret
metadata:
name: tts-staging-secret
type: kubernetes.io/basic-auth
---
apiVersion: v1
stringData:
password: <FILL-IN>
username: ni
Expand Down
1 change: 1 addition & 0 deletions services/pulumi/niployments/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// ementas is an example pulumi service
// import "./services/ementas/index.js";
import "./services/tts/index.js";

import { CommitSignal } from "./utils/pending.js";
CommitSignal.globalParent.resolve();
104 changes: 104 additions & 0 deletions services/pulumi/niployments/services/tts/common/backend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
import { Prefixer } from "#utils/prefixer.js";

export class TTSBackend extends pulumi.ComponentResource {
public readonly name: pulumi.Output<string>;
public readonly port = pulumi.output(80);

constructor(
name: string,
args: {
namespace: pulumi.Input<string>;
branch: pulumi.Input<"main" | "develop">;
envSecretRef: pulumi.Input<string>;
},
opts?: pulumi.ComponentResourceOptions,
) {
super("niployments:tts:TTSBackend", name, opts);

const prefixer = new Prefixer(name);

const backendLabels = { app: "tts-backend" };
const backendPort = 8000;

const deployment = new k8s.apps.v1.Deployment(
prefixer.deployment(),
{
metadata: {
namespace: args.namespace,
},
spec: {
replicas: 1,
selector: {
matchLabels: backendLabels,
},
template: {
metadata: {
labels: backendLabels,
},
spec: {
containers: [
{
name: "tts-be",
image: pulumi.interpolate`registry.niaefeup.pt/niaefeup/tts-be:${args.branch}`,
imagePullPolicy: "Always",
resources: {
limits: {
memory: "128Mi",
cpu: "500m",
},
},
ports: [
{
containerPort: backendPort,
},
],
envFrom: [
{
secretRef: {
name: args.envSecretRef,
},
},
],
},
],
imagePullSecrets: [
{
name: "harbor-pull-secret",
},
],
},
},
},
},
{ parent: this },
);

const service = new k8s.core.v1.Service(
prefixer.service(),
{
metadata: {
namespace: args.namespace,
},
spec: {
ports: [
{
port: this.port,
targetPort: backendPort,
},
],
selector: backendLabels,
},
},
{ parent: this, dependsOn: [deployment] },
);

this.name = service.metadata.name;

this.registerOutputs({
serviceName: this.name,
servicePort: this.port,
});
}
}
96 changes: 96 additions & 0 deletions services/pulumi/niployments/services/tts/common/frontend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
import { Prefixer } from "#utils/prefixer.js";

export class TTSFrontend extends pulumi.ComponentResource {
public readonly name: pulumi.Output<string>;
public readonly port = pulumi.output(80);

constructor(
name: string,
args: {
namespace: pulumi.Input<string>;
branch: pulumi.Input<"main" | "develop">;
},
opts?: pulumi.ComponentResourceOptions,
) {
super("niployments:tts:TTSFrontend", name, opts);

const prefixer = new Prefixer(name);

const frontendLabels = { app: "tts-frontend" };
const frontendPort = 80;

const deployment = new k8s.apps.v1.Deployment(
prefixer.deployment(),
{
metadata: {
namespace: args.namespace,
},
spec: {
replicas: 1,
selector: {
matchLabels: frontendLabels,
},
template: {
metadata: {
labels: frontendLabels,
},
spec: {
containers: [
{
name: "tts-fe",
image: pulumi.interpolate`registry.niaefeup.pt/niaefeup/tts-fe:${args.branch}`,
imagePullPolicy: "Always",
resources: {
limits: {
memory: "128Mi",
cpu: "500m",
},
},
ports: [
{
containerPort: frontendPort,
},
],
},
],
imagePullSecrets: [
{
name: "harbor-pull-secret",
},
],
},
},
},
},
{ parent: this },
);

const service = new k8s.core.v1.Service(
prefixer.service(),
{
metadata: {
namespace: args.namespace,
},
spec: {
ports: [
{
port: this.port,
targetPort: frontendPort,
},
],
selector: frontendLabels,
},
},
{ parent: this, dependsOn: [deployment] },
);

this.name = service.metadata.name;

this.registerOutputs({
serviceName: this.name,
servicePort: this.port,
});
}
}
2 changes: 2 additions & 0 deletions services/pulumi/niployments/services/tts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// import "./production/index.js";
import "./staging/index.js";
Loading
Loading