Skip to content

Commit

Permalink
Start the build out of the new UI (#261)
Browse files Browse the repository at this point in the history
* Start the build out of the new UI

* Fix broken test

* Fix build for new ui

* Add a test so build passes

* Add sonar back in

* Add test coverage for ui

* Add initial docs

* Add doc publish action
  • Loading branch information
chrisrohr authored Jul 20, 2023
1 parent 172130c commit 371332e
Show file tree
Hide file tree
Showing 153 changed files with 13,090 additions and 9,569 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ jobs:
# Setup Node/JS
- uses: actions/setup-node@v3
with:
node-version: 16
cache: 'yarn'
cache-dependency-path: '**/yarn.lock'
node-version: 18
cache: 'npm'
cache-dependency-path: '**/package-lock.json'

# Cache all the things
- name: Cache SonarCloud packages
Expand All @@ -102,19 +102,19 @@ jobs:

# Install dependencies
- name: Install Dependencies
run: yarn install
run: npm install

# Compile the project
- name: Build ui
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
run: yarn build
run: npm run build

# Run the tests
- name: Run ui tests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
run: yarn test:unit:ci:coverage
run: npm run test:unit

# Run Sonar Analysis
- name: SonarCloud Scan
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: docs
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.x
- run: pip install mkdocs
- run: cd docs && mkdocs gh-deploy --force --clean --verbose

59 changes: 59 additions & 0 deletions docs/docs/getting_started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Getting Started

## Prerequisites

* Postgres database (tested on 15.x)
* Java 17+ (if building/running from source)
* Node 18+ (if building/running from source)

## Configuration

The service component will need some configuration items set in order to run successfully. These should be set in a file
named `config.yml`. The following configuration items are available:

| Name | Default | Required | Description |
|----------------------------|------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
| database | none | yes | Database connection information (See https://www.dropwizard.io/en/stable/manual/configuration.html#database) |
| jwtCacheSpec | `expireAfterWrite=60m` | yes | Configuration for the JWT tokens being generated. Default expires after 60 minutes |
| jwtCookieAuth | none | no | JWT cookie configuration information (See https://github.com/dhatim/dropwizard-jwt-cookie-authentication#edit-you-apps-dropwizard-yaml-config-file) |
| auditCleanup.initialDelay | 30s | no | Initial time to wait for cleanup job to start after server startup |
| auditCleanup.intervalDelay | 1d | no | How often to run the cleanup job |
| auditRecordsMaxRetain | 30d | no | How long audit records should be retained. |

## Building and Running from Source

* Clone the repo from [https://github.com/kiwiproject/champagne-service.git](https://github.com/kiwiproject/champagne-service.git)

### Service side

* Build the service:

```shell
cd service
mvn package --DskipTests
```

* Setup the database:

```shell
java -jar target/champagne-service-<version>.jar db migrate config.yml
```

* Run the service:

```shell
java -jar target/champagne-service-<version>.jar server config.yml
```

### UI side

* Run the UI

```shell
cd ui
npm run dev
```

* Access the UI

Open your browser and go to `http://localhost:5173`
Binary file added docs/docs/img/add.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/docs/img/create_component.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/docs/img/create_environment.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/docs/img/create_host.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/docs/img/delete.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/docs/img/disable.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/docs/img/enable.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/docs/img/environments.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/docs/img/expand_button_action.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/docs/img/host_config.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/docs/img/login.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/docs/img/new_component_button.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/docs/img/new_host_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Champagne

Champagne is a service that allows you to toast successful deployments. This service will assist a project in managing builds,
deployments, promotions to different environments and tracking manual deployment steps.
39 changes: 39 additions & 0 deletions docs/docs/user_guide/environments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Environments

The environments page lets a user manage a logical list of deployable environments for the overall system.

![Screenshot](../img/environments.png)

## Creating an environment

1. Click the <img alt="add" src="../../img/add.png" width="40"/> button at the bottom of the screen
2. The create new environment dialog will appear

<img alt="New deployment environment dialog" src="../../img/create_environment.png" width="300"/>

3. Enter the new environment name (**This is required**)
4. Click Save to create the environment

## Enabling/Disabling an environment

Deployable environments can be enabled and disabled. This might be a better option than deleting the environment if there
is historical data related to the environment that should be kept.

**Heads Up!** Enabling and Disabling can only be performed by administrators of the deployable system!

### Disable an environment

To disable an environment, find the row with the environment to be disabled, click the <img alt="disable" src="../../img/disable.png" width="40"/> button.

### Enable an environment

To enable an environment, find the row with the environment to be enabled, click the <img alt="enable" src="../../img/enable.png" width="40"/> button.

## Deleting an environment

Deployable environments can be deleted. Beware, however, that this will also delete all information related to that
deployable environment

**Heads Up!** Deleting can only be performed by administrators of the deployable system!

To delete an environment, find the row with the environment to be deleted and click the <img alt="delete" src="../../img/delete.png" width="40"/> button.
49 changes: 49 additions & 0 deletions docs/docs/user_guide/host_configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Host Configuration

The host configuration page lets a user manage a list of deployable hosts and components for the system.

![Screenshot](../img/host_config.png)

## Creating a host

**Heads Up!** Creating can only be performed by administrators of the deployable system!

1. Click the <img alt="action" src="../../img/expand_button_action.png" width="40"/> button at the bottom of the screen
2. Click the <img alt="new host" src="../../img/new_host_button.png" width="80"/> button
3. The create new host dialog will appear

<img alt="New host dialog" src="../../img/create_host.png" width="300"/>

4. Enter the new host name (**This is required**)
5. Enter any tags for the host (This is how components are linked to hosts). **After entering a tag name, type enter so that the tag gets included**
6. Click Save to create the host

## Deleting a host

Hosts can be deleted. This will _only_ delete the host entry and will _not_ delete any of the components linked to that host.

**Heads Up!** Deleting can only be performed by administrators of the deployable system!

To delete a host, find the row with the host to be deleted and click the <img alt="delete" src="../../img/delete.png" width="40"/> button.

## Creating a component

**Heads Up!** Creating can only be performed by administrators of the deployable system!

1. Click the <img alt="action" src="../../img/expand_button_action.png" width="40"/> button at the bottom of the screen
2. Click the <img alt="new component" src="../../img/new_component_button.png" width="80"/> button
3. The create new host dialog will appear

<img alt="New component dialog" src="../../img/create_component.png" width="300"/>

4. Enter the new component name (**This is required**)
5. Enter the tag for the component (This is how components are linked to hosts). **This is required**
6. Click Save to create the component

## Deleting a component

Components can be deleted. This will delete the component entry and will unlink it from every host matching the tag.

**Heads Up!** Deleting can only be performed by administrators of the deployable system!

To delete a component, find the row with the component to be deleted and click the <img alt="delete" src="../../img/delete.png" width="40"/> button.
9 changes: 9 additions & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
site_name: Champagne
site_url: https://github.com/kiwiproject/champagne-service
theme: readthedocs
nav:
- Overview: index.md
- Getting Started: getting_started.md
- User Guid:
- Environments: user_guide/environments.md
- Host Configuration: user_guide/host_configuration.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.kiwiproject.champagne.dao;

import java.util.List;

import org.jdbi.v3.sqlobject.config.RegisterRowMapper;
import org.jdbi.v3.sqlobject.customizer.Bind;
import org.jdbi.v3.sqlobject.customizer.BindBean;
Expand All @@ -12,13 +10,15 @@
import org.kiwiproject.champagne.dao.mappers.ComponentMapper;
import org.kiwiproject.champagne.model.Component;

import java.util.List;

@RegisterRowMapper(ComponentMapper.class)
public interface ComponentDao {

@SqlQuery("select * from components where tag in (<tags>)")
List<Component> findComponentsByHostTags(@BindList("tags") List<String> tags);

@SqlUpdate("insert into components (component_name, tag) values (:componentName, :tag)")
@SqlUpdate("insert into components (component_name, tag, deployable_system_id) values (:componentName, :tag, :deployableSystemId)")
@GetGeneratedKeys
long insertComponent(@BindBean Component component);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package org.kiwiproject.champagne.dao.mappers;

import static org.kiwiproject.jdbc.KiwiJdbc.instantFromTimestamp;
import org.jdbi.v3.core.mapper.RowMapper;
import org.jdbi.v3.core.statement.StatementContext;
import org.kiwiproject.champagne.model.Component;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.jdbi.v3.core.mapper.RowMapper;
import org.jdbi.v3.core.statement.StatementContext;
import org.kiwiproject.champagne.model.Component;
import static org.kiwiproject.jdbc.KiwiJdbc.instantFromTimestamp;

public class ComponentMapper implements RowMapper<Component> {

@Override
public Component map(ResultSet rs, StatementContext ctx) throws SQLException {
return Component.builder()
.id(rs.getLong("id"))
.createdAt(instantFromTimestamp(rs, "created_at"))
.updatedAt(instantFromTimestamp(rs, "updated_at"))
.componentName(rs.getString("component_name"))
.tag(rs.getString("tag"))
.build();
.id(rs.getLong("id"))
.createdAt(instantFromTimestamp(rs, "created_at"))
.updatedAt(instantFromTimestamp(rs, "updated_at"))
.componentName(rs.getString("component_name"))
.tag(rs.getString("tag"))
.deployableSystemId(rs.getLong("deployable_system_id"))
.build();
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package org.kiwiproject.champagne.resource;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.kiwiproject.champagne.model.AuditRecord.Action.CREATED;
import static org.kiwiproject.champagne.model.AuditRecord.Action.DELETED;
import static org.kiwiproject.champagne.model.AuditRecord.Action.UPDATED;
import static org.kiwiproject.search.KiwiSearching.zeroBasedOffset;

import com.codahale.metrics.annotation.ExceptionMetered;
import com.codahale.metrics.annotation.Timed;
import io.dropwizard.auth.Auth;
Expand All @@ -20,21 +14,16 @@
import org.kiwiproject.jaxrs.exception.JaxrsNotAuthorizedException;
import org.kiwiproject.spring.data.KiwiPage;

import java.util.List;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import java.util.List;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.kiwiproject.champagne.model.AuditRecord.Action.*;
import static org.kiwiproject.search.KiwiSearching.zeroBasedOffset;

@Path("/systems")
@Produces(APPLICATION_JSON)
Expand Down Expand Up @@ -176,4 +165,7 @@ public Response removeUserFromSystem(@PathParam("systemId") long systemId, @Path
deployableSystemDao.deleteUserFromSystem(systemId, userId);
return Response.noContent().build();
}

// TODO: Add endpoint to set and unset existing system user as admin (only can be done by system admins)
// TODO: Add endpoint to retrieve a list of users for the current system (only by system admin)
}
Loading

0 comments on commit 371332e

Please sign in to comment.