Platform Deployment

Harmony Platform build results in build artifacts that are simple to scale and deploy. They allow for optimization and scale of applications based on business needs while keeping code organization independent from your production infrastructure.

Using Bit and Harmony, you can produce a single binary build artifact for each of your application runtimes, the produced output of a standard platform build includes:

  • Binary artifact for the backend.
  • Code split-ed and optimized UI application bundle.

This allows for optimized security, safety and performance for your software.

Orchestration of a platform deployment on a Kubernetes cluster
Orchestration of a platform deployment on a Kubernetes cluster

To configure the default Kubernetes deployer, first install it:

bit install @bitdev/symphony.deployers.kubernetes
CopiedCopy

Then use aspect in your application shell:

import { KubernetesAspect } from '@bitdev/symphony.deployers.kubernetes';
import { SymphonyPlatformAspect } from '@bitdev/symphony.symphony-platform';

export const MyPlatform = HarmonyPlatform.from({
  name: 'my-platform',
  platform: [SymphonyPlatformAspect, {
    name: 'My platform',
    domain: 'example.com',
  }],
  
  aspects: [[
    KubernetesAspect, {
      auth: {
        // configure your kubernetes cluster.
        basic: {
          server: 'http://1.2.3.4',
          token: process.env.KUBE_USER_TOKEN // set environment variables as Ripple CI secrets.
        }
      },
      // configure your docker registry.
      docker: {
        imagePrefix: 'dockerhub-account',
        auth: {
          username: 'ci-user',
          password: process.env.DOCKER_TOKEN // set DOCKER_TOKEN environment variables as Ripple CI secrets.
        }
      }
  }]],
});
CopiedCopy

Once configured, the shell application deployment pipelines will be invoked during the release pipeline, when you run the tag or snap commands:

bit tag --message 'releasing my feature' --major
CopiedCopy

Ensure to configure the environment variable secrets in Ripple CI secrets, making them available for deployment.

Initiate the release CI job:

bit export
CopiedCopy

The CI pipeline automatically releases your application to the specified Kubernetes cluster. You can adjust the deployment of each runtime to use the below list of supported deployers or build your own.

Cloud providers

Use specific cloud providers to ease the deployment to the cloud provider of your choice.

Configuring a deployment to Google Cloud:

import { KubernetesAspect } from '@bitdev/symphony.deployers.kubernetes';
import { SymphonyPlatformAspect } from '@bitdev/symphony.symphony-platform';

export const MyPlatform = HarmonyPlatform.from({
  name: 'my-platform',
  platform: [SymphonyPlatformAspect, {
    name: 'My platform',
    domain: 'example.com',
  }],
  
  aspects: [
    KubernetesAspect,
    [AwsAspect, {
      clusterName: 'acme-platform',
      zone: 'us-central1',
      keyJson: process.env.GCP_ACCESS_KEY
    }]
  ],
});
CopiedCopy

Pre-production

It is recommended to automate the deployment to pre-production from the main lane, and deploy to production separately after carefully testing changes on the pre production environment.

Manual deployment

Each version of the platform component includes its deployment artifact. Use the artifact command to fetch it:

bit artifacts pied.pied-piper/pied-piper --out-dir deploy
CopiedCopy

Now you can run the deployment:

node path/to/artifact/my-platform.cjs deploy
CopiedCopy

When running the deployment, ensure to authenticate with your Docker registry and Kubernetes cluster, or cloud provider.

Rollback

To rollback to any past version, use the artifacts command to fetch any of your past artifacts:

bit artifacts pied.pied-piper/pied-piper@1.0.0 --out-dir deploy
CopiedCopy

Run the deployment:

node path/to/artifact/my-platform.cjs deploy
CopiedCopy

Customizing the deployment

You can customize and control every level of the platform deployment.

Setup instructions

When deploying on Kubernetes, you can register additional setup instructions. They will be executed during deployment process:

export class AcmePlatformNode {
  static dependencies = [KubernetesAspect];
  
  static async provider([kubernetes]: [KubernetesNode]) {
    const acmePlatform = new AcmePlatform();

    kubernetes.registerSetup([
      {
        name: 'mongo-db',
        yamls: []
      }
    ])

    return acmePlatform;
  }
}
CopiedCopy

API gateway

By default, Symphony has a default implementation of an API gateway, supporting Express and GraphQL. You can replace the API gateway implementation with your own if needed.

UI app

By default, the browser runtime is leveraging Vite (with SSR support) for the bundling of your application. You can replace the bundler to other tools, as needed.

Service-level configuration

You can override and use configuration files for specific services using the backend server DeployOptions.

Custom deployer

Alternatively, you can implement your own deploy function using the deploy property key in your Harmony platform:

// my-platform.bit-app.ts
import { HarmonyDeployContext } from '@bitdev/harmony.harmony-platform';

export async function platformBuildFunction(context: HarmonyDeployContext) {
  // echos the platform path and a list of build artifacts created for each of the platform runtimes.
  console.log(context.capsule.path, context.runtimeArtifacts); 

  return {
    // used for display on bit cloud for staging and production environments.
    url: 'my-platform.com'
  }
}
CopiedCopy

Find more information on the API available in the Harmony Deploy Context API reference. To learn more on Application context head to the Deploying apps section.

Testing deployments

You can test your deployment locally without creating a new version to your platform (be careful, as this will trigger your deploy pipeline):

bit build --include-tag
CopiedCopy

To deploy a micro service a common practice is to invoke the NodeJS runtime with a deploy argument and handle deployment from within the platform aspect.

Running the app

Harmony gives you granular control when running your platform, app or services.

Run the application:

node path/to/artifact/my-platform.cjs
CopiedCopy

Run a specific backend service:

node path/to/artifact/my-platform.cjs people
CopiedCopy

Run a specific frontend application:

node path/to/artifact/my-platform.cjs people
CopiedCopy