Skip to content

Commit

Permalink
Updated & pipeline and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
changesbyjames committed Nov 15, 2024
1 parent 8ba7d1b commit 04113ea
Show file tree
Hide file tree
Showing 7 changed files with 5,585 additions and 7,121 deletions.
2 changes: 1 addition & 1 deletion census/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@azure/msal-browser": "^3.21.0",
"@hookform/resolvers": "^3.9.0",
"@microsoft/applicationinsights-react-js": "^17.3.1",
"@microsoft/applicationinsights-web": "^3.3.1",
"@microsoft/applicationinsights-web": "^3.3.4",
"@radix-ui/react-dialog": "^1.1.2",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-popover": "^1.1.1",
Expand Down
2 changes: 1 addition & 1 deletion census/website/src/layouts/sidebars/Achivements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const Achievements = () => {

return (
<motion.div
className="flex flex-col fixed md:relative right-2 top-2 bottom-2 md:top-auto md:bottom-auto md:right-auto antialiased"
className="flex flex-col z-10 fixed md:relative right-2 top-2 bottom-2 md:top-auto md:bottom-auto md:right-auto antialiased"
animate={{ width: open ? '16rem' : '0' }}
transition={{ ease: 'backInOut', duration: 0.4 }}
>
Expand Down
8 changes: 8 additions & 0 deletions infrastructure/pulumi/Pulumi.prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
config:
azure-native:location: northcentralus
census:image: ghcr.io/alveusgg/census:main-11799584669-census-api
census:jwt-secret:
secure: AAABAFFLzowgnCldcwYtWAiYrmvn6ktctistnnFHDlFf7U79Tpb0I/YSY6bMXNhfXmQmXqVXqkFGtfZ40rkOK8d3ukXcX2ZniYw87o+YAnfu0hvTPI4Iy+Hh4a3M8g7rC/k5bMPOsMkxJxd0XQ0+pfHVMEaA/uo91WtrNqYPoQ39itEAY8KSgUksfEfTTvmQcY1jg4H4sRAigfz59o9lZw==
census:twitch-client-id: itag8f5m4r3ynbtrz933d7qh7c6ffq
census:twitch-client-secret:
secure: AAABAET+mgAA+bu+Y2jmX/ENpvnBHc2pquz7h75I2MiZWvQ5zWXD19ainH3I8ZosE1dSTuoFJGWTghHzMmE=
4 changes: 0 additions & 4 deletions infrastructure/pulumi/Pulumi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,3 @@ runtime:
options:
packagemanager: pnpm
description: A minimal Azure Native TypeScript Pulumi program
config:
pulumi:tags:
value:
pulumi:template: azure-typescript
79 changes: 66 additions & 13 deletions infrastructure/pulumi/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Component, IngestionMode } from '@pulumi/azure-native/insights';
import { getSharedKeysOutput, GetSharedKeysResult, Workspace } from '@pulumi/azure-native/operationalinsights';
import { ResourceGroup } from '@pulumi/azure-native/resources';
import { Config, getProject, getStack } from '@pulumi/pulumi';
import { Config, getProject, getStack, interpolate } from '@pulumi/pulumi';

import { ManagedEnvironment, ManagedEnvironmentsStorage } from '@pulumi/azure-native/app';
import { API } from './resources/API';

import { Endpoint, QueryStringCachingBehavior } from '@pulumi/azure-native/cdn';
import { Configuration, Database } from '@pulumi/azure-native/dbforpostgresql';
import {
BlobContainer,
Expand All @@ -23,7 +24,7 @@ import { Website } from './resources/Website';
const project = getProject();
const stack = getStack();
const id = `${project}-${stack}`;
const simpleId = `cc${stack}`;
const simpleId = `apc${stack}`;

// MARK: Config
const config = new Config();
Expand Down Expand Up @@ -95,7 +96,7 @@ export = async () => {
accountName: storage.name
});

const environmentStorage = new ManagedEnvironmentsStorage(`${simpleId}-stge`, {
const environmentCacheStorage = new ManagedEnvironmentsStorage(`${simpleId}-cache`, {
resourceGroupName: group.name,
environmentName: environment.name,
properties: {
Expand Down Expand Up @@ -139,6 +140,7 @@ export = async () => {
resourceGroupName: group.name,
environmentName: environment.name,
port: 3000,
size: 'regular',
env: {
HOST: '0.0.0.0',
PORT: '3000',
Expand All @@ -155,31 +157,82 @@ export = async () => {
JWT_SECRET: config.require('jwt-secret'),
TWITCH_CLIENT_ID: config.require('twitch-client-id'),
TWITCH_CLIENT_SECRET: config.require('twitch-client-secret'),
TWITCH_USERNAME: config.require('twitch-username'),
UI_URL: `https://${config.require('ui-domain')}`,
API_URL: `https://${config.require('api-domain')}`,

CHANNELS_TO_LISTEN_TO: 'alveussanctuary,alveusgg,strangecyan',
// UI_URL: `https://${config.require('ui-domain')}`,

STORAGE_ACCOUNT_NAME: storage.name,
STORAGE_ACCOUNT_KEY: key,
CONTAINER_NAME: container.name
},
image: config.require('api-image'),
volumes: {
dragonfly: {
path: '/data',
storage: environmentCacheStorage
}
},
image: config.require('image'),
scale: {
min: 1,
min: 0,
max: 1,
noOfRequestsPerInstance: 100
}
},
sidecars: [
{
name: 'dragonfly-cache',
image: 'docker.dragonflydb.io/dragonflydb/dragonfly:latest',
volumes: {
dragonfly: {
path: '/data',
storage: environmentCacheStorage
}
},
env: {}
}
]
});

const imageOptimisation = new API(`${id}-ipx`, {
name: 'ipx',
resourceGroupName: group.name,
environmentName: environment.name,
env: {},
image: 'node:22',
command: [
interpolate`IPX_HTTP_DOMAINS=${storage.name}.blob.core.windows.net IPX_HTTP_MAX_AGE=86400 npx --yes ipx serve --port 3000 --host 0.0.0.0`
],
size: 'micro',
scale: {
min: 0,
max: 1,
noOfRequestsPerInstance: 50
},
port: 3000
});

const imageOptimisationEndpoint = new Endpoint(`${id}-ipx-cdn`, {
endpointName: `${id}-ipx-cdn`,
location: 'global',
isHttpAllowed: false,
isHttpsAllowed: true,
originHostHeader: imageOptimisation.defaultHost,
origins: [
{
hostName: imageOptimisation.defaultHost,
httpsPort: 443,
name: 'origin-image-optimisation'
}
],
profileName: website.profileName,
queryStringCachingBehavior: QueryStringCachingBehavior.IgnoreQueryString,
resourceGroupName: group.name
});

// MARK: Backstage
const backstage = new BackstageConfiguration(`${id}-backstage`, {
...website,
env: {
variables: {
apiBaseUrl: `https://${config.require('api-domain')}`,
imageResizeCDNUrl: config.require('image-resize-cdn-url'),
apiBaseUrl: api.defaultUrl,
ipxBaseUrl: imageOptimisationEndpoint.hostName.apply(host => `https://${host}`),
appInsightsConnectionString: appInsights.connectionString
},
flags: {}
Expand Down
26 changes: 20 additions & 6 deletions infrastructure/pulumi/resources/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface RawContainerArgs {
name: string;
image: string;
env: Record<string, string | Input<string>>;
volumes?: Record<string, Volume>;
}

interface Volume {
Expand All @@ -39,6 +40,8 @@ interface APIArgs {

env: Record<string, string | Input<string>>;
image: Image | string;
command?: Input<string>[];
size: Size;

vaults?: Vault[];

Expand Down Expand Up @@ -93,6 +96,7 @@ const getSidecarContainers = (sidecars?: RawContainerArgs[]) => {
};
})
],
volumeMounts: getVolumeMounts(sidecar.volumes),
resources: {
cpu: 1,
memory: '2.0Gi'
Expand Down Expand Up @@ -136,10 +140,20 @@ const getCustomDomains = (
];
};

type Size = 'micro' | 'regular' | 'large';

const getResources = (size: Size) => {
if (size === 'micro') return { cpu: 0.25, memory: '0.5Gi' };
if (size === 'regular') return { cpu: 1, memory: '2.0Gi' };
if (size === 'large') return { cpu: 2, memory: '4.0Gi' };
throw new Error(`Unknown size: ${size}`);
};

export class API extends ComponentResource {
public readonly resourceGroupName: Input<string>;
public readonly environmentName: Input<string>;
public readonly defaultUrl: Output<string>;
public readonly defaultHost: Output<string>;
public readonly identity: Output<SystemAssignedIdentity>;

constructor(id: string, args: APIArgs, opts?: ResourceOptions) {
Expand Down Expand Up @@ -190,10 +204,7 @@ export class API extends ComponentResource {
{
name: args.name,
image: getName(args.image),
resources: {
cpu: 1,
memory: '2.0Gi'
},
resources: getResources(args.size),
env: [
...Object.entries(args.env).map(([name, value]) => {
return {
Expand All @@ -207,7 +218,8 @@ export class API extends ComponentResource {
},
...(args.port ? [{ name: 'PORT', value: args.port.toString() }] : [])
],
volumeMounts: getVolumeMounts(args.volumes)
volumeMounts: getVolumeMounts(args.volumes),
command: args.command
},
...getSidecarContainers(args.sidecars)
],
Expand All @@ -232,11 +244,13 @@ export class API extends ComponentResource {
{ parent: this }
);

const defaultUrl = interpolate`https://${api.name}.${environment.defaultDomain}`;
const defaultHost = interpolate`${api.name}.${environment.defaultDomain}`;
const defaultUrl = interpolate`https://${defaultHost}`;

this.resourceGroupName = args.resourceGroupName;
this.environmentName = environment.name;
this.defaultUrl = defaultUrl;
this.defaultHost = defaultHost;
this.identity = api.identity.apply(i => {
if (!i) throw new Error('No identity found');
if (i.type !== 'SystemAssigned') throw new Error('Identity is not system assigned');
Expand Down
Loading

0 comments on commit 04113ea

Please sign in to comment.