Skip to Content
Personal Insights
Author's profile photo Siddarth Pugazhendi

Spartacus deployment automation using AWS CodePipeline

Introduction

Spartacus is the next gen accelerator which is an alternative to the traditional JSP based accelerator storefront in SAP Commerce Cloud. As it has reached version 3+ now, it is becoming more and more mature with every release and is adopted in more customer projects now. Not much information about deploying Spartacus in a Cloud platform is available now. Hence I did a small POC to deploy Spartacus in one of the cloud platforms (AWS) and also explored how to automate the deployments. My blog talks about some steps on how to achieve this.

Usefulness of this Setup

Only cloud setup available currently is through SAP Commerce Cloud subscription in Azure, which is normally used for Customer projects. It has got its fair share of challenges, some of them are listed below

  • Single code repository with backend SAP Commerce code
  • No Independent build and deployment pipeline, leading to slower release cycle, usually deployed with the backend code
  • Lastly no automated code build and deployments available in SAP Commerce Cloud portal

Deploying Spartacus independently outside of SAP Commerce Cloud will alleviate the above concerns for an additional cost for cloud services. And having our own cloud setup has a number of advantages like it can be used as a sandbox for learning, POC and demo purposes across the team. 

Architecture of the POC

My POC uses the following components

  • AWS S3 Bucket for hosting
  • AWS Code Pipeline and Build for deployment of code
  • AWS Code Commit for detecting code changes in the repository

However more components such as 

  • CloudFront as CDN 
  • Route 53 for custom domain 

can be added as per the below architecture

Steps to achieve the Deployment automation of spartacus

Code setup

Setup Spartacus in your local machine based on the instructions from this page.

Commit the Spartacus code into a Git based code repository.

Also create and commit a file named buildspec.yaml, with the below contents. Make sure to replace [SpartacusAppName] with your own Spartacus App name.

version: 1.0

phases:

  install:

    commands:

      - echo installing nodejs...

      - curl -sL https://deb.nodesource.com/setup_12.x | bash -

      - apt-get install -y nodejs

      - echo installing yarn...

      - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -

      - echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

      - apt install --no-install-recommends yarn

  pre_build:

    commands:

      - echo installing dependencies...

      - npm i -g @angular/cli

      - npm install

  build:

    commands:

      # - echo testing...

      # - echo building...

      - ng build --prod

artifacts:

  files:

    - "**/*"

  discard-paths: no

  base-directory: dist/[SpartacusAppName]

AWS S3 Bucket setup

I am leveraging AWS S3 bucket for hosting Spartacus as it is an Angular application. Create a S3 Bucket in the region nearest to you and Block all public access like below

Once you created the bucket -> go to permissions, click Edit bucket policy and paste the below contents.

{

    "Version": "2012-10-17",

    "Id": "Policy1607422534880",

    "Statement": [

        {

            "Sid": "Stmt1607422532941",

            "Effect": "Allow",

            "Principal": "*",

            "Action": "s3:GetObject",

            "Resource": "arn:aws:s3:::{yourbucketname}/*"

        }

    ]

}

Enable the Static website hosting with the following settings and click save. Take note of the bucket website endpoint which will be used for spartacus once the setup is done fully.

AWS CodePipeline setup

I am using AWS CodePipeline for setting up the build and deployment pipeline of Spartacus.

Open CodePipeline from the AWS menu and create a pipeline based on the screenshots and settings

Link your code repository with AWS here, if the connection does not exist already you need to use connect to Bitbucket functionality to configure a new connection.

The next stage is where you specify the build tool, you can either go with CodeBuild (Recommended) or Jenkins. Also a new project needs to be created.

The new project requires the below settings. I prefer Ubuntu as the OS for the build tool. Use the below runtime configuration and create a project.

In the Deploy stage, choose the Deploy provider as Amazon S3. The bucket which was created previously should be linked here.

Upon clicking next, you can review the code pipeline settings and then hit create pipeline.

Spartacus Deployment

As soon as you create the pipeline, AWS will automatically execute the pipeline. Whenever a code changes are pushed to the Code repo, this pipeline will automatically re-run to deploy any new changes.

To see the logs you need to click on the AWS CodeBuild link in the Build section, will show the complete step by step logs of Spartacus deployment. In total this takes only 5 minutes to finish.

Now click on the S3 Bucket public link to access Spartacus.

It Works!

Conclusion

Deploying Spartacus independently outside of SAP Commerce Cloud and automating the process is a bit of an unknown at the moment because of lack of documentation, this blog provides a good starting point for this process.

 

References

  1. Spartacus official documentation
  2. Spartacus code repository setup
  3. Deploy Angular apps in AWS S3
  4. Deployment automation using AWS CodePipeline

 

Assigned tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.