-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a0855a
commit 7a89450
Showing
122 changed files
with
25,547 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...n-service/src/main/java/de/openknowledge/sample/infrastructure/openapi/OpenApiFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2019 - 2023 open knowledge GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.openknowledge.sample.infrastructure.openapi; | ||
|
||
import java.util.Map.Entry; | ||
|
||
import org.eclipse.microprofile.openapi.OASFilter; | ||
import org.eclipse.microprofile.openapi.models.Components; | ||
import org.eclipse.microprofile.openapi.models.OpenAPI; | ||
import org.eclipse.microprofile.openapi.models.PathItem; | ||
|
||
public class OpenApiFilter implements OASFilter { | ||
|
||
public void filterOpenAPI(OpenAPI openApi) { | ||
for (Entry<String, PathItem> item: openApi.getPaths().getPathItems().entrySet()) { | ||
if (item.getKey().startsWith("/metrics") || item.getKey().startsWith("/health") || item.getKey().contains("webjars")) { | ||
openApi.getPaths().removePathItem(item.getKey()); | ||
} | ||
} | ||
Components components = openApi.getComponents(); | ||
components.removeSchema("void"); | ||
components.removeSchema("java_lang_Object"); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...validation-service/src/main/java/de/openknowledge/sample/swaggerui/SwaggerUiResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2023 open knowledge GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.openknowledge.sample.swaggerui; | ||
|
||
import static java.util.logging.Level.WARNING; | ||
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; | ||
import static javax.ws.rs.core.Response.Status.NOT_FOUND; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.StringWriter; | ||
import java.util.logging.Logger; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.core.Response; | ||
|
||
/** | ||
* RESTFul endpoint swaggerui | ||
*/ | ||
@ApplicationScoped | ||
@Path("{path: webjars/.*}") | ||
public class SwaggerUiResource { | ||
|
||
private final static Logger LOG = Logger.getLogger(SwaggerUiResource.class.getSimpleName()); | ||
|
||
@GET | ||
public Response getWebJarsResource(@PathParam("path") String path) { | ||
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(String.format("META-INF/resources/%s", path)); | ||
BufferedReader buffer = new BufferedReader(new InputStreamReader(inputStream)); | ||
StringWriter content = new StringWriter()) { | ||
buffer.lines().forEach(content::write); | ||
|
||
String mediaType = path.endsWith(".js") ? "application/javascript" : "text/" + path.substring(path.lastIndexOf('.') + 1); | ||
return Response.ok(content.toString()).type(mediaType).build(); | ||
} catch (NullPointerException e) { | ||
LOG.log(WARNING, "Could not find resource [{0}]", path); | ||
return Response.status(NOT_FOUND).build(); | ||
} catch (IOException e) { | ||
LOG.severe(e.getMessage()); | ||
return Response.status(INTERNAL_SERVER_ERROR).build(); | ||
} | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
address-validation-service/src/main/resources/META-INF/microprofile-config.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mp.openapi.filter=de.openknowledge.sample.infrastructure.openapi.OpenApiFilter |
40 changes: 40 additions & 0 deletions
40
...ss-validation-service/src/main/resources/META-INF/resources/webjars/swagger-ui/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!-- HTML for static distribution bundle build --> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Swagger UI</title> | ||
<link rel="stylesheet" type="text/css" href="./5.4.2/swagger-ui.css" /> | ||
<link rel="stylesheet" type="text/css" href="./5.4.2/index.css" /> | ||
<link rel="icon" type="image/png" href="./5.4.2/favicon-32x32.png" sizes="32x32" /> | ||
<link rel="icon" type="image/png" href="./5.4.2/favicon-16x16.png" sizes="16x16" /> | ||
</head> | ||
|
||
<body> | ||
<div id="swagger-ui"></div> | ||
<script src="./5.4.2/swagger-ui-bundle.js" charset="UTF-8"> </script> | ||
<script src="./5.4.2/swagger-ui-standalone-preset.js" charset="UTF-8"> </script> | ||
<script> | ||
window.onload = function() { | ||
window.ui = SwaggerUIBundle({ | ||
urls: [ | ||
{ | ||
name: "Address Validation Service", | ||
url: "../../openapi" | ||
} | ||
], | ||
dom_id: '#swagger-ui', | ||
deepLinking: true, | ||
presets: [ | ||
SwaggerUIBundle.presets.apis, | ||
SwaggerUIStandalonePreset | ||
], | ||
plugins: [ | ||
SwaggerUIBundle.plugins.DownloadUrl | ||
], | ||
layout: "StandaloneLayout" | ||
}); | ||
}; | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Stage 1 - Create yarn install skeleton layer | ||
FROM node:18-bullseye-slim AS packages | ||
|
||
WORKDIR /app | ||
COPY package.json yarn.lock ./ | ||
|
||
COPY packages packages | ||
|
||
# Comment this out if you don't have any internal plugins | ||
#COPY plugins plugins | ||
|
||
RUN find packages \! -name "package.json" -mindepth 2 -maxdepth 2 -exec rm -rf {} \+ | ||
|
||
# Stage 2 - Install dependencies and build packages | ||
FROM node:18-bullseye-slim AS build | ||
|
||
# install sqlite3 dependencies | ||
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ | ||
--mount=type=cache,target=/var/lib/apt,sharing=locked \ | ||
apt-get update && \ | ||
apt-get install -y --no-install-recommends libsqlite3-dev python3 build-essential && \ | ||
yarn config set python /usr/bin/python3 | ||
|
||
USER node | ||
WORKDIR /app | ||
|
||
COPY --from=packages --chown=node:node /app . | ||
|
||
# Stop cypress from downloading it's massive binary. | ||
ENV CYPRESS_INSTALL_BINARY=0 | ||
RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid=1000 \ | ||
yarn install --frozen-lockfile --network-timeout 600000 | ||
|
||
COPY --chown=node:node . . | ||
|
||
RUN yarn tsc | ||
RUN yarn --cwd packages/backend build | ||
# If you have not yet migrated to package roles, use the following command instead: | ||
# RUN yarn --cwd packages/backend backstage-cli backend:bundle --build-dependencies | ||
|
||
RUN mkdir packages/backend/dist/skeleton packages/backend/dist/bundle \ | ||
&& tar xzf packages/backend/dist/skeleton.tar.gz -C packages/backend/dist/skeleton \ | ||
&& tar xzf packages/backend/dist/bundle.tar.gz -C packages/backend/dist/bundle | ||
|
||
# Stage 3 - Build the actual backend image and install production dependencies | ||
FROM node:18-bullseye-slim | ||
|
||
# Install sqlite3 dependencies. You can skip this if you don't use sqlite3 in the image, | ||
# in which case you should also move better-sqlite3 to "devDependencies" in package.json. | ||
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ | ||
--mount=type=cache,target=/var/lib/apt,sharing=locked \ | ||
apt-get update && \ | ||
apt-get install -y --no-install-recommends libsqlite3-dev python3 build-essential curl && \ | ||
yarn config set python /usr/bin/python3 | ||
|
||
# From here on we use the least-privileged `node` user to run the backend. | ||
USER node | ||
|
||
# This should create the app dir as `node`. | ||
# If it is instead created as `root` then the `tar` command below will fail: `can't create directory 'packages/': Permission denied`. | ||
# If this occurs, then ensure BuildKit is enabled (`DOCKER_BUILDKIT=1`) so the app dir is correctly created as `node`. | ||
WORKDIR /app | ||
|
||
# Copy the install dependencies from the build stage and context | ||
COPY --from=build --chown=node:node /app/yarn.lock /app/package.json /app/packages/backend/dist/skeleton/ ./ | ||
|
||
RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid=1000 \ | ||
yarn install --frozen-lockfile --production --network-timeout 600000 | ||
|
||
# Copy the built packages from the build stage | ||
COPY --from=build --chown=node:node /app/packages/backend/dist/bundle/ ./ | ||
|
||
# Copy any other files that we need at runtime | ||
COPY --chown=node:node app-config.yaml ./ | ||
COPY --chown=node:node examples /examples | ||
|
||
# This switches many Node.js dependencies to production mode. | ||
ENV NODE_ENV production | ||
|
||
CMD ["node", "packages/backend", "--config", "app-config.yaml"] |
Oops, something went wrong.