Skip to main content

A CDK construct which creates a pipeline that pulls code from a source repository, builds it, then deploys to an S3 bucket (with CloudFront if a certificate is required)

Project description

SPA + CICD Website Construct

This CDK construct is used to create a static website with a CodePipeline to deploy from source code on pushes to master. The goal of this construct is to be able to point it at a git repository, give it a url, and you've got a continuously deployed static website.

This is a pre-release!

This is a quick first-draft. All the options that will likely need to be added to accomodate a large number of use-cases are still needed. If you'd like to make requests or help update this construct, please open an Issue or a PR.

What Gets Created

At the base level, the following will be built:

  • An S3 bucket for build artifacts
  • An S3 bucket for the website content
  • CICD Pipeline - CodePipeline sourced from Github, built using CodeBuild and deployed to an S3 bucket.

If a certificate is supplied or requested:

  • An ACM certificate will be provisioned via DNS if requested
  • A CloudFront Distribution pointing to the S3 bucket.

Example

This will create the website, the deployment pipeline, and add a generated certificate (and CloudFront) for HTTPS support.

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
CicdSpaWebsite(stack, "public-site",
    url="www.matthewbonig.com",
    github_source={
        "owner": "mbonig",
        "repo": "public_site",
        "oauth_token": SecretValue.secrets_manager("github-oauth-token")
    },
    hosted_zone={
        "hosted_zone_id": "ABCDEFGHIJKLM",
        "zone_name": "matthewbonig.com"
    },
    certificate=True
)

Input Properties

property description example
url The url you'd like your website to be available at. Must be full url and must be controlled by the given HostedZone www.matthewbonig.com
githubSource.owner The Github repository's owner mbonig
githubSource.repo The GH repo name public_site
githubSource.branch An optional branch name. Defaults to 'master' qa
githubSource.oauthToken An ISecret pointing to an oauthToken. SecretValue.secretsManager('github-oauth-token')
hostedZone (Optional) - If provided, used to create DNS Records.
hostedZone.hostedZoneId The hostedZone ID for the 'url's domain ABCDEFGHI
hostedZone.zoneName The hostedZone's name matthewbonig.com
certificate (Optional) - If provided, creates a CloudFront Distribution with the given certificate. If 'true' is provided, then a certificate will be generated. true
buildSpec (Optional) - If provided, will override the default BuildSpec in the CodeBuild project. Accepts either a string value (the filename in the source code) or an object. The object is passed to the BuildSpec.fromObject(). If not provided, see BuildSpec. build-prod.yaml

Design Notes

Certificates

If a certificate is required to provide HTTPS support then a simple S3 Bucket with website hosting will not work. This construct chooses to put a CloudFront Distribution in front of it when a certificate is required.

If that certificate already exists, it can be supplied as an ICertificate. If not, then it will be created using a DNSValidatedCertificate.

If no certificate is supplied or requested, then the site will be hosted using a public S3 Bucket with Website Hosting enabled. No CloudFront Distribution will be created in that case.

Github Sources

Github source information is provided through props for the construct.

If you'd like to see support for another type of Source action, please open an Issue or a PR.

BuildSpec

The default buildspec is defined at DEFAULT_BUILD_SPEC. It uses a Node v12 runtime, runs an npm install and then an npm run build and assumes the static deliverables are in the dist directory.

You may override the BuildSpec with either your own object or by passing a string which will be interpreted as a filename within the source to use.

Contributing

Please open Pull Requests and Issues on the Github Repo.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mbonig.cicd-spa-website-0.1.2.tar.gz (38.1 kB view details)

Uploaded Source

File details

Details for the file mbonig.cicd-spa-website-0.1.2.tar.gz.

File metadata

  • Download URL: mbonig.cicd-spa-website-0.1.2.tar.gz
  • Upload date:
  • Size: 38.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.5

File hashes

Hashes for mbonig.cicd-spa-website-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6bd88f818d0fdd5cb93496776260fb70c07838d5631abe1d0d3d383f33e2f757
MD5 cfc13a281acf754cba5c09ac3b689080
BLAKE2b-256 3ae5037ee0180cca656e5b0a0cec688593fb0bf1b9cc19f65de98f01060b939b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page