Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jvallexm committed Feb 9, 2024
2 parents 2d26a5b + 6076df0 commit 173467e
Show file tree
Hide file tree
Showing 124 changed files with 8,826 additions and 1,088 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.md
unit-tests/
old/
node_modules/
client/node_modules/
89 changes: 6 additions & 83 deletions .docs/CRAIG-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,107 +6,31 @@ CRAIG simplifies the process of creating IaC through its GUI, which manages and

CRAIG configures infrastructure using JSON to create full VPC networks, manage security and networking with VSI deployments, and create services, clusters, and manage IAM for an IBM Cloud Account. This JSON configuration can be imported to quick start environments, and can be downloaded as Terraform code directly from the GUI.

- [CRAIG Public Github Repository](https://github.com/IBM/CRAIG)

---
## CRAIG Usage Pattern

<img src="./images/CRAIG-usage-pattern.drawio.png" alt="CRAIG Usage Pattern" width="400" align="right"/>

- Recommended use case is to deploy CRAIG to Code Engine both in Development account and Customer/POC account.
- The recommended use case is to deploy CRAIG to Code Engine both in Development account and Customer/POC account.

- Development Account will be used to configure PowerVS Workspaces for CRAIG to use.
- _see [Power VS Workspace Deployment](#power-vs-workspace-deployment) section for more information._
- The development Account will have Power VS Workspaces for CRAIG to query when building Power VS projects.

- PoC Environment will be configured within CRAIG Code Engine Instance on Development Account. Once ready, configuration template can be uploaded to Schematics for automated provisioning and internal testing.
- The PoC Environment will be configured within CRAIG Code Engine Instance on Development Account. Once ready, configuration template can be uploaded to Schematics for automated provisioning and internal testing.

- After internal testing is complete, PoC Environment template can be:
- downloaded from CRAIG _(see [Downloading CRAIG Configuration](#downloading-craig-configuration) section)_
- or copied using the `craig.json` _(see [Copying JSON from within CRAIG](#copying-json-from-within-craig) section)_

- PoC Environment `craig.json` template is transferred over to Customer/PoC Account's CRAIG Code Engine Instance using CRAIG's [Import JSON Feature](#importing-json-into-craig), then uploaded to Schematics again for PoC Infrastructure.

- See _[Integrating Schematics with CRAIG documentation](https://github.ibm.com/platinum-developer-tools/powervs-coe-docs/blob/mvp-docs/mvps/schematics-how-to.md)_ for more information on how to Integrate CRAIG with Schematics.
- See _[Integrating Schematics with CRAIG documentation](./schematics-how-to.md)_ for more information on how to Integrate CRAIG with Schematics.

<br clear="right"/>

---
_Recommended Deployment Solution:_ [Deploying CRAIG in IBM Code Engine](#deploying-craig-in-ibm-code-engine)

For instructions on how to run CRAIG locally instead of using Code Engine, see the CRAIG documentation for the following:
## Installing CRAIG

- [Running CRAIG Application Locally](https://github.com/IBM/CRAIG?tab=readme-ov-file#running-craig-application-locally)
- [Setting Up CRAIG Development Environment](https://github.com/IBM/CRAIG?tab=readme-ov-file#setting-up-craig-development-environment)
- [Building Local CRAIG Container Image](https://github.com/IBM/CRAIG?tab=readme-ov-file#building-local-container-image)

---

## Deploying CRAIG in IBM Code Engine
[CRAIG's deploy.sh script](https://github.ibm.com/platinum-developer-tools/CRAIG/blob/main/deploy.sh) deploys CRAIG to IBM Cloud Code Engine. The user running this command must have sufficient permissions to provision a Code Engine project, application, image build, and secrets. In addition, this API key must be able to create a IBM Container Registry namespace. See below for a simple use case using the default parameters.

CRAIG uses existing Power VS workspaces in the account to query zone specific items such as images, hardware, etc. If these workspaces are not configured CRAIG will use a static list which may include options that are not available in a specific zone. The [Power VS Workspace Deployment](#power-vs-workspace-deployment) section overs the configuration of these Power VS workspaces. If the workspace query functionality is desired, the workspaces should be created before deploying CRAIG in Code Engine.

#### Prerequisites for running deploy.sh from IBM Cloud Shell (recommended)
>* An API key must be provided that will be used for CRAIG's integration with IBM Cloud Schematics and Power Virtual Server Workspaces. This API key will also be used for IBM Code Engine's access to the IBM Container Registry. See later sections in this document about Schematics and Power Virtual Server integrations for more information.
#### Prerequisites for running deploy.sh outside of IBM Cloud Shell
>* The `ibmcloud` CLI must be [installed](https://cloud.ibm.com/docs/cli?topic=cli-install-ibmcloud-cli)
>* `ibmcloud login` must be run before invoking the script
>* An API key must be provided that will be used for CRAIG's integration with IBM Cloud Schematics and Power Virtual Server Workspaces. This API key will also be used for IBM Code Engine's access to the IBM Container Registry. See later sections in this document about Schematics and Power Virtual Server integrations for more information.
>* [jq](https://jqlang.github.io/jq/) v1.7 or higher
#### Downloading deploy.sh in IBM Cloud Shell
From within IBM Cloud Shell run the following two commands to download the deploy.sh script and make it executable:
```bash
wget https://raw.githubusercontent.com/IBM/CRAIG/main/deploy.sh
chmod 755 deploy.sh
```

### Running the deploy script
By default the script will securely prompt you for your API key. It may also be read from an environment variable or specified as a command line argument. See the `deploy.sh -h` usage for more information.

```bash
./deploy.sh
```

The deploy script can also create the Power Virtual Server workspaces and automatically integrate them with the CRAIG deployment. The deploy script uses a Schematics workspace and Terraform to drive the creation and deletion of the Power Virtual Server workspaces. Specify the `-z` parameter to automatically create the Power Virtual Server workspaces:
```bash
./deploy.sh -z
```

This script can also delete the resources when the delete flag `-d` is passed

```bash
./deploy.sh -d
```

For the full list of parameters which allows full customization of the IBM Code Engine deployment, specify the `-h` parameter:
```
./deploy.sh -h
```

Note, if you've specified custom parameters beyond the default values for your deploy script, then you must specify them after the delete flag in order to delete all resources properly.

For example, to delete the CRAIG Code Engine and Container Registry resources with custom parameters resource group: `test-rg`, namespace: `craig-demo-namespace`, and project name: `craig-demo-project`, then the script must be specified as followed:

```bash
./deploy.sh -d -g test-rg -n craig-demo-namespace -p craig-demo-project
```

---

### Bring Your Own Workspace

To bring your own Power VS Workspace into CRAIG to fetch images, you will need to set a field in your `.env` file with the following format. To see an example, see [.env.example](./.env.example)

```
POWER_WORKSPACE_<zone-of-workspace>=<workspace-guid>
```
To find the GUIDs and locations of your workspaces, the following command can be run in a terminal window or an IBM Cloud Shell using the [IBM Cloud CLI](https://cloud.ibm.com/docs/cli?topic=cli-getting-started):

```
ibmcloud resource service-instances --service-name power-iaas --output json | jq -r '.[]? | "\(.guid), \(.name), \(.region_id)"'
```
See the [main README for installation instructions](../README.md#installation). The recommended approach is to [deploy CRAIG in IBM Code Engine](../README.md#deploying-to-ibm-code-engine).

---
## Using CRAIG
Expand Down Expand Up @@ -148,7 +72,6 @@ Alternatively, the `craig.json` can be quickly viewed, copied, or overrided dire
- Override your configuration by allowing you to edit your `craig.json` file manually _(not recommended)_.
2. Navigating to the Summary Page, users can copy their `craig.json` output for future use.


---

## Importing JSON into CRAIG
Expand Down
53 changes: 53 additions & 0 deletions .docs/craig-code-engine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# CRAIG in IBM Code Engine

The default setup of CRAIG in Code Engine pulls the latest CRAIG source, builds a container image, and creates the serverless application. All of this activity is done in a Code Engine project. The default CRAIG Code Engine project looks like this:

![craig-ce-project](images/craig-ce-project.png)

## Updating CRAIG
CRAIG is continually being enhanced with new features. To update your CRAIG deployment with the latest CRAIG code level, navigate to the `craig` project's image build. The navigation flow from the [Code Engine project page](https://cloud.ibm.com/codeengine/projects) is:
1. Click on the `craig` project name
2. Click `Image builds` on the left panel
3. Click the `Image build` tab in the main panel
4. Click the `imgbld-craig` build name

The image build panel looks like this:
![craig-ce-image-build](images/craig-ce-imgbld.png)

To refresh the container image with the latest code, click the `Submit build` button and then the `Submit build` button on the right nav pop-over.

This will build a new container image with the latest CRAIG source. The next time the CRAIG application starts after a period of inactivity, it will use the new image.

### Redeploying the CRAIG instance
The new instance can also be deployed immediately by navigating to the `craig` application panel and clicking the `Redeploy` button.

The `craig` application panel can be reached from the `craig` project by clicking on the `Applications` left menu item and clicking the on the `craig` application name in the table. The application panel looks like this:

![craig-application-panel](images/craig-application-panel.png)

## Advanced source and container image management
The Code Engine image build and application settings can be used to manage the CRAIG source level being built and run.

* The `Branch name` field on the image build panel can be changed to build a specific CRAIG tag/release or a specific commit level.
* The output tab of the image build panel can be used to change the output container image name and tag. The image name and tag can also be set during image build submission. The container image tags can be changed from `latest` to something else like the CRAIG source image tag or the date the latest `main` branch was pulled and built.
* If different image container names or tags are used, the `Image reference` field on the `craig` application panel must be updated with the new image/tag name and the revision [redeployed](#redeploying-the-craig-instance) to run with the new image.

## Bring your own Power VS workspace

### Background
You can bring your own existing Power VS workspace into CRAIG which allows you to choose custom images for Power VSIs.

The IBM Code Engine deployment script will automatically create Power VS workspaces for CRAIG use when using the `-z` parameter. The script also allows specifying environment variables with the workspace IDs in a file with the `-e` parameter. In both cases the Power VS workspace zones and corresponding workspace IDs are placed in a Code Engine configmap.

### Modifying the configmap
If you want to bring your own workspace after CRAIG deployment in Code Engine you can update the configmap with the GUID of your workspace.

To find the GUIDs and locations of your workspaces, the following IBM Cloud CLI command can be run in a terminal window or an IBM Cloud Shell:

```
ibmcloud resource service-instances --service-name power-iaas --output json | jq -r '.[]? | "\(.guid), \(.name), \(.region_id)"'
```

To modify the configmap to add your workspace GUID, click on `Secrets and configmaps` on left navigation pane of the Code Engine project. Click on the `craig-env` Configmap. Find the key that matches your workspace's zone and set your workspace's GUID as the value for the key. Click the `Save` button. The CRAIG instance can then be [redeployed](#redeploying-the-craig-instance) to pick up the configmap change.

If CRAIG was deployed without specifying `-z` or `-e`, a configmap can be manually created and set with the correct key-value for the zone. See the [.example.env](../.example.env) for the possible keys and the [IBM Code Engine documentation](https://cloud.ibm.com/docs/codeengine?topic=codeengine-configmap) for how to create the configmap and add the reference to the `craig` application.
57 changes: 57 additions & 0 deletions .docs/dev-env-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Setting Up CRAIG Development Environment

CRAIG is a flexible application that can be used directly from your local environment or containerized and deployed to your platform of choice.

To run CRAIG in your development environment, follow these steps:

## 1. Install Dependencies

To install needed dependencies, use the command
```shell
npm run setup
```

## 2. Creating .env file

Make sure to set the `API_KEY` variable in a `.env` file to be used for IBM Cloud integration. To dynamically fetch Power VS images and storage pools within CRAIG, the IBM Power VS APIs require a workspace to be created and its GUID to be in an environment file. See [Power VS Workspace Deployment](.docs/power-vs-workspace-deployment.md) for more information.

See `.env.example` found [here](./.env.example)

## 3. Starting the Back-End Server

In order to make sure the Back-End API calls are successful, the server needs to be started. To start the server run the following command from the root directory:

```shell
node server.js
```

## 4. Starting the Front-End Application

CRAIG uses [craco](https://www.npmjs.com/package/@craco/craco) to setup and run the development environment. To start the development build server, run the following command in parallel with [Step 3](#3-starting-the-back-end-server):

```shell
npm run dev-start
```

## 5. Opening the Application

Congratulations! CRAIG is now running at `localhost:3000`

## 6. Testing the Development Environment

CRAIG uses [mocha](https://mochajs.org/) and [chai](https://www.chaijs.com/) for unit testing. To run unit tests use the command:

```shell
npm run test
```

Craig uses [nyc](https://www.npmjs.com/package/nyc) for unit test coverage. To get a report of unit test coverage run the command

```shell
npm run coverage
```

## 7. Install Pre-commit Hook
```shell
git config --local core.hooksPath .githooks/
```
Binary file added .docs/images/craig-application-panel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .docs/images/craig-ce-imgbld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .docs/images/craig-ce-project.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions .docs/power-vs-workspace-deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Power VS Workspace Deployment

To dynamically fetch Power VS images and storage pools within CRAIG, the IBM Power VS APIs require a workspace to be created. CRAIG provides Terraform scripts to automatically provision these workspaces and an environment file that can be used for both IBM Code Engine deployments and local deployments.

>* _**Note:** this only needs to be done once per IBM Cloud Account, not per user of CRAIG._
>* _The deploy.sh script used to deploy CRAIG in IBM Code Engine can also automatically deploy the workspaces using its `-z` parameter._
## Prerequisites
- [Create an IBM Cloud API Key](https://cloud.ibm.com/docs/account?topic=account-userapikey&interface=ui#create_user_key)
- [jq](https://jqlang.github.io/jq/) v1.7 or higher


<br /> _Note: If you plan on [deploying CRAIG To IBM Code Engine](../README.md#deploying-to-ibm-code-engine), ensure you are using the same account you intend to use for CRAIG deployment in Code Engine when creating the API key and doing the PowerVS Workspace Deployment setup below._


## Automated Deployment

The `terraform.sh` script found in the `/deploy` folder of the CRAIG root directory provisions a Power VS Workspace in each zone and sets the needed environment variables with the format of `POWER_WORKSPACE_<zone>=<workspace-guid>`.

Use the following command to run the script:
```shell
sh deploy/terraform.sh -a "<Your IBM Cloud Platform API key>"
```

This will produce a file named `.env` that can be passed to the `deploy.sh` script when deploying CRAIG in Code Engine.

#### Bring Your Own Workspace

To bring your own Power VS Workspace into CRAIG to fetch images, you will need to set a field in your `.env` with the following format. To see an example, see [.env.example](../.env.example)

```
POWER_WORKSPACE_<zone-of-workspace>=<workspace-guid>
```

To find the GUIDs and locations of your workspaces, the following IBM Cloud CLI command can be run in a terminal window or an IBM Cloud Shell:

```
ibmcloud resource service-instances --service-name power-iaas --output json | jq -r '.[]? | "\(.guid), \(.name), \(.region_id)"'
```

*For instructions on how to install the IBM Cloud CLI, click [here](https://cloud.ibm.com/docs/cli?topic=cli-getting-started)*
17 changes: 17 additions & 0 deletions .docs/powervs-poc.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,20 @@ After deploying the PoC resources additional configuration in the VSI operating
Any additional non-boot disk (rootvg, *SYSBAS, etc) volumes will be blank and require formatting, volume group restores, mount point configuration, ASP configuration, etc depending on the operating system and intended use case.

The VPC VSIs can also be configured to serve utility purposes such as acting as an internet proxy for the Power VSIs, as a jump host, an NFS server, or any other utility functions.

### Configuring the on-premises VPN gateway

Now that the PowerVS POC environment is setup. The next step is to configure on-premises VPN gateway peer to connect to your IBM Cloud VPN Gateway for Power Virtual Server workspace.

Here are the list of fields and values to be used to setup on-prem VPN gateway:

* VPN Mode: Policy based routing.
* Peer gateway address: Use IBM VPN gateway active public <IP address> as peer address.
> * You can find this address from [IBM cloud console](https://cloud.ibm.com/).
> * From left menu click on `VPC Infrastructures > VPNs`.
> * Select the region where VPN has been deployed and all VPNs in that region will be listed.
> * Read the `Gateway IP` of the peer VPN from the list.
* Preshared Key: Shared between both VPNs to establish connection.
* Peer CIDR: IBM VPC CIDRs + IBM PowerVS CIDRs to allow communication into IBM cloud environment via VPN.
* IKE policy: IKEv2
40 changes: 40 additions & 0 deletions .docs/running-terraform-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Running the Terraform Files

After creating a deployment using the GUI, users can download a file called `craig.zip`. Included in this file are all the Terraform files needed to create your environment. In addition, your environment configuration is saved as `craig.json` and can easily be imported into the GUI for further customization.

## Prerequisites

- Terraform v1.3 or higher
- Terraform CLI
- IBM Cloud Platform API Key

### 1. Initializing the Directory

After unzipping craig.zip, enter the containing folder from your terminal. In your directory, run the following command to install needed providers and to initialize the directory:
```
terraform init
```

### 2. Adding Environment Variables

Once your environment has been initialized, add your IBM Cloud Platform API key to the environment. This can be done by exporting your API key as an environment variable. Once that's complete, run the following command to plan your terraform directory.

```
terraform plan
```

### 3. Creating Resources

Resources can be created from the directory by running the Terraform Apply command after a successful plan

```
terraform apply
```

### 4. Destroying Resources

To destroy your resources, use the following command. This will **delete all resources** provisioned by the template.

```
terraform destroy
```
Loading

0 comments on commit 173467e

Please sign in to comment.