Skip to content

Commit 7a9d985

Browse files
committed
initial app and tests
1 parent f078d58 commit 7a9d985

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3962
-1
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!target/*-runner
3+
!target/*-runner.jar
4+
!target/lib/*
5+
!target/quarkus-app/*

.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#Maven
2+
target/
3+
pom.xml.tag
4+
pom.xml.releaseBackup
5+
pom.xml.versionsBackup
6+
release.properties
7+
8+
# Eclipse
9+
.project
10+
.classpath
11+
.settings/
12+
bin/
13+
14+
# IntelliJ
15+
.idea
16+
*.ipr
17+
*.iml
18+
*.iws
19+
20+
# NetBeans
21+
nb-configuration.xml
22+
23+
# Visual Studio Code
24+
.vscode
25+
.factorypath
26+
27+
# OSX
28+
.DS_Store
29+
30+
# Vim
31+
*.swp
32+
*.swo
33+
34+
# patch
35+
*.orig
36+
*.rej
37+
38+
# Local environment
39+
.env
40+
41+
deployment/mongo-volume
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2007-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import java.net.*;
17+
import java.io.*;
18+
import java.nio.channels.*;
19+
import java.util.Properties;
20+
21+
public class MavenWrapperDownloader {
22+
23+
private static final String WRAPPER_VERSION = "0.5.6";
24+
/**
25+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
26+
*/
27+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29+
30+
/**
31+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32+
* use instead of the default one.
33+
*/
34+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35+
".mvn/wrapper/maven-wrapper.properties";
36+
37+
/**
38+
* Path where the maven-wrapper.jar will be saved to.
39+
*/
40+
private static final String MAVEN_WRAPPER_JAR_PATH =
41+
".mvn/wrapper/maven-wrapper.jar";
42+
43+
/**
44+
* Name of the property which should be used to override the default download url for the wrapper.
45+
*/
46+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
47+
48+
public static void main(String args[]) {
49+
System.out.println("- Downloader started");
50+
File baseDirectory = new File(args[0]);
51+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
52+
53+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
54+
// wrapperUrl parameter.
55+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
56+
String url = DEFAULT_DOWNLOAD_URL;
57+
if(mavenWrapperPropertyFile.exists()) {
58+
FileInputStream mavenWrapperPropertyFileInputStream = null;
59+
try {
60+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61+
Properties mavenWrapperProperties = new Properties();
62+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64+
} catch (IOException e) {
65+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66+
} finally {
67+
try {
68+
if(mavenWrapperPropertyFileInputStream != null) {
69+
mavenWrapperPropertyFileInputStream.close();
70+
}
71+
} catch (IOException e) {
72+
// Ignore ...
73+
}
74+
}
75+
}
76+
System.out.println("- Downloading from: " + url);
77+
78+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79+
if(!outputFile.getParentFile().exists()) {
80+
if(!outputFile.getParentFile().mkdirs()) {
81+
System.out.println(
82+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
83+
}
84+
}
85+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
86+
try {
87+
downloadFileFromURL(url, outputFile);
88+
System.out.println("Done");
89+
System.exit(0);
90+
} catch (Throwable e) {
91+
System.out.println("- Error downloading");
92+
e.printStackTrace();
93+
System.exit(1);
94+
}
95+
}
96+
97+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
98+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
99+
String username = System.getenv("MVNW_USERNAME");
100+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
101+
Authenticator.setDefault(new Authenticator() {
102+
@Override
103+
protected PasswordAuthentication getPasswordAuthentication() {
104+
return new PasswordAuthentication(username, password);
105+
}
106+
});
107+
}
108+
URL website = new URL(urlString);
109+
ReadableByteChannel rbc;
110+
rbc = Channels.newChannel(website.openStream());
111+
FileOutputStream fos = new FileOutputStream(destination);
112+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113+
fos.close();
114+
rbc.close();
115+
}
116+
117+
}

.mvn/wrapper/maven-wrapper.jar

