Code Monkey home page Code Monkey logo

image-builder-frontend's Introduction

Image Builder Frontend

Principles

  1. We want to use the latest and greatest web technologies.
  2. We want to expose all the options and customizations possible, even if not all are visible by default.
  3. The default path should be ‘short(est)’ clickpath, which should be determined in a data-driven way.
  4. This is an Insights application, so it abides by some rules and standards of Insights.

Table of Contents

  1. How to build and run image-builder-frontend
    1. Frontend Development
    2. Backend Development
  2. File structure
  3. Style Guidelines
  4. Test Guidelines

How to build and run image-builder-frontend

Frontend Development

To develop the frontend you can use a proxy to run image-builder-frontend locally against the chrome and backend at console.redhat.com.

Working against the production environment is preferred, as any work can be released without worrying if a feature from stage has been released yet.

Nodejs and npm version

Make sure you have npm@7 and node 15+ installed. If you need multiple versions of nodejs check out nvm.

Webpack proxy

  1. run npm ci

  2. run npm run prod-beta. This command uses a prod-beta env by default. Configure your environment by the env attribute in dev.webpack.config.js.

  3. Secondly redirect a few prod.foo.redhat.com to localhost, if this has not been done already.

echo "127.0.0.1 prod.foo.redhat.com" >> /etc/hosts
  1. open browser at https://prod.foo.redhat.com:1337/beta/insights/image-builder

Webpack proxy (staging) -- Runs with image-builder's stage deployment

  1. run npm ci

  2. run npm run stage-beta. This command uses a stage-beta env by default. Configure your environment by the env attribute in dev.webpack.config.js.

  3. Secondly redirect a few stage.foo.redhat.com to localhost, if this has not been done already.

echo "127.0.0.1 stage.foo.redhat.com" >> /etc/hosts
  1. open browser at https://stage.foo.redhat.com:1337/beta/insights/image-builder

Insights proxy (deprecated)

  1. Clone the insights proxy: https://github.com/RedHatInsights/insights-proxy

  2. Setting up the proxy

    Choose a runner (podman or docker), and point the SPANDX_CONFIG variable to profile/local-frontend.js included in image-builder-frontend.

        sudo insights-proxy/scripts/patch-etc-hosts.sh
        export RUNNER="podman"
        export SPANDX_CONFIG=$PATH_TO/image-builder-frontend/profiles/local-frontend.js
        sudo -E insights-proxy/scripts/run.sh
    
  3. Starting up image-builder-frontend

    In the image-builder-frontend checkout directory

        npm install
        npm start
    

The UI should be running on https://prod.foo.redhat.com:1337/beta/insights/image-builder/landing. Note that this requires you to have access to either production or stage (plus VPN and proxy config) of insights.

API endpoints

API endpoints are programmatically generated with the RTKQ library. This sections overview the steps to add new APIs and endpoints.

Add a new API

For an hypothetical API called foobar

  1. Download the foobar api openapi json or yaml representation under api/schema/foobar.json

  2. Create a new "empty" api file under src/store/emptyFoobarApi.ts that has for content:

import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';

import { FOOBAR_API } from '../constants';

// initialize an empty api service that we'll inject endpoints into later as needed
export const emptyFoobarApi = createApi({
  reducerPath: 'foobarApi',
  baseQuery: fetchBaseQuery({ baseUrl: FOO_BAR }),
  endpoints: () => ({}),
});
  1. Declare the new constat FOOBAR_API to the API url in src/constants.js
export const FOOBAR_API = 'api/foobar/v1'
  1. Create the config file for code generation in api/config/foobar.ts containing:
import type { ConfigFile } from '@rtk-query/codegen-openapi';

const config: ConfigFile = {
  schemaFile: '../schema/foobar.json',
  apiFile: '../../src/store/emptyFoobarApi.ts',
  apiImport: 'emptyEdgeApi',
  outputFile: '../../src/store/foobarApi.ts',
  exportName: 'foobarApi',
  hooks: true,
  filterEndpoints: ['getFoo', 'getBar', 'getFoobar'],
};
  1. Update the api.sh script by adding a new line for npx to generate the code:
npx @rtk-query/codegen-openapi ./api/config/foobar.ts &
  1. Update the .eslintignore file by adding a new line for the generated code:
foobarApi.ts
  1. run api generation
