Skip to content

Commit a1ec814

Browse files
authored
Update java guide to work on windows (#16)
1 parent 9a2d703 commit a1ec814

File tree

19 files changed

+150
-56
lines changed

19 files changed

+150
-56
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ jobs:
88
- setup_remote_docker
99
- checkout
1010
- run: echo "deb http://ftp.us.debian.org/debian sid main" >> /etc/apt/sources.list
11-
- run: apt update && apt install -y openjdk-8-jdk unzip rsync
11+
- run: apt update && apt install -y openjdk-8-jdk unzip rsync python
1212
- run: with-kind-cluster.sh test/test.sh

1-measured/Tiltfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# shows you how to set up a custom workflow that measures it.
66
local_resource(
77
'deploy',
8-
'./record-start-time.sh',
8+
'python record-start-time.py',
99
)
1010

1111
docker_build('example-java-image', '.')

1-measured/record-start-time.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import re
2+
import time
3+
4+
filename = "src/main/java/dev/tilt/example/IndexController.java"
5+
f = open(filename, "r")
6+
contents = f.read()
7+
f.close()
8+
9+
timestamp_sec = int(time.time())
10+
timestamp_nano = (float(time.time()) - timestamp_sec) * 1000 * 1000 * 1000
11+
contents = re.sub(r'startTimeSecs = .*;',
12+
"startTimeSecs = %d;" % timestamp_sec,
13+
contents)
14+
contents = re.sub(r'startTimeNanos = .*;',
15+
"startTimeNanos = %d;" % timestamp_nano,
16+
contents)
17+
18+
f = open(filename, "w")
19+
f.write(contents)
20+
f.close()

1-measured/record-start-time.sh

-10
This file was deleted.

1-measured/src/main/java/dev/tilt/example/IndexController.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
@Controller
1111
public class IndexController {
12-
private final long startTimeSecs = 1585948785;
13-
private final long startTimeNanos = 738488576;
12+
private final long startTimeSecs = 1589420918;
13+
private final long startTimeNanos = 445805788;
1414
private final String updateDuration;
1515

1616
public IndexController() {

2-optimized/Tiltfile

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
# shows you how to set up a custom workflow that measures it.
66
local_resource(
77
'deploy',
8-
'./record-start-time.sh',
8+
'python record-start-time.py',
99
)
1010

11+
gradlew = "./gradlew"
12+
if os.name == "nt":
13+
gradlew = "gradlew.bat"
14+
1115
local_resource(
1216
'example-java-compile',
13-
'./gradlew bootJar',
17+
gradlew + ' bootJar',
1418
deps=['src', 'build.gradle'],
1519
resource_deps = ['deploy'])
1620

2-optimized/record-start-time.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import re
2+
import time
3+
4+
filename = "src/main/java/dev/tilt/example/IndexController.java"
5+
f = open(filename, "r")
6+
contents = f.read()
7+
f.close()
8+
9+
timestamp_sec = int(time.time())
10+
timestamp_nano = (float(time.time()) - timestamp_sec) * 1000 * 1000 * 1000
11+
contents = re.sub(r'startTimeSecs = .*;',
12+
"startTimeSecs = %d;" % timestamp_sec,
13+
contents)
14+
contents = re.sub(r'startTimeNanos = .*;',
15+
"startTimeNanos = %d;" % timestamp_nano,
16+
contents)
17+
18+
f = open(filename, "w")
19+
f.write(contents)
20+
f.close()

2-optimized/record-start-time.sh

-10
This file was deleted.

2-optimized/src/main/java/dev/tilt/example/IndexController.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
@Controller
1111
public class IndexController {
12-
private final long startTimeSecs = 1585948852;
13-
private final long startTimeNanos = 998017468;
12+
private final long startTimeSecs = 1589420974;
13+
private final long startTimeNanos = 199830532;
1414
private final String updateDuration;
1515

1616
public IndexController() {

3-unpacked/Tiltfile

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
# shows you how to set up a custom workflow that measures it.
66
local_resource(
77
'deploy',
8-
'./record-start-time.sh',
8+
'python record-start-time.py',
99
)
1010

11+
gradlew = "./gradlew"
12+
if os.name == "nt":
13+
gradlew = "gradlew.bat"
14+
1115
local_resource(
1216
'example-java-compile',
13-
'./gradlew bootJar && ' +
17+
gradlew + ' bootJar && ' +
1418
'unzip -o build/libs/example-0.0.1-SNAPSHOT.jar -d build/jar',
1519
deps=['src', 'build.gradle'],
1620
resource_deps = ['deploy'])

3-unpacked/record-start-time.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import re
2+
import time
3+
4+
filename = "src/main/java/dev/tilt/example/IndexController.java"
5+
f = open(filename, "r")
6+
contents = f.read()
7+
f.close()
8+
9+
timestamp_sec = int(time.time())
10+
timestamp_nano = (float(time.time()) - timestamp_sec) * 1000 * 1000 * 1000
11+
contents = re.sub(r'startTimeSecs = .*;',
12+
"startTimeSecs = %d;" % timestamp_sec,
13+
contents)
14+
contents = re.sub(r'startTimeNanos = .*;',
15+
"startTimeNanos = %d;" % timestamp_nano,
16+
contents)
17+
18+
f = open(filename, "w")
19+
f.write(contents)
20+
f.close()

3-unpacked/record-start-time.sh

-10
This file was deleted.

3-unpacked/src/main/java/dev/tilt/example/IndexController.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
@Controller
1111
public class IndexController {
12-
private final long startTimeSecs = 1585948876;
13-
private final long startTimeNanos = 129265771;
12+
private final long startTimeSecs = 1589420981;
13+
private final long startTimeNanos = 366875886;
1414
private final String updateDuration;
1515

1616
public IndexController() {

4-recommended/Tiltfile

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
# shows you how to set up a custom workflow that measures it.
66
local_resource(
77
'deploy',
8-
'./record-start-time.sh',
8+
'python record-start-time.py',
99
)
1010

11+
gradlew = "./gradlew"
12+
if os.name == "nt":
13+
gradlew = "gradlew.bat"
14+
1115
local_resource(
1216
'example-java-compile',
13-
'./gradlew bootJar && ' +
17+
gradlew + ' bootJar && ' +
1418
'unzip -o build/libs/example-0.0.1-SNAPSHOT.jar -d build/jar-staging && ' +
1519
'rsync --inplace --checksum -r build/jar-staging/ build/jar',
1620
deps=['src', 'build.gradle'],

4-recommended/record-start-time.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import re
2+
import time
3+
4+
filename = "src/main/java/dev/tilt/example/IndexController.java"
5+
f = open(filename, "r")
6+
contents = f.read()
7+
f.close()
8+
9+
timestamp_sec = int(time.time())
10+
timestamp_nano = (float(time.time()) - timestamp_sec) * 1000 * 1000 * 1000
11+
contents = re.sub(r'startTimeSecs = .*;',
12+
"startTimeSecs = %d;" % timestamp_sec,
13+
contents)
14+
contents = re.sub(r'startTimeNanos = .*;',
15+
"startTimeNanos = %d;" % timestamp_nano,
16+
contents)
17+
18+
f = open(filename, "w")
19+
f.write(contents)
20+
f.close()

4-recommended/record-start-time.sh

-10
This file was deleted.

4-recommended/src/main/java/dev/tilt/example/IndexController.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
@Controller
1111
public class IndexController {
12-
private final long startTimeSecs = 1585948883;
13-
private final long startTimeNanos = 217899651;
12+
private final long startTimeSecs = 1589420989;
13+
private final long startTimeNanos = 594529390;
1414
private final String updateDuration;
1515

1616
public IndexController() {

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ An example project that demonstrates a live-updating Java server in Kubernetes.
77
We used [Spring Initializr](https://start.spring.io/) to bootstrap the project,
88
then added Docker & Kubernetes configs for running it in Kubernetes.
99

10+
To run these examples, you should also have:
11+
- javac (a JDK)
12+
- unzip
13+
- rsync
14+
- python
15+
1016
## Fastest Deployment
1117

1218
This progression of examples shows how to start, and incrementally update

test/test.ps1

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
echo "Testing 0-base"
3+
tilt ci --file 0-base/Tiltfile
4+
if (!$?) {
5+
throw "failed"
6+
}
7+
tilt down --file 0-base/Tiltfile
8+
9+
echo "Testing 1-measured"
10+
tilt ci --file 1-measured/Tiltfile
11+
if (!$?) {
12+
throw "failed"
13+
}
14+
tilt down --file 1-measured/Tiltfile
15+
16+
echo "Testing 2-optimized"
17+
tilt ci --file 2-optimized/Tiltfile
18+
if (!$?) {
19+
throw "failed"
20+
}
21+
tilt down --file 2-optimized/Tiltfile
22+
23+
echo "Testing 3-unpacked"
24+
tilt ci --file 3-unpacked/Tiltfile
25+
if (!$?) {
26+
throw "failed"
27+
}
28+
tilt down --file 3-unpacked/Tiltfile
29+
30+
echo "Testing 4-recommended"
31+
tilt ci --file 4-recommended/Tiltfile
32+
if (!$?) {
33+
throw "failed"
34+
}
35+
tilt down --file 4-recommended/Tiltfile
36+

0 commit comments

Comments
 (0)