Spartacus is the next-gen storefront for SAP Commerce Cloud, replacing the traditional JSP-based accelerators. As it has reached version 3+ now, it is becoming more and more mature with every release and is being adopted in more customer projects. However, not much information about deploying Spartacus in a cloud environment is available at the moment. I did a small POC on deploying Spartacus in AWS and also explored how to automate the deployments. This article discusses some steps on how to achieve this.
Deploying Spartacus independently outside of SAP Commerce Cloud will alleviate the above concerns but will also imply additional costs for cloud services. Having our own cloud setup has a number of additional advantages. For example, it can be used as a sandbox for learning, POC and demo purposes across the team.
My POC uses the following components
However, more components such as CloudFront as CDN and Route 53 for custom domain can be added as per the below architecture:
For this POC, I am leveraging an 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:
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][a][b][c]
First, set up Spartacus in your local machine based on the instructions from this page. Then 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.
Once you created the bucket, go to permissions, click Edit bucket policy and paste the below content:
{
"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 S3 bucket settings and click save. Take note of the bucket website endpoint, which will be used for Spartacus once the setup is done.
I am using AWS CodePipeline for setting up the build and deployment pipeline of Spartacus. Search and select CodePipeline from the menu and create a pipeline as shown in the screenshot below.
Link your code repository with AWS here. If the connection does not already exist, you need to connect to Bitbucket to configure a new connection.
The next stage is where you specify the build tool. You can either go with CodeBuild (recommended) or Jenkins.
We also need to create a new project now.
The new project requires the below settings. I prefer Ubuntu as the OS for the build tool.
In the Deploy stage, choose Amazon S3 as the Deploy provider. The bucket, which was created previously, should be linked here.
Upon clicking next, you can now review the code pipeline settings and then click Create pipeline.
As soon as you create the pipeline, AWS will automatically execute the pipeline. Whenever a code change is 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, which will show the complete step-by-step logs of the Spartacus deployment. In total, it takes only 5 minutes to complete.
Now click on the S3 bucket public link to access Spartacus.
It works!
Deploying Spartacus independently outside of SAP Commerce Cloud and automating the process is a bit of an unknown area at the moment due to the lack of official documentation. This article provides a good starting point for this process.