49.5 KB
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,57 @@
1-
# lodestar-artifacts
1+
# LodeStar Artifacts
2+
3+
This project provides artifact data for LodeStar.
4+
5+
The API is document via swagger and is available at `/q/swagger-ui`
6+
7+
----
8+
9+
## Configuration
10+
11+
The following environment variables are available:
12+
13+
### Logging
14+
| Name | Default | Description|
15+
|------|---------|------------|
16+
| LODESTAR_LOGGING | DEBUG | Logging to the base source package |
17+
| LODESTAR_LOGGING | DEBUG | Minimum logging level for the base package |
18+
| MONGODB_USER | mongouser | The database user |
19+
| MONGODB_PASSWORD | mongopassword | The database password |
20+
| DATABASE_SERVICE_NAME | localhost:27017 | The host and port of the database |
21+
| MONGODB_DATABASE | artifacts | The database name |
22+
23+
| GITLAB_API_URL | https://acmegit.com | The url to Gitlab |
24+
| GITLAB_TOKEN | t | The Access Token for Gitlab |
25+
26+
| GROUP_PARENT_ID | 1234 | Gitlab group ID containing engagements |
27+
| DEFAULT_BRANCH | master | Default branch to use if default not found for project |
28+
| DEFAULT_COMMIT_MESSAGE | updated artifacts list | Default commit message used if diff fails |
29+
| DEFAULT_PAGE_SIZE | 20 | Default number of artifacts that will be returned if pageSize not specified |
30+
31+
## Deployment
32+
33+
See the deployment [readme](./deployment) for information on deploying to a OpenShift environment
34+
35+
## Running the application locally
36+
37+
### MongoDB
38+
39+
A MongoDB database is needed for development. To spin up a docker MongoDB container run the following
40+
41+
```
42+
cd deployment
43+
docker-compose up
44+
```
45+
46+
### Local Dev
47+
48+
You can run your application in dev mode that enables live coding using:
49+
50+
```
51+
export GITLAB_API_URL=https://gitlab.com/
52+
export GITLAB_TOKEN=token
53+
export GROUP_PARENT_ID=<your-group-id>
54+
mvn quarkus:dev
55+
```
56+
57+
> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.

deployment/Chart.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: v2
2+
name: lodestar-backend
3+
description: A Helm chart to deploy the backend (coordination API) of Lodestar
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
version: 0.1.0
18+
19+
# This is the version number of the application being deployed. This version number should be
20+
# incremented each time you make changes to the application.
21+
appVersion: 1.0.0

deployment/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Development on OpenShift
2+
3+
## Getting Started With Helm
4+
5+
This directory contains a Helm chart which can be used to deploy a development version of this app for rapid testing.
6+
7+
Before you use it, you will need to download & install Helm 3.
8+
9+
If you are not familiar with Helm - how to configure it and run - you can start with this quickstart:
10+
11+
[https://helm.sh/docs/intro/quickstart](https://helm.sh/docs/intro/quickstart)
12+
13+
## Using This Chart
14+
15+
1. Clone the target repo:
16+
17+
```
18+
git clone https://github.com/rht-labs/lodestar-artifacts
19+
```
20+
21+
2. Change into to the `deployment` directory:
22+
23+
```
24+
cd lodestar-artifacts/deployment
25+
```
26+
27+
3. Deploy using the following Helm command:
28+
29+
```shell script
30+
helm template . \
31+
--values values-dev.yaml \
32+
--set git.uri=<your fork> \
33+
--set git.ref=<your branch> \
34+
--set api.gitlab=<gitlabUrl> \
35+
--set tokens.gitlab=<gitlabToken> \
36+
--set db.mongodbServiceName=lodestar-artifacts-mongodb \
37+
--set db.mongodbUser=<your-mongodb-user> \
38+
--set db.mongodbPassword=<your-mongodb-password> \
39+
--set db.mongodbDatabase=artifacts \
40+
--set db.mongodbAdminPassword=<your-mongodb-admin-password> \
41+
| oc apply -f -
42+
```
43+
44+
It accepts the following variables
45+
46+
| Variable | Use |
47+
|---|---|
48+
| `git.uri` | The HTTPS reference to the repo (your fork!) to build |
49+
| `git.ref` | The branch name to build |
50+
| `api.gitlab` | The base URL of the GitLab instance to use |
51+
| `db.mongodbServiceName` | MongoDB service name |
52+
| `db.mongodbUser` | Application user for MongoDB |
53+
| `db.mongodbPassword` | Application user password for MongoDB |
54+
| `db.mongodbDatabase` | Application database name |
55+
| `db.mongodbAdminPassword` | Admin password for MongoDB |
56+
57+
This will spin up all of the usual resources that this service needs in production, plus a `BuildConfig` configured to build it from source from the Git repository specified. To trigger this build, use `oc start-build lodestar-artifacts`. To trigger a build from the source code on your machine, use `oc start-build lodestar-artifacts --from-dir=. -F`

deployment/docker-compose.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: '3'
2+
services:
3+
database:
4+
image: 'mongo'
5+
container_name: 'artifacts-mongo'
6+
environment:
7+
- MONGO_INITDB_DATABASE=artifacts
8+
- MONGO_INITDB_ROOT_USERNAME=mongouser
9+
- MONGO_INITDB_ROOT_PASSWORD=mongopassword
10+
- MONGODB_USER=mongouser
11+
- MONGODB_PASSWORD=mongopassword
12+
volumes:
13+
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
14+
- ./mongo-volume:/data/db
15+
ports:
16+
- '27017-27019:27017-27019'

deployment/init-mongo.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
db.createUser(
2+
{
3+
user : "mongouser",
4+
pwd : "mongopassword",
5+
roles : [
6+
{
7+
role: "readWrite",
8+
db: "engagement"
9+
}
10+
]
11+
}
12+
)

0 commit comments

Comments
 (0)