Skip to content

Commit

Permalink
Update java guide to work on windows (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicks committed May 13, 2020
1 parent 9a2d703 commit a1ec814
Show file tree
Hide file tree
Showing 19 changed files with 150 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ jobs:
- setup_remote_docker
- checkout
- run: echo "deb http://ftp.us.debian.org/debian sid main" >> /etc/apt/sources.list
- run: apt update && apt install -y openjdk-8-jdk unzip rsync
- run: apt update && apt install -y openjdk-8-jdk unzip rsync python
- run: with-kind-cluster.sh test/test.sh
2 changes: 1 addition & 1 deletion 1-measured/Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# shows you how to set up a custom workflow that measures it.
local_resource(
'deploy',
'./record-start-time.sh',
'python record-start-time.py',
)

docker_build('example-java-image', '.')
Expand Down
20 changes: 20 additions & 0 deletions 1-measured/record-start-time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import re
import time

filename = "src/main/java/dev/tilt/example/IndexController.java"
f = open(filename, "r")
contents = f.read()
f.close()

timestamp_sec = int(time.time())
timestamp_nano = (float(time.time()) - timestamp_sec) * 1000 * 1000 * 1000
contents = re.sub(r'startTimeSecs = .*;',
"startTimeSecs = %d;" % timestamp_sec,
contents)
contents = re.sub(r'startTimeNanos = .*;',
"startTimeNanos = %d;" % timestamp_nano,
contents)

f = open(filename, "w")
f.write(contents)
f.close()
10 changes: 0 additions & 10 deletions 1-measured/record-start-time.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

@Controller
public class IndexController {
private final long startTimeSecs = 1585948785;
private final long startTimeNanos = 738488576;
private final long startTimeSecs = 1589420918;
private final long startTimeNanos = 445805788;
private final String updateDuration;

public IndexController() {
Expand Down
8 changes: 6 additions & 2 deletions 2-optimized/Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
# shows you how to set up a custom workflow that measures it.
local_resource(
'deploy',
'./record-start-time.sh',
'python record-start-time.py',
)

gradlew = "./gradlew"
if os.name == "nt":
gradlew = "gradlew.bat"

local_resource(
'example-java-compile',
'./gradlew bootJar',
gradlew + ' bootJar',
deps=['src', 'build.gradle'],
resource_deps = ['deploy'])

Expand Down
20 changes: 20 additions & 0 deletions 2-optimized/record-start-time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import re
import time

filename = "src/main/java/dev/tilt/example/IndexController.java"
f = open(filename, "r")
contents = f.read()
f.close()

timestamp_sec = int(time.time())
timestamp_nano = (float(time.time()) - timestamp_sec) * 1000 * 1000 * 1000
contents = re.sub(r'startTimeSecs = .*;',
"startTimeSecs = %d;" % timestamp_sec,
contents)
contents = re.sub(r'startTimeNanos = .*;',
"startTimeNanos = %d;" % timestamp_nano,
contents)

f = open(filename, "w")
f.write(contents)
f.close()
10 changes: 0 additions & 10 deletions 2-optimized/record-start-time.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

@Controller
public class IndexController {
private final long startTimeSecs = 1585948852;
private final long startTimeNanos = 998017468;
private final long startTimeSecs = 1589420974;
private final long startTimeNanos = 199830532;
private final String updateDuration;

public IndexController() {
Expand Down
8 changes: 6 additions & 2 deletions 3-unpacked/Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
# shows you how to set up a custom workflow that measures it.
local_resource(
'deploy',
'./record-start-time.sh',
'python record-start-time.py',
)

gradlew = "./gradlew"
if os.name == "nt":
gradlew = "gradlew.bat"

local_resource(
'example-java-compile',
'./gradlew bootJar && ' +
gradlew + ' bootJar && ' +
'unzip -o build/libs/example-0.0.1-SNAPSHOT.jar -d build/jar',
deps=['src', 'build.gradle'],
resource_deps = ['deploy'])
Expand Down
20 changes: 20 additions & 0 deletions 3-unpacked/record-start-time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import re
import time

filename = "src/main/java/dev/tilt/example/IndexController.java"
f = open(filename, "r")
contents = f.read()
f.close()

timestamp_sec = int(time.time())
timestamp_nano = (float(time.time()) - timestamp_sec) * 1000 * 1000 * 1000
contents = re.sub(r'startTimeSecs = .*;',
"startTimeSecs = %d;" % timestamp_sec,
contents)
contents = re.sub(r'startTimeNanos = .*;',
"startTimeNanos = %d;" % timestamp_nano,
contents)

f = open(filename, "w")
f.write(contents)
f.close()
10 changes: 0 additions & 10 deletions 3-unpacked/record-start-time.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

@Controller
public class IndexController {
private final long startTimeSecs = 1585948876;
private final long startTimeNanos = 129265771;
private final long startTimeSecs = 1589420981;
private final long startTimeNanos = 366875886;
private final String updateDuration;

public IndexController() {
Expand Down
8 changes: 6 additions & 2 deletions 4-recommended/Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
# shows you how to set up a custom workflow that measures it.
local_resource(
'deploy',
'./record-start-time.sh',
'python record-start-time.py',
)

gradlew = "./gradlew"
if os.name == "nt":
gradlew = "gradlew.bat"

local_resource(
'example-java-compile',
'./gradlew bootJar && ' +
gradlew + ' bootJar && ' +
'unzip -o build/libs/example-0.0.1-SNAPSHOT.jar -d build/jar-staging && ' +
'rsync --inplace --checksum -r build/jar-staging/ build/jar',
deps=['src', 'build.gradle'],
Expand Down
20 changes: 20 additions & 0 deletions 4-recommended/record-start-time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import re
import time

filename = "src/main/java/dev/tilt/example/IndexController.java"
f = open(filename, "r")
contents = f.read()
f.close()

timestamp_sec = int(time.time())
timestamp_nano = (float(time.time()) - timestamp_sec) * 1000 * 1000 * 1000
contents = re.sub(r'startTimeSecs = .*;',
"startTimeSecs = %d;" % timestamp_sec,
contents)
contents = re.sub(r'startTimeNanos = .*;',
"startTimeNanos = %d;" % timestamp_nano,
contents)

f = open(filename, "w")
f.write(contents)
f.close()
10 changes: 0 additions & 10 deletions 4-recommended/record-start-time.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

@Controller
public class IndexController {
private final long startTimeSecs = 1585948883;
private final long startTimeNanos = 217899651;
private final long startTimeSecs = 1589420989;
private final long startTimeNanos = 594529390;
private final String updateDuration;

public IndexController() {
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ An example project that demonstrates a live-updating Java server in Kubernetes.
We used [Spring Initializr](https://start.spring.io/) to bootstrap the project,
then added Docker & Kubernetes configs for running it in Kubernetes.

To run these examples, you should also have:
- javac (a JDK)
- unzip
- rsync
- python

## Fastest Deployment

This progression of examples shows how to start, and incrementally update
Expand Down
36 changes: 36 additions & 0 deletions test/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

echo "Testing 0-base"
tilt ci --file 0-base/Tiltfile
if (!$?) {
throw "failed"
}
tilt down --file 0-base/Tiltfile

echo "Testing 1-measured"
tilt ci --file 1-measured/Tiltfile
if (!$?) {
throw "failed"
}
tilt down --file 1-measured/Tiltfile

echo "Testing 2-optimized"
tilt ci --file 2-optimized/Tiltfile
if (!$?) {
throw "failed"
}
tilt down --file 2-optimized/Tiltfile

echo "Testing 3-unpacked"
tilt ci --file 3-unpacked/Tiltfile
if (!$?) {
throw "failed"
}
tilt down --file 3-unpacked/Tiltfile

echo "Testing 4-recommended"
tilt ci --file 4-recommended/Tiltfile
if (!$?) {
throw "failed"
}
tilt down --file 4-recommended/Tiltfile

0 comments on commit a1ec814

Please sign in to comment.