Skip to content

infoxchange/make-it-so

Repository files navigation

Make It So

NPM Version

A helpful little library that allows you to deploy apps on Infoxchange's (IX) infrastructure without having to specify all the implementation details that are specific to IX's deployment environment. You tell it what you want and it will worry about making it happen. Most of the heavily lifting is done by SST which is extending to take care the IX related specifics.

Installation

# NPM
npm --save-dev @infoxchange/make-it-so
# Yarn
yarn add --dev @infoxchange/make-it-so

Features

deployConfig

The IX pipeline provides certain information about the deployment currently in progress via environment variables. deployConfig gives you a friendly (and typed) way to access these details.

import deployConfig from "@infoxchange/make-it-so/deployConfig";

if (deployConfig.isIxDeploy) {
  console.log(
    `Deploying ${deployConfig.appName} into ${deployConfig.environment}`,
  );
} else {
  console.log(`Not deploying via the IX deploy pipeline`);
}
Name Description Type for IX Deploy Type for non-IX Deploy
isIxDeploy Is deploying via IX pipeline or not true false
appName Name of app being deployed string undefined
environment Name of env app is being deployed to string undefined
workloadGroup The workload group of the app string undefined
primaryAwsRegion AWS Region used by IX string undefined
siteDomains Domains to be used by the app string[] []

CDK Construct - IxNextjsSite

Deploys a serverless instance of a Next.js. IxNextjsSite extends SST's NextjsSite and takes the exact same props.

It will automatically create certificates and DNS records for any custom domains given (including alternative domain names which SST doesn't currently do). If the props customDomain is not set the first site domain provided by the IX deployment pipeline will be used as the primary custom domain and if there is more than one domain the rest will be used as alternative domain names. Explicitly setting customDomain to undefined will ensure no customDomain is used.

It will also automatically attach the site to the standard IX VPC created in each workload account (unless you explicitly pass other VPC details or set the VPC-related props (see the SST doco) to undefined).

import { IxNextjsSite } from "@infoxchange/make-it-so/cdk-constructs";

const site = new IxNextjsSite(stack, "Site", {
  environment: {
    DATABASE_URL: process.env.DATABASE_URL || "",
    SESSION_SECRET: process.env.SESSION_SECRET || "",
  },
  // Included by default:
  // customDomain: {
  //   domainName: ixDeployConfig.siteDomains[0],
  //   alternateNames: ixDeployConfig.siteDomains.slice(1)
  // },
});

CDK Construct - IxElasticache

Deploys an AWS Elasticache cluster, either the redis or the memcached flavour.

It will also automatically attach the cluster to the standard IX VPC created in each workload account (unless you explicitly pass a different VPC to be attached with the vpc prop or set the vpc prop to undefined which will stop any VPC being attached).

import { IxElasticache } from "@infoxchange/make-it-so/cdk-constructs";

const redisCluster = new IxElasticache(stack, "elasticache", {
  autoMinorVersionUpgrade: true,
  cacheNodeType: "cache.t2.small",
  engine: "redis",
  numCacheNodes: 1,
});

Options:

Prop Type Description
vpc IVpc (optional) A VPC to attach if not using default IX VPC
vpcSubnetIds string[] (optional) List of IDs of subnets to be used if not using default IX VPC subnets
[...CfnCacheClusterProps] Any props accepted by CfnCacheCluster

Properties:

Properties Type Description
connectionString string A string with all the details required to connect to the cluster
cluster CfnCacheCluster An AWS CDK CfnCacheCluster instance

CDK Construct - IxCertificate

Creates a new DNS validated ACM certificate for a domain managed by IX.

import { IxCertificate } from "@infoxchange/make-it-so/cdk-constructs";

const domainCert = new IxCertificate(scope, "ExampleDotComCertificate", {
  domainName: "example.com",
  subjectAlternativeNames: ["other-domain.com"],
  region: "us-east-1",
});

Options:

Prop Type Description
domainName string Domain name for cert
subjectAlternativeNames string[] (optional) Any domains for the certs "Subject Alternative Name"
region string (optional) The AWS region to create the cert in

CDK Construct - IxDnsRecord

Creates a DNS record for a domain managed by IX. Route53 HostedZones for IX managed domains live in the dns-hosting AWS account so if a workload AWS account requires a DNS record to be created this must be done "cross-account". IxDnsRecord handles that part for you. Just give it the details for the DNS record itself and IxDnsRecord will worry about creating it.

import { IxDnsRecord } from "@infoxchange/make-it-so/cdk-constructs";

new IxDnsRecord(scope, "IxDnsRecord", {
  type: "A",
  name: "example.com",
  value: "1.1.1.1",
  ttl: 900,
});

Options:

Prop Type Description
type "A" | "CNAME" | "NS" | "SOA" | "ALIAS" DNS record type
name string DNS record FQDN
value string DNS record value
ttl number (optional) TTL value for DNS record
hostedZoneId string (optional) The ID of the Route53 HostedZone belonging to the dns-hosting account in which to create the DNS record. If not given the correct HostedZone will be inferred from the domain in the "value" prop.
aliasZoneId string (only needed if type = "Alias") the Route53 HostedZone that the target of the alias record lives in. Generally this will be the well known ID of a HostedZone for a AWS service itself that is managed by AWS, not an end-user.

CDK Construct - IxVpcDetails

Fetches the standard VPC and subnets that exist in all IX workload aws accounts.

import { IxVpcDetails } from "@infoxchange/make-it-so/cdk-constructs";

const vpcDetails = new IxVpcDetails(scope, "VpcDetails");

Options:

Prop Type Description
domainName string Domain name for cert
subjectAlternativeNames string[] (optional) Any domains for the certs "Subject Alternative Name"
region string (optional) The AWS region to create the cert in

Full Example

To deploy a Next.js based site you would include a sst.config.ts file at the root of repo with contents like this:

import { SSTConfig } from "sst";
import { IxNextjsSite } from "@infoxchange/make-it-so/cdk-constructs"<