Skip to content

Commit 2e63c95

Browse files
committed
.
1 parent ac9a54b commit 2e63c95

File tree

17 files changed

+620
-2
lines changed

17 files changed

+620
-2
lines changed

.github/workflows/build-java.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Build
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- develop
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
10+
jobs:
11+
cache:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
path: java
17+
- run: cd java
18+
- name: Set up JDK 11
19+
uses: actions/setup-java@v1
20+
with:
21+
java-version: 11
22+
# - name: Cache SonarCloud packages
23+
# uses: actions/cache@v1
24+
# with:
25+
# path: ~/.sonar/cache
26+
# key: ${{ runner.os }}-sonar
27+
# restore-keys: ${{ runner.os }}-sonar
28+
- name: Cache Gradle packages
29+
uses: actions/cache@v1
30+
with:
31+
path: |
32+
~/.gradle/caches
33+
~/.gradle/wrapper
34+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle', '**/gradle-wrapper.properties') }}
35+
restore-keys: ${{ runner.os }}-gradle
36+
- name: Build and analyze
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
40+
run: ./gradlew build --info
41+
42+
no-cache:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v3
46+
with:
47+
path: java
48+
fetch-depth: 0
49+
- name: Set up JDK 11
50+
uses: actions/setup-java@v1
51+
with:
52+
java-version: 11
53+
- name: Build and analyze
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
57+
run: ./gradlew build --info

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
build
2+
bin
23
.gradle
34
.vscode
45
.idea
@@ -13,7 +14,7 @@ build
1314
*.rar
1415

1516
# MAC
16-
**/.DS_Store
17+
.DS_Store
1718

1819
# internal
1920
*internal*

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# githubaction
2-
githubaction for AWS, GCP, CDK, Terraform
2+
3+
GCP, Docker, Terraform, Python, Sonarqube
4+
5+
[gke-workload-identity](https://github.com/DevSecOpsSamples/gke-workload-identity/blob/master/.github/workflows/build.yml)
6+
7+
8+
## Cache

build-java.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- develop
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
10+
jobs:
11+
sonarqube:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0
17+
- name: Set up JDK 11
18+
uses: actions/setup-java@v1
19+
with:
20+
java-version: 11
21+
- name: Cache SonarCloud packages
22+
uses: actions/cache@v1
23+
with:
24+
path: ~/.sonar/cache
25+
key: ${{ runner.os }}-sonar
26+
restore-keys: ${{ runner.os }}-sonar
27+
- name: Cache Gradle packages
28+
uses: actions/cache@v1
29+
with:
30+
path: |
31+
~/.gradle/caches
32+
~/.gradle/wrapper
33+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle', '**/gradle-wrapper.properties') }}
34+
restore-keys: ${{ runner.os }}-gradle
35+
- name: Build and analyze
36+
# env:
37+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
39+
run: ./gradlew build --info
40+

java/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM openjdk:8-jdk-alpine
2+
3+
RUN mkdir -p /opt/build
4+
ADD ./ /opt/build
5+
WORKDIR /opt/build
6+
7+
RUN ./gradlew build --no-daemon \
8+
&& cp ./build/libs/app.jar app.jar
9+
10+
VOLUME /tmp
11+
EXPOSE 8080
12+
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","./app.jar"]

java/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# SpringBoot sample docker image
2+
3+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=DevSecOpsSamples_java-gradle&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=DevSecOpsSamples_java-gradle) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=DevSecOpsSamples_java-gradle&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=DevSecOpsSamples_java-gradle)
4+
5+
@RequestMapping(value="/", method=RequestMethod.GET)
6+
@RequestMapping(value="/ping", method=RequestMethod.GET)
7+
8+
## AWS
9+
10+
```bash
11+
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
12+
REGION=$(aws configure get default.region)
13+
14+
echo "ACCOUNT_ID: $ACCOUNT_ID"
15+
echo "REGION: $REGION"
16+
sleep 1
17+
18+
docker build -t java-gradle . --platform linux/amd64
19+
20+
aws ecr create-repository --repository-name java-gradle --image-scanning-configuration scanOnPush=true --region $REGION
21+
22+
docker tag java-gradle:latest ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/java-gradle:latest
23+
24+
aws ecr get-login-password --region ${REGION} | docker login --username AWS --password-stdin ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com
25+
26+
docker push ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/java-gradle:latest
27+
```
28+
29+
## GCP
30+
31+
```bash
32+
COMPUTE_ZONE="us-central1"
33+
PROJECT_ID="sample-project" # replace with your project
34+
```
35+
36+
```bash
37+
echo "PROJECT_ID: ${PROJECT_ID}"
38+
39+
docker build -t java-gradle . --platform linux/amd64
40+
docker tag java-gradle:latest gcr.io/${PROJECT_ID}/java-gradle:latest
41+
42+
gcloud auth configure-docker
43+
docker push gcr.io/${PROJECT_ID}/java-gradle:latest
44+
```

java/build.gradle

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
plugins {
2+
id 'org.springframework.boot' version '2.2.1.RELEASE'
3+
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
4+
id 'java'
5+
id 'base'
6+
id "org.sonarqube" version "3.4.0.2513"
7+
}
8+
sourceCompatibility = '1.8'
9+
archivesBaseName = 'app'
10+
11+
repositories {
12+
mavenCentral()
13+
}
14+
15+
dependencies {
16+
implementation 'org.springframework.boot:spring-boot-starter-web'
17+
testImplementation('org.springframework.boot:spring-boot-starter-test') {
18+
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
19+
}
20+
}
21+
22+
springBoot {
23+
mainClassName = 'com.sample.SampleApplication.java'
24+
}
25+
test {
26+
useJUnitPlatform()
27+
}
28+
29+
sonarqube {
30+
properties {
31+
property "sonar.projectName", "java-gradle"
32+
property "sonar.projectKey", "DevSecOpsSamples_java-gradle"
33+
property "sonar.organization", "devsecopssamples"
34+
// property "sonar.host.url", "http://127.0.0.1:9000"
35+
property "sonar.host.url", "https://sonarcloud.io"
36+
property "sonar.sourceEncoding", "UTF-8"
37+
property "sonar.sources", "."
38+
property "sonar.java.binaries", "build"
39+
property "sonar.exclusions", "**/node_modules/**, **/cdk.out/**"
40+
property "sonar.issue.ignore.multicriteria", "e1"
41+
property "sonar.issue.ignore.multicriteria.e1.ruleKey", "typescript:S1848"
42+
property "sonar.issue.ignore.multicriteria.e1.resourceKey", "**/*.ts"
43+
property "sonar.links.ci", "https://github.com/DevSecOpsSamples/java-gradle"
44+
}
45+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)