-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpodman_build.sh
103 lines (95 loc) · 3.19 KB
/
podman_build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/sh
set -e
# Gradle init file for Jib plugin outsite of build.gradle
if [ -f build.gradle ]; then
cat <<'EOF'> init.gradle
initscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2'
}
}
dependencies {
classpath 'gradle.plugin.com.google.cloud.tools:jib-gradle-plugin:3.2.1'
}
}
rootProject {
afterEvaluate {
if (!project.plugins.hasPlugin('com.google.cloud.tools.jib')) {
project.apply plugin: com.google.cloud.tools.jib.gradle.JibPlugin
tasks.jib.dependsOn classes
}
}
}
EOF
fi
# Extra directories to add to the image
# Entrypoint script to allow custom commands
mkdir -p /var/tmp/extraDirectories/app
cat <<'EOF'> /var/tmp/extraDirectories/app/run.sh
#!/bin/sh
set -e
CLASS_PATH="$(cat /app/jib-classpath-file)"
MAIN_CLASS="$(cat /app/jib-main-class-file)"
java -XshowSettings:vm -version
exec java -cp $CLASS_PATH $MAIN_CLASS
EOF
# Build with Podman
if [ -f pom.xml ]; then
podman run --platform=linux/amd64 -it --rm \
-v /var/tmp:/var/tmp \
-v $PWD:/code:ro -w /code \
docker.io/library/openjdk:11-jdk \
sh -c '
set -ex
cp -r /code /home/code
cd /home/code
export JAVA_HOME=/usr/local/openjdk-11
chmod +x mvnw
exec ./mvnw --batch-mode test com.google.cloud.tools:jib-maven-plugin:3.2.1:buildTar \
-Dmaven.repo.local=/var/tmp/build_cache/maven \
-Djib.container.user=999:0 \
-Djib.container.workingDirectory=/app \
-Djib.container.entrypoint=/app/run.sh \
-Djib.container.args= \
-Djib.extraDirectories.paths=/var/tmp/extraDirectories \
-Djib.extraDirectories.permissions=/app/run.sh=755,/app=775 \
-Djib.from.image=docker.io/library/openjdk:11-jre \
-Djib.from.platforms=linux/amd64 \
-Djib.allowInsecureRegistries=true \
-Djib.outputPaths.tar=/var/tmp/build_cache/jib-image.tar
'
fi
if [ -f build.gradle ]; then
podman run --platform=linux/amd64 -it --rm \
-v /var/tmp:/var/tmp \
-v $PWD:/code:ro -w /code \
docker.io/library/openjdk:11-jdk \
sh -c '
set -ex
cp -r /code /home/code
cd /home/code
export JAVA_HOME=/usr/local/openjdk-11
export GRADLE_USER_HOME=/var/tmp/build_cache/gradle
chmod +x gradlew
exec ./gradlew --info --init-script init.gradle jibBuildTar \
-Djib.container.user=999:0 \
-Djib.container.workingDirectory=/app \
-Djib.container.entrypoint=/app/run.sh \
-Djib.container.args= \
-Djib.extraDirectories.paths=/var/tmp/extraDirectories \
-Djib.extraDirectories.permissions=/app/run.sh=755,/app=775 \
-Djib.from.image=docker.io/library/openjdk:11-jre \
-Djib.from.platforms=linux/amd64 \
-Djib.allowInsecureRegistries=true \
-Djib.outputPaths.tar=/var/tmp/build_cache/jib-image.tar
'
fi
# Load the Jib image on Podman
printf '\nLoading Image... /var/tmp/build_cache/jib-image.tar\n'
podman load -i /var/tmp/build_cache/jib-image.tar | \
awk '{print $NF}' | \
xargs -i podman tag {} test
printf '\nLoaded Image...\n'
podman image tree test
printf '\nRun "podman run -it --rm -p 8080:8080 test"\n\n'