Skip to content

Commit 0be7a59

Browse files
committed
Initial commit
0 parents  commit 0be7a59

File tree

15 files changed

+1006
-0
lines changed

15 files changed

+1006
-0
lines changed

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
!.mvn/wrapper/
2+
!**/src/main/**
3+
!**/src/test/**
4+
target/
5+
6+
### STS ###
7+
.apt_generated
8+
.classpath
9+
.factorypath
10+
.project
11+
.settings
12+
.springBeans
13+
.sts4-cache
14+
15+
### IntelliJ IDEA ###
16+
.idea
17+
*.iws
18+
*.iml
19+
*.ipr
20+
21+
### NetBeans ###
22+
/nbproject/private/
23+
/nbbuild/
24+
/dist/
25+
/nbdist/
26+
/.nb-gradle/
27+
build/
28+
29+
### VS Code ###
30+
.vscode/
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+
* 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+
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.5";
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.

.mvn/wrapper/maven-wrapper.properties

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

.travis.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
notifications:
2+
email: false
3+
4+
language: java
5+
rvm: 2.6.4
6+
python: 3
7+
8+
service:
9+
- docker
10+
11+
addons:
12+
apt:
13+
update: true
14+
packages:
15+
- sudo
16+
- lsof
17+
- wget
18+
- bash
19+
- curl
20+
- jq
21+
- python3-dev
22+
- python3-pip
23+
- python3-six
24+
- python3-setuptools
25+
- docker-ce
26+
27+
install: true
28+
before_install:
29+
- export PATH=$HOME/.local/bin:$PATH
30+
- pip3 install --user $(whoami) --upgrade pip >/dev/null # pip3 -> pip
31+
- pip install --user $(whoami) --upgrade docker-compose httpie >/dev/null 2>&1
32+
#- http --version --debug
33+
#- docker-compose -v
34+
- source <(curl -s https://raw.githubusercontent.com/daggerok/bash-functions/master/main.bash)
35+
- stop_any 80 8080 5432
36+
37+
stages:
38+
- test
39+
- deploy
40+
41+
jobs:
42+
include:
43+
44+
- stage: test
45+
jdk: openjdk8
46+
name: tests jdk8
47+
script:
48+
- cd $TRAVIS_BUILD_DIR && ./mvmw
49+
- java -jar webapp/target/*.jar &
50+
- wait_for 8080
51+
- http get :8080
52+
- http post :8080/maksimko
53+
- stop_any 80 8080
54+
55+
- stage: test
56+
jdk: openjdk11
57+
name: tests jdk11
58+
script:
59+
- cd $TRAVIS_BUILD_DIR && ./mvmw
60+
- java -jar webapp/target/*.jar &
61+
- wait_for 8080
62+
- http get :8080
63+
- http post :8080/maksimko
64+
- stop_any 80 8080
65+
66+
- stage: test
67+
jdk: openjdk11
68+
name: tests jdk11
69+
script:
70+
- cd $TRAVIS_BUILD_DIR && ./mvmw
71+
- docker build -t daggerok/webapp -f docker/Dockerfile webapp
72+
- docker run -i --rm --name run-webapp -p 8080:8080 daggerok/webapp &
73+
- docker logs -f -t run-webapp &
74+
- wait_for 8080
75+
- http get :8080
76+
- http post :8080/maksimko
77+
- docker rm -f -v run-webapp
78+
79+
# - stage: deploy
80+
# jdk: openjdk8
81+
# rvm: 2.6.4
82+
# name: Gradle Reckon Tag Github and Jekyll GitHub Pages
83+
# script: ./gradlew --stop
84+
# env:
85+
# - secure: "rMVeoE0TGkC2ld/vt7yMtNmkb5ZuKCq4EWTlFDgKBZqRCaIZVZ+zJv1yHXf2mGEBt7j4tVn+fwlUm+8clA2vXUx4eRL+SBEz+MSS8fZRSgRLoGwvdhsH2Sbgx4logXBGd04rStRQgrh0Px/7SaLmtXGoSlmy8LQObZlfDg0hHKxa9dlPjhcjHYo3D4QmE00w9IAUp1cU2AtlUtxd+CsxBmBYHhRTRfQU1IZTseFGPflNjTRqpM5RM/IWe6ecdwKCdVZpqHH1VOmHtsbxxYBSYxt5QQtP5Pg2brUcJha5TCSs81dZ+SnleoEt1iIvW535UVCdLUKxPw56F2Q2ZEyjYWJcX5JRgfZ0Bxwwsg1Pj746utvzsgMntRNm0taWpQsGOSL7tAGQZgtB8TIP55I1QR/YmR0V7t1aYJ/4ooVgnaB5jyqmLQSCRbdbD9prZ+a4dmjTHyBBg4B7gAB/IP6IOyLFm6MOLmTJnVS7nofDTHTvpQ0+GoZuQqZLGc1AUPwbNTZIOO3PNKSUhoLtD00k9dBytWtTA0nzbbfKTa4auvavDkpQNEcoxZGRxnQsdZN4Rw6j/PAEd4Y67iMq8TPm2MCNXPpcOWNxO2ceh3JYl3tfiXqlIgAt9glLGd54RB60OBQa40Sy9oQFlSQIgLsRUjVI/tY/LUN8wHFgH34BvEM="
86+
# before_deploy:
87+
# - if [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ "$TRAVIS_BRANCH" != "master" ] ; then exit 0 ; fi
88+
# - export GITHUB_AUTH="-Dorg.ajoberstar.grgit.auth.password=${GITHUB_PASSWORD} -Dorg.ajoberstar.grgit.auth.username=daggerok"
89+
# - set -e
90+
# - ./gradlew bundle
91+
# - ./gradlew bundle-exec-just-the-docs-rake-search-init
92+
# - ./gradlew bundle-exec-jekyll-build
93+
# deploy:
94+
# - provider: script
95+
# skip_cleanup: true
96+
# script: bash -c './gradlew ${GITHUB_AUTH} reckonTagPush -Preckon.stage=final'
97+
# on:
98+
# branch: master
99+
# condition: "$TRAVIS_PULL_REQUEST == false"
100+
# - provider: pages
101+
# skip-cleanup: true
102+
# github-token: "$GITHUB_TOKEN"
103+
# keep-history: true
104+
# local-dir: docs/_site
105+
# target_branch: gh-pages
106+
# on:
107+
# branch: master
108+
# condition: "$TRAVIS_PULL_REQUEST == false"
109+
110+
cache:
111+
pip: true
112+
packages: true
113+
directories:
114+
- ~/.m2

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# nginx-reverse-proxy-in-k8s-in-docker
2+
Example of nginx reverse proxy in k8s in Docker for Mac (Windows)
3+
4+
## Table of content
5+
6+
* [local development](#local-development)
7+
** [build locally](#build-locally)
8+
** [run locally](#run-locally)
9+
** [run tests](#run-tests)
10+
* [docker development](#docker-development)
11+
** [build docker image](#build-docker-image)
12+
** [run in docker](#run-in-docker)
13+
* [k8s](#k8s)
14+
15+
## local development
16+
17+
### build locally
18+
19+
```shell script
20+
./mvnw
21+
```
22+
23+
### run locally
24+
25+
```shell script
26+
java -jar webapp/target/*.jar
27+
```
28+
29+
### run tests
30+
31+
```shell script
32+
http get :8080
33+
http post :8080/maksimko
34+
```
35+
36+
## docker development
37+
38+
### build docker image
39+
40+
```shell script
41+
docker build -t daggerok/webapp -f docker/Dockerfile webapp
42+
```
43+
44+
### run in docker
45+
46+
```shell script
47+
docker run -i --rm --name native-app -p 8080:8080 daggerok/webapp
48+
```
49+
50+
### k8s
51+
52+
TODO: implement me please...
53+
54+
## resources
55+
56+
* [YouTube: Transform a Legacy Application with Kubernetes and Istio - David Gageot](https://www.youtube.com/watch?v=6jBetJgluEE&list=UUCBVCTuk6uJrN3iFV_3vurg&index=5)

docker/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM openjdk:14-ea-12-jdk-alpine3.10
2+
LABEL MAINTAINER='Maksim Kostromin https://github.com/daggerok/nginx-reverse-proxy-in-k8s-in-docker'
3+
RUN apk --no-cache --update add busybox-suid curl unzip sudo openssh-client shadow wget \
4+
&& adduser -h /home/app.user -s /bin/bash -D -u 1025 app.user wheel \
5+
&& echo "app.user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers \
6+
&& sed -i "s/.*requiretty$/Defaults !requiretty/" /etc/sudoers \
7+
&& apk del busybox-suid unzip sudo openssh-client shadow wget \
8+
&& rm -rf /var/cache/apk/* /tmp/*
9+
USER app.user
10+
WORKDIR /home/app.user
11+
VOLUME /home/app.user
12+
EXPOSE 8080
13+
ENTRYPOINT java -Djava.net.preferIPv4Stack=true \
14+
-XX:+UnlockExperimentalVMOptions \
15+
-XshowSettings:vm \
16+
-jar ./app.jar
17+
CMD /bin/ash
18+
EXPOSE 8080
19+
HEALTHCHECK --timeout=1s \
20+
--retries=35 \
21+
CMD curl -f http://127.0.0.1:8080/actuator/health || exit 1
22+
COPY --chown=app.user target/*.jar ./app.jar

0 commit comments

Comments
 (0)