npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-s3-cicd

v0.0.37

Published

The [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) (CDK) is used to build and expose an [Angular](https://angular.io/) application using [AWS CloudFront](https://aws.amazon.com/cloudfront/).

Downloads

8

Readme

CI/ CD Pipeline for an Angular project

The AWS Cloud Development Kit (CDK) is used to build and expose an Angular application using AWS CloudFront.

The source code

The Angular source code is stored in one of my GitHub repositories. It is a very basic application that can be build by executing

ng build --prod

The build pipeline

The build pipeline consists of two stages, the sourceStage and the buildStage.

const sourceStage = pipeline.addStage({
    stageName: "Source"
});

const buildStage = pipeline.addStage({
    stageName: "Build",
    placement: {
    justAfter: sourceStage
    }
});

The sourceStage contains only a single action responsible for monitoring changes on the code repository

const sourceAction = new GitHubSourceAction({
    actionName: "GitHub",
    owner: "stefanfreitag",
    repo: "angular-hello-world",
    oauthToken: SecretValue.secretsManager("my-github-token"),
    output: sourceOutput,
    branch: "master",
    trigger: GitHubTrigger.POLL
});

sourceStage.addAction(sourceAction);

In the buildstage a CodeBuild project is executed. As part of the project the required software is installed: all required libraries, the AWS as well as the Angular CLI.

npm install
pip install awscli --upgrade --user,
npm i -g @angular/cli"

In the next phase of the project ng build --prod runs and generated the distribution files.

The last phase is responsible for updating the content of the used S3 bucket.

aws s3 rm s3://${websiteBucket.bucketName}/ --recursive
aws s3 cp ./dist/angular-hello-world s3://${websiteBucket.bucketName}/ --recursive

The CloudFront setup

The S3 bucket websiteBucket is not exposed directly to the Internet, CloudFront will be installed in between. Hence the publicReadAccess and blockPublicAccess are set to false settings.

const websiteBucket = new Bucket(this, "bucket", {
  websiteIndexDocument: "index.html",
  publicReadAccess: false,
  encryption: BucketEncryption.S3_MANAGED,
  blockPublicAccess: {
    restrictPublicBuckets: false,
    blockPublicAcls: false,
    ignorePublicAcls: false,
    blockPublicPolicy: false,
  },
   removalPolicy: RemovalPolicy.DESTROY,
});

To allow CloudFront access to the content of the S3 bucket a user is setup

const oai = new OriginAccessIdentity(this, "originAccessIdentity", {
  comment: "Allows CloudFront to reach the bucket",
});
websiteBucket.grantRead(oai);

The CloudFrontWebDistribution contains aside from the websiteBucket and the user information also another bucket used to store the access logs.

new CloudFrontWebDistribution(this, "myDistribution", {
  originConfigs: [
    {
      s3OriginSource: {
        s3BucketSource: websiteBucket,
        originAccessIdentity: oai,
      },
      behaviors: [{ isDefaultBehavior: true }],
    }],
    comment: "Demo CloudFront Distribution",
    loggingConfig: {
      bucket: accessLogsBucket,
      prefix: "ng-s3-demo",
      includeCookies: true,
    },
    priceClass: PriceClass.PRICE_CLASS_100,
});