Skip to content

mokeseven7/phpbuilder

Repository files navigation

codecov GitHub Workflow Status npm

CDK Docker Image Builder

Although the construct can technically build an image from any docker file, it's optimized towards the building of php images from the lambda runtime base image. If you want to build images for other languages, there are probably better options out there.

Installation

In your existing CDK project, pull in the library using one of the package managers:

# Using pnpm
$ pnpm i @mikemcgrath/phpbuilder

# Using NPM
$ npm i @mikemcgrath/phpbuilder

# Using Yarn
yarn add @mikemcgrath/phpbuilder

Using The Construct

The below is a basic example of how the contruct could be used in an existing CDK project:

import * as ecr from 'aws-cdk-lib/aws-ecr';
import * as phpbuilder from '@mikemcgrath/phpbuilder';

//The Construct requires 3 things - 

//1. and instance of ecr.Repository, either new or existing
const repo = new ecr.Repository.fromRepositoryName(this, 'MyRepository', 'latest');

//2. A path to a valid Dockerfile location
const source = phpbuilder.PHPDockerImageSource.directory('path/to/dockerfile');

//3. A valid Docker Image Host, only Supports aws ecr as of now
const destination = phpbuilder.PHPDockerImageDestination.ecr(repo, {tag: 'latest'});

//4. Once you have a repo, source and destination, simply call new on the builder
  new phpbuilder.PHPDockerImageBuilder(stack, 'TestDeployment', {
    source,
    destination,
});

Full Example:

import * as path from 'path';
import * as process from 'process';
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ecr from 'aws-cdk-lib/aws-ecr';
import * as phpbuilder from '@mikemcgrath/phpbuilder';


export class MyDockerImageDeployment extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);
    
    const repository = new ecr.Repository(this, "phpbuilder", {
      repositoryName: "phpbuilder"
    });

    const source = phpbuilder.PHPDockerImageSource.directory(path.join(process.cwd()));
    const destination = phpbuilder.PHPDockerImageDestination.ecr(repository, {tag: 'latest'});

    const image = new phpbuilder.PHPDockerImageBuilder(this, 'PHPBuilderStack', {
      source,
      destination
    })
  }
}

Thats It! You can now synthethize and deploy!

Need Help?

A full basic example can be found here: example repo
A more advanced example can be found here: JWT authorizer

About

Construct to easily create docker images in ECR. 100% test coverage and automations for NPM.

Resources

Stars

Watchers

Forks

Packages

No packages published