Skip to content

Latest commit

 

History

History
 
 

01-set-up-workspace

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Exercise 01 - Set up your workspace

At the end of this exercise, you'll have an environment in which to work for the duration of this CodeJam, and the contents of this repository loaded and ready to use.

Set up the environment and clone this repository

To have the building blocks for this CodeJam ready to use, you'll need to clone this CodeJam repository and have the contents available in the workspace that you chose in the prerequisites. Your workspace is either going to be a Dev Space in the SAP Business Application Studio (the "primary environment"), or VS Code with a dev container (the "alternative environment").

Follow one of the two subsections here, as appropriate: either for a primary environment or for an alternative environment.

Primary environment: A Dev Space in the SAP Business Application Studio

Follow the "Alternative environment" subsection below if you want to use VS Code and a container image.

Create a Dev Space

👉 Via your subscription to the SAP Business Application Studio, create a new Dev Space, choosing the "Full Stack Cloud Application" type, and then make sure it's started up:

Setting up a dev space

Choosing the "Full Stack Cloud Application" brings in some predefined extensions, as you can see from the screenshot, including a CDS Graphical Modeler and the CAP Tools.

You may need to stop existing Dev Spaces to use this one, depending on your subscription access.

Clone this repository

👉 Once the Dev Space is started and you're in it, use the "Clone from Git" option in the "Get Started" screen that appears, to clone this repository, following the subsequent prompts to open the cloned repository; specify https://github.com/SAP-samples/cap-service-integration-codejam as the URL.

Cloning the repo

At this point your Dev Space will restart.

Set up a URL redirector

One of the many great benefits of the SAP Business Application Studio is that you can run it anywhere, all you need is a modern browser. Each Dev Space provides a complete working environment, and the infrastructure also provides you with the facilities to run services and bind to sockets, to listen and respond to incoming requests from your services that are local to the Dev Space but available on the Web.

In practice, this means that when running a CAP server "locally" in this context, you'll access it not via localhost (as that's specific to your local machine where your browser is running) but via a URL provided and serviced by the SAP Business Application Studio infrastructure, and your requests will find their way to your CAP server in your Dev Space.

The upshot of this is that whereas with a locally running VS Code environment, where localhost really means localhost even when using a dev container (this is because of published ports in container networking), with such a hosted SAP Business Application Studio context the URLs will be different for each of your Dev Spaces.

In order to provide a comfortable CodeJam experience, and include links to various CAP server provided resources that you'll create along your journey, we can only use generic localhost URLs in the exercise content, because we cannot know in advance what the SAP Business Application Studio infrastructure will provide for you in terms of URL structure.

So for the best experience during this CodeJam (i.e. this is not a normal development requirement), we recommend you consider using a browser extension and set up a temporary redirect from http://localhost:4004 style URLs, to whatever URL structure you have in your Dev Space.

Note that this is only a recommendation so that you can comfortably select URLs in this CodeJam content. You don't have to install such an extension -- you can just as easily select the http://localhost:4004 style URLs shown in the terminal in your Dev Space instead if you wish.

We've had good experience with the Redirector extension for Google Chrome and this is the one that we recommend you install, just for the duration of this CodeJam.

👉 If you wish, please follow the instructions in Set up a temporary localhost redirector.

Alternative environment: VS Code and a container image

Follow the "Primary environment" section above if you want to use a Dev Space in the SAP Business Application Studio.

👉 At a command prompt on your local machine, clone this repository into a directory of your choice, and then open VS Code, pointing to that newly cloned repository's directory:

git clone https://github.com/SAP-samples/cap-service-integration-codejam
code cap-service-integration-codejam

Once VS Code has started, and opened the directory, it should notice the dev container configuration file (in the .devcontainer/ directory) and ask you if you want to reopen everything in a container, as shown in the screenshot. Confirm that you want to, by selecting the default answer "Reopen in Container".

If this doesn't happen, check that you have the Dev Containers extension in VS Code - see the corresponding prerequisites section section for details. The dialog prompting you to "Reopen in Container"

