Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Scaffolder committed Nov 30, 2023
0 parents commit 9c24146
Show file tree
Hide file tree
Showing 50 changed files with 1,760 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 120

[*.java]
indent_size = 4
ij_continuation_indent_size = 4
ij_java_align_multiline_parameters = true
ij_java_align_multiline_parameters_in_calls = true
ij_java_call_parameters_new_line_after_left_paren = true
ij_java_call_parameters_right_paren_on_new_line = true
ij_java_call_parameters_wrap = on_every_item
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SERVER_PORT=8080
7 changes: 7 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"local>hmcts/.github:renovate-config",
"local>hmcts/.github//renovate/automerge-all"
]
}
24 changes: 24 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Build
run: ./gradlew check
- name: Dependency check
run: ./gradlew dependencyCheckAggregate
36 changes: 36 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time.
#
# You can adjust the behavior by modifying this file.
# For more information, see:
# https://github.com/actions/stale
name: Mark stale issues and pull requests

on:
schedule:
- cron: '30 3 * * *'

jobs:
stale:

runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write

steps:
- uses: actions/stale@v8
with:
repo-token:
stale-issue-message: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
stale-pr-message: >
This pull request has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
stale-issue-label: 'stale'
stale-pr-label: 'stale'
days-before-close: '4'
days-before-stale: '7'
exempt-pr-labels: 'pinned,dependencies'
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.gradle
/build/
!gradle/wrapper/gradle-wrapper.jar
*.class
bin/main/application.yaml

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans

### IntelliJ IDEA ###
.idea
/out
*.iws
*.iml
*.ipr

.DS_Store
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# renovate: datasource=github-releases depName=microsoft/ApplicationInsights-Java
ARG APP_INSIGHTS_AGENT_VERSION=3.4.18
ARG PLATFORM=""
# Application image

FROM hmctspublic.azurecr.io/base/java${PLATFORM}:21-distroless

COPY lib/applicationinsights.json /opt/app/
COPY build/libs/labs-hub-ngfw-poc.jar /opt/app/

EXPOSE 8080
CMD [ "labs-hub-ngfw-poc.jar" ]
12 changes: 12 additions & 0 deletions Jenkinsfile_CNP
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!groovy

@Library("Infrastructure")

def type = "java"
def product = "labs"
def component = "hub-ngfw-poc"

// docs:
// 1. https://github.com/hmcts/cnp-jenkins-library
// 2. https://hmcts.github.io/ways-of-working/common-pipeline/common-pipeline.html#common-pipeline
withPipeline(type, product, component) {}
15 changes: 15 additions & 0 deletions Jenkinsfile_nightly
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!groovy

properties([
// H allow predefined but random minute see https://en.wikipedia.org/wiki/Cron#Non-standard_characters
pipelineTriggers([cron('H 07 * * 1-5')])
])

@Library("Infrastructure")

def type = "java"
def product = "labs"
def component = "hub-ngfw-poc"

// docs: https://github.com/hmcts/cnp-jenkins-library#nightly-pipeline
withNightlyPipeline(type, product, component) {}
12 changes: 12 additions & 0 deletions Jenkinsfile_parameterized
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!groovy

@Library("Infrastructure")

def type = "java"
def product = "labs"
def component = "hub-ngfw-poc"

// docs:
// 1. https://github.com/hmcts/cnp-jenkins-library
// 2. https://hmcts.github.io/ways-of-working/common-pipeline/common-pipeline.html#common-pipeline
withPipeline(type, product, component) {}
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2021 HMCTS (HM Courts & Tribunals Service)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# labs-hub-ngfw-poc


The application exposes health endpoints (http://localhost:8080/health) and metrics endpoint
(http://localhost:8080/metrics).

## Notes

JUnit 5 is enabled by default in the project. Please refrain from using JUnit4 and use the next generation

## Building and deploying the application

### Building the application

The project uses [Gradle](https://gradle.org) as a build tool. It already contains
`./gradlew` wrapper script, so there's no need to install gradle.

To build the project execute the following command:

```bash
./gradlew build
```

### Running the application

Create the image of the application by executing the following command:

```bash
./gradlew assemble
```

Create docker image:

```bash
docker-compose build
```

Run the distribution (created in `build/install/spring-boot-template` directory)
by executing the following command:

```bash
docker-compose up
```

This will start the API container exposing the application's port
(set to `4550` in this template app).

In order to test if the application is up, you can call its health endpoint:

```bash
curl http://localhost:4550/health
```

You should get a response similar to this:

```
{"status":"UP","diskSpace":{"status":"UP","total":249644974080,"free":137188298752,"threshold":10485760}}
```

### Alternative script to run application

To skip all the setting up and building, just execute the following command:

```bash
./bin/run-in-docker.sh
```

For more information:

```bash
./bin/run-in-docker.sh -h
```

Script includes bare minimum environment variables necessary to start api instance. Whenever any variable is changed or any other script regarding docker image/container build, the suggested way to ensure all is cleaned up properly is by this command:

```bash
docker-compose rm
```

It clears stopped containers correctly. Might consider removing clutter of images too, especially the ones fiddled with:

```bash
docker images

docker image rm <image-id>
```

There is no need to remove postgres and java or similar core images.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

52 changes: 52 additions & 0 deletions acb.tpl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: 1.0-preview-1
steps:
- id: pull-base-image-amd64
cmd: docker pull --platform linux/amd64 hmctspublic.azurecr.io/base/java:17-distroless && docker tag hmctspublic.azurecr.io/base/java:17-distroless hmctspublic.azurecr.io/base/java/linux/amd64:17-distroless
when: ["-"]
keep: true

- id: runtime-amd64
build: >
-t {{.Run.Registry}}/{{CI_IMAGE_TAG}}-amd64
--build-arg PLATFORM=/linux/amd64
--platform linux/amd64
.
when:
- pull-base-image-amd64
keep: true

- id: pull-base-image-arm64
cmd: docker pull --platform linux/arm64 hmctspublic.azurecr.io/base/java:17-distroless && docker tag hmctspublic.azurecr.io/base/java:17-distroless hmctspublic.azurecr.io/base/java/linux/arm64:17-distroless
when:
- pull-base-image-amd64
keep: true

- id: runtime-arm64
build: >
-t {{.Run.Registry}}/{{CI_IMAGE_TAG}}-arm64
--build-arg PLATFORM=/linux/arm64
--platform linux/arm64/v8
.
when:
- pull-base-image-arm64
keep: true

- id: push-images
push:
- "{{.Run.Registry}}/{{CI_IMAGE_TAG}}-amd64"
- "{{.Run.Registry}}/{{CI_IMAGE_TAG}}-arm64"
when:
- runtime-amd64
- runtime-arm64

- id: manifest-create
cmd: docker manifest create {{.Run.Registry}}/{{CI_IMAGE_TAG}} {{.Run.Registry}}/{{CI_IMAGE_TAG}}-amd64 {{.Run.Registry}}/{{CI_IMAGE_TAG}}-arm64
when:
- push-images
keep: true

- id: manifest-push
cmd: docker manifest push --purge {{.Run.Registry}}/{{CI_IMAGE_TAG}}
when:
- manifest-create
keep: true
Loading

0 comments on commit 9c24146

Please sign in to comment.