npm run api

And voilà!

Add a new endpoint

To add a new endpoint, simply update the api/config/foobar.ts file with new endpoints in the filterEndpoints table.

Unleash feature flags for the frontend

Your user needs to have the corresponding rights, do the same as this MR in internal gitlab https://gitlab.cee.redhat.com/service/app-interface/-/merge_requests/79225 you can ask on the slack channel https://redhat-internal.slack.com/archives/C023YSA47A4 for a merge if your MR stays unchecked for a little while.

Then connect to the following platforms:

Once you have a toggle to work with, on the frontend code there's just need to import the useFlag hook and to use it. You can get some inspiration from existing flags:

https://github.com/RedHatInsights/image-builder-frontend/blob/c84b493eba82ce83a7844943943d91112ffe8322/src/Components/ImagesTable/ImageLink.js#L99

Mocking flags for tests

Flags can be mocked for the unit tests to access some feature. Checkout: https://github.com/RedHatInsights/image-builder-frontend/blob/c84b493eba82ce83a7844943943d91112ffe8322/src/test/Components/CreateImageWizard/CreateImageWizard.test.js#L74

If the two possible code path accessible via the toggles are defined in the code base, then it's good practice to test the two of them. If not, only test what's actually owned by the frontend project.

Cleaning the flags

Unleash toggles are expected to live for a limited amount of time, documentation specify 40 days for a release, we should keep that in mind for each toggle we're planning on using.

Backend Development

To develop both the frontend and the backend you can again use the proxy to run both the frontend and backend locally against the chrome at cloud.redhat.com. For instructions see the osbuild-getting-started project.

File Structure

Quick Reference

Directory Description
/api API schema and config files
/config webpack configuration
/devel tools for local development
/src source code
/src/Components source code split by individual components
/src/test test utilities
/src/test/mocks mock handlers and server config for MSW
/src/store Redux store
/src/api.js API calls

Style Guidelines

This project uses eslint's recommended styling guidelines. These rules can be found here: https://eslint.org/docs/rules/

To run the linter, use:

npm run lint

Any errors that can be fixed automatically, can be corrected by running:

npm run lint --fix

All the linting rules and configuration of eslint can be found in .eslintrc.yml.

Additional eslint rules

There are also additional rules added to enforce code style. Those being:

  • import/order -> enforces the order in import statements and separates them into groups based on their type
  • prefer-const -> enforces use of const declaration for variables that are never reassigned
  • no-console -> throws an error for any calls of console methods leftover after debugging

Test Guidelines

This project is tested using the Jest framework, React Testing Library, and the Mock Service Worker library.

All UI contributions must also include a new test or update an existing test in order to maintain code coverage.

Running the tests

To run the unit tests, the linter, and the code coverage check run:

npm run test

These tests will also be run in our CI when a PR is opened.

Using MSW data in development

If you want to develop in environment with mocked data, run the command npm run stage-beta:msw.

Enabling MSW

In a case you're seeing Error: [MSW] Failed to register the Service Worker in console, you might also need to configure SSL certification on your computer.

In order to do this install mkcert

After the installation, go to the /node_modules/.cache/webpack-dev-server folder and run following commands:

  1. mkcert -install  to create a new certificate authority on your machine
  2. mkcert prod.foo.redhat.com  to create the actual signed certificate

Mac Configuration

Follow these steps to find and paste the certification file into the 'Keychain Access' application:

  1. Open the 'Keychain Access' application.

  2. Select 'login' on the left side.

  3. Navigate to the 'Certificates' tab.

  4. Drag the certification file (located at /image-builder-frontend/node_modules/.cache/webpack-dev-server/server.pem) to the certification list.

  5. Double-click on the added certificate (localhost certificate) to open the localhost window.

  6. Open the 'Trust' dropdown menu.

  7. Set all options to 'Always Trust'.

  8. Close the localhost screen.

  9. Run npm run stage-beta:msw and open the Firefox browser to verify that it is working as expected.

API endpoints

API slice definitions are generated using the @rtk-query/codegen-openapi package.

OpenAPI schema for the endpoints are stored in /api/schema. Their corresponding configuration files are stored in /api/config. Each endpoint has a corresponding empty API slice and generated API slice which are stored in /src/store.

To generate or update API slice definitions, run:

npm run api

image-builder-frontend's People

