Skip to content

Commit 02f4d29

Browse files
agolPLagolPL
agolPL
authored and
agolPL
committed
quarkus simple application
1 parent 67224c1 commit 02f4d29

14 files changed

+1010
-18
lines changed

.dockerignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*
2+
!target/*-runner
3+
!target/*-runner.jar
4+
!target/lib/*

.gitignore

+30-18
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
1-
# Compiled class file
2-
*.class
1+
# Eclipse
2+
.project
3+
.classpath
4+
.settings/
5+
bin/
36

4-
# Log file
5-
*.log
7+
# IntelliJ
8+
.idea
9+
*.ipr
10+
*.iml
11+
*.iws
612

7-
# BlueJ files
8-
*.ctxt
13+
# NetBeans
14+
nb-configuration.xml
915

10-
# Mobile Tools for Java (J2ME)
11-
.mtj.tmp/
16+
# Visual Studio Code
17+
.vscode
1218

13-
# Package Files #
14-
*.jar
15-
*.war
16-
*.nar
17-
*.ear
18-
*.zip
19-
*.tar.gz
20-
*.rar
19+
# OSX
20+
.DS_Store
2121

22-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23-
hs_err_pid*
22+
# Vim
23+
*.swp
24+
*.swo
25+
26+
# patch
27+
*.orig
28+
*.rej
29+
30+
# Maven
31+
target/
32+
pom.xml.tag
33+
pom.xml.releaseBackup
34+
pom.xml.versionsBackup
35+
release.properties
+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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+
* http://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+
17+
import java.io.File;
18+
import java.io.FileInputStream;
19+
import java.io.FileOutputStream;
20+
import java.io.IOException;
21+
import java.net.Authenticator;
22+
import java.net.PasswordAuthentication;
23+
import java.net.URL;
24+
import java.nio.channels.Channels;
25+
import java.nio.channels.ReadableByteChannel;
26+
import java.util.Properties;
27+
28+
public class MavenWrapperDownloader {
29+
30+
private static final String WRAPPER_VERSION = "0.5.5";
31+
/**
32+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
33+
*/
34+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
35+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
36+
37+
/**
38+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
39+
* use instead of the default one.
40+
*/
41+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
42+
".mvn/wrapper/maven-wrapper.properties";
43+
44+
/**
45+
* Path where the maven-wrapper.jar will be saved to.
46+
*/
47+
private static final String MAVEN_WRAPPER_JAR_PATH =
48+
".mvn/wrapper/maven-wrapper.jar";
49+
50+
/**
51+
* Name of the property which should be used to override the default download url for the wrapper.
52+
*/
53+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
54+
55+
public static void main(String args[]) {
56+
System.out.println("- Downloader started");
57+
File baseDirectory = new File(args[0]);
58+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
59+
60+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
61+
// wrapperUrl parameter.
62+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
63+
String url = DEFAULT_DOWNLOAD_URL;
64+
if(mavenWrapperPropertyFile.exists()) {
65+
FileInputStream mavenWrapperPropertyFileInputStream = null;
66+
try {
67+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
68+
Properties mavenWrapperProperties = new Properties();
69+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
70+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
71+
} catch (IOException e) {
72+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
73+
} finally {
74+
try {
75+
if(mavenWrapperPropertyFileInputStream != null) {
76+
mavenWrapperPropertyFileInputStream.close();
77+
}
78+
} catch (IOException e) {
79+
// Ignore ...
80+
}
81+
}
82+
}
83+
System.out.println("- Downloading from: " + url);
84+
85+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
86+
if(!outputFile.getParentFile().exists()) {
87+
if(!outputFile.getParentFile().mkdirs()) {
88+
System.out.println(
89+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
90+
}
91+
}
92+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
93+
try {
94+
downloadFileFromURL(url, outputFile);
95+
System.out.println("Done");
96+
System.exit(0);
97+
} catch (Throwable e) {
98+
System.out.println("- Error downloading");
99+
e.printStackTrace();
100+
System.exit(1);
101+
}
102+
}
103+
104+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
105+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
106+
String username = System.getenv("MVNW_USERNAME");
107+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
108+
Authenticator.setDefault(new Authenticator() {
109+
@Override
110+
protected PasswordAuthentication getPasswordAuthentication() {
111+
return new PasswordAuthentication(username, password);
112+
}
113+
});
114+
}
115+
URL website = new URL(urlString);
116+
ReadableByteChannel rbc;
117+
rbc = Channels.newChannel(website.openStream());
118+
FileOutputStream fos = new FileOutputStream(destination);
119+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
120+
fos.close();
121+
rbc.close();
122+
}
123+
124+
}

.mvn/wrapper/maven-wrapper.jar

49.5 KB
Binary file not shown.

.mvn/wrapper/maven-wrapper.properties

+2
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.6.1/apache-maven-3.6.1-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar

Dockerfile

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
####
2+
# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode
3+
#
4+
# Before building the docker image run:
5+
#
6+
# mvn package
7+
#
8+
# Then, build the image with:
9+
#
10+
# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/hello-quarkus-jvm .
11+
#
12+
# Then run the container using:
13+
#
14+
# docker run -i --rm -p 8080:8080 quarkus/hello-quarkus-jvm
15+
#
16+
###
17+
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.1
18+
19+
ARG JAVA_PACKAGE=java-1.8.0-openjdk-headless
20+
ARG RUN_JAVA_VERSION=1.3.5
21+
22+
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'
23+
24+
# Install java and the run-java script
25+
# Also set up permissions for user `1001`
26+
RUN microdnf install openssl curl ca-certificates ${JAVA_PACKAGE} \
27+
&& microdnf update \
28+
&& microdnf clean all \
29+
&& mkdir /deployments \
30+
&& chown 1001 /deployments \
31+
&& chmod "g+rwX" /deployments \
32+
&& chown 1001:root /deployments \
33+
&& curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \
34+
&& chown 1001 /deployments/run-java.sh \
35+
&& chmod 540 /deployments/run-java.sh \
36+
&& echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security
37+
38+
# Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size.
39+
ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
40+
41+
COPY target/lib/* /deployments/lib/
42+
COPY target/*-runner.jar /deployments/app.jar
43+
44+
EXPOSE 8080
45+
USER 1001
46+
47+
ENTRYPOINT [ "/deployments/run-java.sh" ]

0 commit comments

Comments
 (0)