At this stage, once VS Code has reopened, you need to do one more thing, so that both primary and alternative environments are aligned (and so that the instructions in this CodeJam content don't need to differ between them). When you use the "git clone" facility in a Dev Space, the repo is cloned into a directory called projects/, which itself lives in your home directory, in other words, it gets cloned to /home/user/projects/<the-repo>. In a VS Code dev container, the equivalent repo will be in /workspaces/<the-repo>. So let's align the repo location in your VS Code dev container environment to the Dev Space one.

👉 Create a projects/ directory in your dev container user's home directory, and then create a symbolic link to the repo in there:

mkdir -p $HOME/projects/ \
  && ln -s /workspaces/cap-service-integration-codejam/ $HOME/projects/

If the projects/ directory already exists, for some reason, then the mkdir command would normally fail and emit a message; this would also mean that the subsequent ln command would not run (as they're connected via &&). So we use the -p option to tell mkdir not to complain.

You can make sure that everything is OK by checking that you can see the directories inside the repo, via this new projects/ directory in your dev container user's home directory. Here's an example, with what you might expect to see:

$ find -L $HOME/projects -maxdepth 2 -type d
/home/node/projects
/home/node/projects/cap-service-integration-codejam
/home/node/projects/cap-service-integration-codejam/.devcontainer
/home/node/projects/cap-service-integration-codejam/.git
/home/node/projects/cap-service-integration-codejam/.github
/home/node/projects/cap-service-integration-codejam/.reuse
/home/node/projects/cap-service-integration-codejam/.vscode
/home/node/projects/cap-service-integration-codejam/LICENSES
/home/node/projects/cap-service-integration-codejam/assets
/home/node/projects/cap-service-integration-codejam/exercises
/home/node/projects/cap-service-integration-codejam/incidents
/home/node/projects/cap-service-integration-codejam/scripts

Now you should be all set. You are ready to explore service integration with CAP in your dev container.

Check the installation of the CDS development kit

This and subsequent steps apply to both the primary and alternative environments.

👉 Open a terminal, using "Terminal: Create New Terminal" in the Command Palette, and at the prompt, check the version:

cds v

You should see that the CDS development kit is installed. Depending on your workspace, you'll see slightly different output, but it should generally look something like this:

@sap/cds: 6.4.1
@sap/cds-compiler: 3.5.4
@sap/cds-dk: 6.4.1
@sap/cds-dk (global): 6.4.1
@sap/cds-foss: 4.0.0
@sap/cds-mtx: -- missing --
@sap/cds-mtxs: 1.4.4
@sap/eslint-plugin-cds: 2.6.0
Node.js: v18.13.0
home: /usr/local/share/npm-global/lib/node_modules/@sap/cds-dk/node_modules/@sap/cds-dk

The CDS development kit is installed as part of any "Full Stack Cloud Application" type of Dev Space in the SAP Business Application Studio, and for the alternative environment there's a RUN command in the Dockerfile that installs it into the dev container.

Install the NPM package dependencies

We'll be working mostly within the incidents/ directory of this repo, which contains a simple starter CAP project. In there, the package.json file contains runtime and design time dependencies.

👉 Make sure you're in the incidents/ directory (where package.json lives):

cd $HOME/projects/cap-service-integration-codejam/incidents/

👉 Now install the dependencies thus:

npm install

You can double check what's installed, with npm list --depth=0, which should show you something similar to this:

@acme/[email protected] /home/user/projects/cap-service-integration-codejam/incidents
├── @sap/[email protected]
├── [email protected]
└── [email protected]

Summary

At this point you've got an environment in which to work through the rest of the exercises in this CodeJam, you've got the contents of the repository, and you have the CDS development kit installed and ready to use.

Further reading


Questions

If you finish earlier than your fellow participants, you might like to ponder these questions. There isn't always a single correct answer and there are no prizes - they're just to give you something else to think about.

  1. What are the advantages of using container images for development work?
  2. What is the difference between the @sap/cds and @sap/cds-dk packages?

Next exercise