Contributors

adiabramovitch avatar amirfefer avatar andrewgdewar avatar atodorov avatar avitova avatar chloenayon avatar cockpituous avatar croissanne avatar dependabot[bot] avatar ezr-ondrej avatar github-actions[bot] avatar hyperkid123 avatar jgiardino avatar jkozol avatar jrusz avatar karelhala avatar kingsleyzissou avatar lavocatt avatar ldjebran avatar lucasgarfield avatar major avatar mgold1234 avatar ochosi avatar ondrejbudai avatar regexowl avatar schuellerf avatar shaded-enmity avatar teg avatar thozza avatar yuxisun1217 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

image-builder-frontend's Issues

Some questions about deploy the image-builder-frontend locally

Hi there,

Greetings! I'm a QE from Virt QE team and interested in this project. I tried to install image-builder-frontend following the README, but met some problems:

(Step1 and step2 works well.)

  1. In Step 3 Starting up osbuild-composer-cloud: I prepared a Fedora 33, and installed osbuild-composer-26-2.fc33.x86_64, but there's no osbuild-composer-cloud.socket. Should I start osbuild-composer.socket instead?
  2. Still in Step 3, when I run "systemctl enable --now osbuild-remote-worker@localhost:8704" it reports:
    Jan 07 08:57:44 jslave-azure-fedora33 osbuild-worker[72493]: 2021/01/07 08:57:44 Error creating TLS config: open /etc/osbuild-composer/ca-crt.pem: no such file or directory
    Jan 07 08:57:44 jslave-azure-fedora33 systemd[1]: osbuild-remote-worker@localhost:8704.service: Main process exited, code=exited, status=1/FAILURE
    I don't know where I can get the "/etc/osbuild-composer/ca-crt.pem", and should I run this service in this way?

I'm fresh new about this and I'm blocked here now...Could anyone please help to have a look? Thank you so much!

Ask the image builder service for content

Right now some values like available distributions, architectures, and image types are hardcoded. There are some endpoints in osbuild/image-builder, see https://github.com/osbuild/image-builder/blob/master/internal/server/api.yaml

  • /distributions returns a list of available distributions (each having a name rhel-8 and a description Red Hat Enter...)

  • /architectures/{distribution} returns a list of archs and image types available for that arch, for instance /architectures/rhel-8 would return [{ arch: 'x86_64', image_types: ['qcow2']}]

Query those instead of hardcoding values.

CreateImageWizard: just clicking `Next` shouldn't lead to error

It would be great if clicking Next without changing anything either gave correct defaults (that would not error out in review) or wouldn't work at all (greyed out Next button?).

  • We should require at least one cloud provider to be selected, if none is, disable the Next button.
  • If AWS is selected, don't allow going past the Upload to AWS screen unless a 12-digit account number has been entered.
  • Default to not register, and if registering is enabled, require an activation key (do we have a way to verify at least the format?)
  • If the Review screen has errors, disable the Create button, now we can go ahead and create an image that we know will fail.

[RFE] button text label to match text

https://bugzilla.redhat.com/show_bug.cgi?id=1954611

“While creating a image on https://cloud.redhat.com/beta/insights/image-builder/imagewizard, in the Review window, the text under "Review" says: Review the information and click Create image to create the image using the following criteria.

However, the button says just "Create" instead of "Create image".”

The reporter suggest to change button label to "Create image" but I think it's a bit long in a button. I prefer to change the introduction text from "Create image" to "Create button".

Rework upload state in image wizard

The upload state shouldn't be directly translatable to an upload request. This turns out to be too confusing to maintain.

So let's just build the upload request when creating the rest of the compose request.

chosen packages disappears

  1. select a package
  2. go to a different step
  3. go back to the packages step, selected packages are not shown

The packages are included in the image.

Required information is missing when trying to upload to Azure

Screenshot_2021-04-13 Image Builder(1)

I've tried creating an image and uploading to Azure but I got this message telling me required info is missing.

Then I went back and saw that I need to authorize Image Builder with Azure. I clicked the link and followed the prompts entering my username and password. After redirect I've arrived at https://login.microsoftonline.com/common/oauth2/nativeclient showing a blank page. According to @Gundersanne this means authorized!

So I've closed the wizard dialog which I still had open at this time and started again:

  1. Create new image
  2. Select Microsoft Azure as upload target
  3. Enter my azure credentials, select packages, etc.

I still get the same error message, telling me that something is missing but not telling me what. I have no idea how to proceed further.

Wizard: document what registraiton does

Currently this subscribes the image and registeres with insights. Down tho road we want insights registration to be opt-out, but either way we should make sure to explain what registration means.

RFE: Display AMI name/ID

I've built an AWS image and provided my account id so that it gets uploaded to EC2. Upon completion the UI looks like this:
Screenshot_2021-04-13 Image Builder

I don't know what my AMI name/ID is.

Following:
https://osbuild.pages.redhat.com/internal-guides/image-builder/stage/image-builder-api.html#using-the-built-aws-image

I was able to discover (looking at last created AMI):

AMI ID: ami-044e50df2b5af4af5
AMI Name: composer-api-8753dec5-c080-43ee-b67a-64773116e2fb
Source: <account_id>/composer-api-8753dec5-c080-43ee-b67a-64773116e2fb

None of the IDs matches the one displayed on the UI.

Request for enhancements:

  1. Use the same UUID in AMI name as used for the image to make it easier to match the two
  2. Since we've got the ID inside the API response show that in the UI to make it explicit
  3. (stretch) - If I am not mistaken it takes some time for the AMI to appear inside AWS (that was my
    impression since I first ordered all private AMIs by date and didn't see anything from today) - a warning message would go a long way to inform the user that AWS needs to perform its internal sync before the AMI can show. Otherwise could lead to "my image didn't show up" requests.

Search with enter key

When searching for a package the pressing the enter key does not trigger a search. In order to fix this we either need to use an html version of the Dual List Selector or request access to the unfiltered key presses since currently no onAvailableOptionsSearchInputChanged event is fired when the enter key is pressed.

Question: Why AWS target environment default region is eu-west-2

Why is the default eu-west-2 ? RHEL's default timezone is America/New York and IIRC AWS default region is us-east-1.

Do you think we should change the defaults ?

We could also make this field into a select and just provide all of them but that's outside the scope of this question.

Don't activate CentOS Stream images

Although I think that it's possible to subscribe a non-RHEL image, it doesn't make much sense for the majority of use-cases.

I propose to hide the activation step when CentOS Stream is selected.

Add pagination to the packages step

Currently the packages step fetches 100 results. However the api does support pagination, so maybe when reaching the end of the scroll it should fetch the next 100?

[RFE] "OAuth permissions" text shortening

https://bugzilla.redhat.com/show_bug.cgi?id=1954598

"""
Description of problem: On "Target Environment - Upload to Azure" window, the "OAuth permissions" text is a bit longer and I would like to suggest a short version:

"To authorize Image Builder to push images to Microsoft Azure, the account owner must configure Image Builder as an authorized application and give it the role of "Contributor" to at least one resource group.
Learn more about OAuth 2.0"
"""

Minimal page

Minimal page which simply has a hardcoded image build, and then polls the status.

Update landing page layout

Update Landing Page layout to match the layout that's shown in the design document. This includes:

  • Removing the extra spacing around the page title
  • Adding the basic container for the toolbar, to include only the Create image button at first
  • Adding a table to include the details currently provided to the UI for listing images

Bug - Swap position of Azure & GCP to be alphabetical

Currently, the order we display the three cloud providers is:
Amazon Web Services (AWS)
Microsoft Azure (Azure)
Google Cloud Platform (GCP)

Although the shortened names for these are alphabetical, the long ones are not!

The order this should appear on the first step of the wizard, in substeps, and on the image builder review list should be actually alphabetical:
Amazon Web Services
Google Cloud Platform
Microsoft Azure

Mocks need to be updated -- Edit: Now they are

Building CentOS Stream 8 image doesn't seem to finish

I've selected a CentOS Stream 8 content and AWS upload target. I've selected "bash" as the RPM package which I want inside the image. I get "Image build in progress" for around 30 minutes and the process seems to be stuck.

[RFE] Provide AMI id for newly uploaded images

Once a new image is created and uploaded to EC2 it is difficult to identify the image and thus to locate it in one's EC2 console.

A UUID is provided but it's not clear what that UUID refers to.

Please provide the AMI id of the newly uploaded image so operators can easily find the image in the EC2 portal.

Screenshot from 2021-03-12 13-37-33

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.