Skip to content

Commit 8a11450

Browse files
committed
Add basic stack customization support.
Signed-off-by: Edward Mezarina <[email protected]>
1 parent 97c39d1 commit 8a11450

File tree

9 files changed

+315
-22
lines changed

9 files changed

+315
-22
lines changed

build.sh

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
####
2+
# For more documentation, see:
3+
# https://github.com/OpenLiberty/application-stack/wiki/Open-Liberty-Application-Stack-Customization
4+
####
5+
6+
#
7+
# Base image used to build stack image
8+
#
9+
BASE_OS_IMAGE="${BASE_OS_IMAGE:-adoptopenjdk/openjdk11-openj9:ubi}"
10+
11+
#
12+
# Version of Open Liberty runtime to use within both inner and outer loops
13+
#
14+
OL_RUNTIME_VERSION="${OL_RUNTIME_VERSION:-20.0.0.10}"
15+
16+
#
17+
# The Open Liberty base image used in the final stage of the outer loop Dockerfile used to build your application image from
18+
#
19+
OL_UBI_IMAGE="${OL_UBI_IMAGE:-openliberty/open-liberty:20.0.0.10-kernel-java11-openj9-ubi}"
20+
21+
#
22+
# The name and tag of the "stack image you will build. This will used to create your inner loop development containers, and also as the base image for the first stage of your outer loop image build.
23+
#
24+
STACK_IMAGE="${STACK_IMAGE:-openliberty/application-stack:0.3}"
25+
26+
#
27+
# URL at which your outer loop Dockerfile is hosted
28+
#
29+
DEVFILE_DOCKERFILE_LOC="${DEVFILE_DOCKERFILE_LOC:-https://raw.githubusercontent.com/OpenLiberty/application-stack/master/outer-loop/0.3/Dockerfile}"
30+
31+
#
32+
# URL at which your outer loop deploy YAML template is hosted
33+
#
34+
DEVFILE_DEPLOY_YAML_LOC="${DEVFILE_DEPLOY_YAML_LOC:-https://raw.githubusercontent.com/OpenLiberty/application-stack/master/outer-loop/0.3/app-deploy.yaml}"
35+
36+
# Base customization.
37+
sed -e "s!{{.OL_RUNTIME_VERSION}}!$OL_RUNTIME_VERSION!; s!{{.STACK_IMAGE}}!$STACK_IMAGE!; s!{{.DEVFILE_DOCKERFILE_LOC}}!$DEVFILE_DOCKERFILE_LOC!; s!{{.DEVFILE_DEPLOY_YAML_LOC}}!$DEVFILE_DEPLOY_YAML_LOC!" src/devfile.yaml > devfile.yaml
38+
sed -e "s!{{.BASE_OS_IMAGE}}!$BASE_OS_IMAGE!; s!{{.OL_RUNTIME_VERSION}}!$OL_RUNTIME_VERSION!" src/stackimage/Dockerfile > stackimage/Dockerfile
39+
40+
# Outer loop customization of Dockerfile
41+
sed -e "s!{{.STACK_IMAGE}}!$STACK_IMAGE!; s!{{.OL_UBI_IMAGE}}!$OL_UBI_IMAGE!" src/outer-loop/Dockerfile > outer-loop/latest/Dockerfile
42+
43+
# Outer loop copy of app-deploy.yaml (no customization at present)
44+
cp src/outer-loop/app-deploy.yaml outer-loop/latest/app-deploy.yaml

devfile.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ starterProjects:
1313
components:
1414
- name: devruntime
1515
container:
16-
# this custom image source can be found at:
17-
# https://github.com/OpenLiberty/application-stack/tree/master/stackimage
16+
# In the original upstream of this devfile, the image used is openliberty/application-stack:<x.y.z>, which is built from source at:
17+
# https://github.com/OpenLiberty/application-stack/tree/master/stackimage
1818
image: openliberty/application-stack:0.3
1919
memoryLimit: 1512Mi
2020
mountSources: true

ext/devfile-java8.yaml

-18
This file was deleted.

src/devfile.yaml

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
schemaVersion: 2.0.0
2+
metadata:
3+
name: java-openliberty
4+
version: 0.3.0
5+
description: Java application stack using Open Liberty runtime
6+
alpha.build-dockerfile: "{{.DEVFILE_DOCKERFILE_LOC}}"
7+
alpha.deployment-manifest: "{{.DEVFILE_DEPLOY_YAML_LOC}}"
8+
starterProjects:
9+
- name: user-app
10+
git:
11+
remotes:
12+
origin: 'https://github.com/OpenLiberty/application-stack-starters.git'
13+
components:
14+
- name: devruntime
15+
container:
16+
# In the original upstream of this devfile, the image used is openliberty/application-stack:<x.y.z>, which is built from source at:
17+
# https://github.com/OpenLiberty/application-stack/tree/master/stackimage
18+
image: {{.STACK_IMAGE}}
19+
memoryLimit: 1512Mi
20+
mountSources: true
21+
endpoints:
22+
- exposure: public
23+
path: /
24+
name: ep1
25+
targetPort: 9080
26+
protocol: http
27+
commands:
28+
- id: build
29+
exec:
30+
component: devruntime
31+
commandLine: if [ -e /projects/.disable-bld-cmd ];
32+
then
33+
echo "found the disable file" && echo "devBuild command will not run" && exit 0;
34+
else
35+
echo "will run the devBuild command" && mkdir -p /projects/target/liberty
36+
&& if [ ! -d /projects/target/liberty/wlp ];
37+
then echo "...moving liberty"; mv /opt/ol/wlp /projects/target/liberty; touch ./.liberty-mv;
38+
elif [[ -d /projects/target/liberty/wlp && ! -e /projects/.liberty-mv ]];
39+
then echo "STACK WARNING - LIBERTY RUNTIME WAS LOADED FROM HOST";
40+
fi
41+
&& mvn -Dliberty.runtime.version={{.OL_RUNTIME_VERSION}} package
42+
&& touch ./.disable-bld-cmd;
43+
fi
44+
workingDir: /projects
45+
hotReloadCapable: true
46+
group:
47+
kind: build
48+
isDefault: true
49+
- id: run
50+
exec:
51+
component: devruntime
52+
commandLine: mvn -Dliberty.runtime.version={{.OL_RUNTIME_VERSION}} -Ddebug=false -DhotTests=true -DcompileWait=3 liberty:dev
53+
workingDir: /projects
54+
hotReloadCapable: true
55+
group:
56+
kind: run
57+
isDefault: true
58+
- id: run-test-off
59+
exec:
60+
component: devruntime
61+
commandLine: mvn -Dliberty.runtime.version={{.OL_RUNTIME_VERSION}} -Ddebug=false liberty:dev
62+
workingDir: /projects
63+
hotReloadCapable: true
64+
group:
65+
kind: run
66+
isDefault: false
67+
- id: debug
68+
exec:
69+
component: devruntime
70+
commandLine: mvn -Dliberty.runtime.version={{.OL_RUNTIME_VERSION}} -DdebugPort=${DEBUG_PORT} liberty:dev -Dliberty.env.WLP_DEBUG_REMOTE=y
71+
workingDir: /projects
72+
hotReloadCapable: true
73+
group:
74+
kind: debug
75+
isDefault: true
76+
- id: test
77+
# The 'test' command requires an active container, so we don't need to specify the liberty runtime version
78+
exec:
79+
component: devruntime
80+
commandLine: mvn -Dmicroshed_hostname=localhost -Dmicroshed_http_port=9080 -Dmicroshed_manual_env=true -Dmicroshed_app_context_root=/ failsafe:integration-test
81+
workingDir: /projects
82+
hotReloadCapable: true
83+
group:
84+
kind: test
85+
isDefault: true

src/outer-loop/Dockerfile

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Step 1: Build the user's application
2+
FROM {{.STACK_IMAGE}} as compile
3+
4+
# Make a well known place for shared library jars separate from the rest of the <server> contents (to help with caching)
5+
RUN mkdir /work/configlibdir \
6+
&& mkdir /work/config \
7+
&& mkdir /work/shared
8+
9+
# Copy the rest of the application source
10+
COPY --chown=1001:0 ./src /work/outer-loop-app/src
11+
COPY --chown=1001:0 ./pom.xml /work/outer-loop-app/pom.xml
12+
13+
# Build (and run unit tests)
14+
# also liberty:create copies config from src->target
15+
# also remove quick-start-security.xml since it's convenient for local dev mode but should not be in the production image.
16+
RUN cd /work/outer-loop-app && \
17+
echo "QUICK START SECURITY IS NOT SECURE FOR PRODUCTION ENVIRONMENTS. IT IS BEING REMOVED" && \
18+
rm -f src/main/liberty/config/configDropins/defaults/quick-start-security.xml && \
19+
mvn -e liberty:create package
20+
21+
# process any resources or shared libraries - if they are present in the dependencies block for this project (there may be none potentially)
22+
# test to see if each is present and move to a well known location for later processing in the next stage
23+
#
24+
RUN cd /work/outer-loop-app/target/liberty/wlp/usr/servers && \
25+
if [ -d ./*/lib ]; then mv ./*/lib /work/configlibdir; fi && \
26+
if [ ! -d /work/configlibdir/lib ]; then mkdir /work/configlibdir/lib; fi && \
27+
mv -f */* /work/config/ && \
28+
if [ -d ../shared ]; then mv ../shared/* /work/shared/; fi
29+
30+
# Step 2: Package Open Liberty image
31+
FROM {{.OL_UBI_IMAGE}}
32+
33+
#2a) copy any resources
34+
COPY --from=compile --chown=1001:0 /work/shared /opt/ol/wlp/usr/shared/
35+
36+
# 2b) next copy shared library
37+
# but can't assume config/lib exists - copy from previous stage to a tmp holding place and test
38+
COPY --from=compile --chown=1001:0 /work/configlibdir/ /config
39+
40+
# 2c) Server config, bootstrap.properties, and everything else
41+
COPY --from=compile --chown=1001:0 /work/config/ /config/
42+
43+
# 2d) Changes to the application binary
44+
COPY --from=compile --chown=1001:0 /work/outer-loop-app/target/*.[ew]ar /config/apps
45+
RUN configure.sh && \
46+
chmod 664 /opt/ol/wlp/usr/servers/*/configDropins/defaults/keystore.xml

src/outer-loop/app-deploy.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apiVersion: openliberty.io/v1beta1
2+
kind: OpenLibertyApplication
3+
metadata:
4+
name: {{.COMPONENT_NAME}}
5+
spec:
6+
# Add fields here
7+
version: 1.0.0
8+
applicationImage: {{.CONTAINER_IMAGE}}
9+
service:
10+
type: ClusterIP
11+
port: {{.PORT}}
12+
annotations:
13+
prometheus.io/scrape: 'true'
14+
readinessProbe:
15+
failureThreshold: 12
16+
httpGet:
17+
path: /health/ready
18+
port: {{.PORT}}
19+
initialDelaySeconds: 5
20+
periodSeconds: 2
21+
timeoutSeconds: 1
22+
livenessProbe:
23+
failureThreshold: 12
24+
httpGet:
25+
path: /health/live
26+
port: {{.PORT}}
27+
initialDelaySeconds: 5
28+
periodSeconds: 2
29+
expose: true

src/stackimage/Dockerfile

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
FROM {{.BASE_OS_IMAGE}} AS maven
2+
3+
RUN yum upgrade --disableplugin=subscription-manager -y \
4+
&& yum clean --disableplugin=subscription-manager packages \
5+
&& echo 'Finished installing dependencies'
6+
7+
RUN useradd --uid 1001 --gid 0 --shell /bin/bash --create-home java_user
8+
9+
# Dependency install
10+
RUN yum install --disableplugin=subscription-manager -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
11+
&& yum install --disableplugin=subscription-manager -y unzip curl ca-certificates wget xmlstarlet
12+
13+
# Maven install
14+
ARG MAVEN_VERSION=3.6.3
15+
ARG SHA=c35a1803a6e70a126e80b2b3ae33eed961f83ed74d18fcd16909b2d44d7dada3203f1ffe726c17ef8dcca2dcaa9fca676987befeadc9b9f759967a8cb77181c0
16+
ARG BASE_URL=https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/
17+
18+
RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
19+
&& curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
20+
&& echo "${SHA} /tmp/apache-maven.tar.gz" | sha512sum -c - \
21+
&& tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
22+
&& rm -f /tmp/apache-maven.tar.gz \
23+
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
24+
25+
FROM maven AS builder
26+
27+
ENV OPENJ9_JAVA_OPTIONS="-Xshareclasses:name=liberty,nonfatal,cacheDir=/output/.classCache/"
28+
29+
RUN umask -S u=rwx,g=rwx,o=rx; mkdir -p /mvn/repository \
30+
&& chown -R java_user /mvn \
31+
&& chmod 775 /mvn \
32+
&& mkdir -p /stacks/java-openliberty/priming-app \
33+
&& chown -R java_user /stacks \
34+
&& mkdir -p /output \
35+
&& chown -R java_user /output \
36+
&& chmod 775 /output
37+
38+
COPY ./LICENSE /licenses/
39+
40+
USER java_user
41+
42+
ADD ./priming-app/src /stacks/java-openliberty/priming-app/src
43+
COPY --chown=1001:0 ./priming-app/pom.xml /stacks/java-openliberty/priming-app/
44+
45+
WORKDIR /stacks/java-openliberty/priming-app
46+
47+
ARG LIBERTY_RUNTIME_VERSION={{.OL_RUNTIME_VERSION}}
48+
49+
RUN umask -S u=rwx,g=rwx,o=rx; mvn -B -e -DserverName=tmp -Dmaven.repo.local=/mvn/repository -Dliberty.runtime.version=${LIBERTY_RUNTIME_VERSION} -DskipITs=true install
50+
51+
#
52+
# A hack maybe but there's quite a few dependencies that only are detected when dev mode is executed, due to use of mojo executor, etc.
53+
#
54+
# If you see this then you got enough cached, but if you don't, you need to build with --no-cache next time or you won't even redo this step
55+
#
56+
# [INFO]
57+
# [INFO] -------------------------------------------------------
58+
# [INFO] T E S T S
59+
# [INFO] -------------------------------------------------------
60+
# [INFO] Running dev.odo.starter.it.EndpointIT
61+
# [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.134 s - in dev.odo.starter.it.EndpointIT
62+
# [INFO]
63+
# [INFO] Results:
64+
# [INFO]
65+
# [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
66+
# [INFO]
67+
# [INFO] Failsafe report directory: /stacks/java-openliberty/priming-app/target/test-reports/it
68+
# [INFO] Integration tests finished.
69+
#
70+
# Done sleeping
71+
72+
#
73+
RUN nohup bash -c "umask -S u=rwx,g=rwx,o=rx; mvn -B -e -DserverName=tmp -Dmaven.repo.local=/mvn/repository -Dliberty.runtime.version=${LIBERTY_RUNTIME_VERSION} liberty:dev -DhotTests=true &" \
74+
&& sleep 600 \
75+
&& echo && echo "Done sleeping" && echo
76+
77+
# Grab the runtime artifact as well, it's big and it might be useful
78+
RUN umask -S u=rwx,g=rwx,o=rx; mvn -B -e -Dmaven.repo.local=/mvn/repository -Dartifact=io.openliberty:openliberty-runtime:${LIBERTY_RUNTIME_VERSION}:zip -DrepoUrl=https://repo1.maven.org/maven2/ org.apache.maven.plugins:maven-dependency-plugin:3.1.2:get
79+
80+
# Delete the server, users will create their own server
81+
RUN rm -rf /stacks/java-openliberty/priming-app/target/liberty/wlp/usr/servers/tmp
82+
# Don't let the sample appear in the user repo
83+
RUN rm -rf /mvn/repository/dev/odo/java-openliberty/samples/priming-app
84+
85+
FROM maven
86+
87+
ENV OPENJ9_JAVA_OPTIONS="-Xshareclasses:name=liberty,nonfatal,cacheDir=/output/.classCache/"
88+
89+
RUN mkdir -p /output \
90+
&& chown -R java_user /output \
91+
&& chmod 775 /output \
92+
&& mkdir -p /opt/ol \
93+
&& chown -R java_user /opt/ol \
94+
&& chmod 775 /opt/ol \
95+
&& mkdir -p /work/outer-loop-app \
96+
&& chown -R java_user /work \
97+
&& chmod -R 775 /work
98+
# Point to local /mvn/repository within container
99+
COPY --chown=1001:0 ./mvn-stack-settings.xml /usr/share/maven/conf/settings.xml
100+
COPY --chown=1001:0 --from=builder /mvn /mvn
101+
102+
COPY --chown=1001:0 --from=builder /stacks/java-openliberty/priming-app/target/liberty /opt/ol
103+
COPY --chown=1001:0 ./LICENSE /licenses/
104+
105+
USER java_user
106+
CMD /bin/bash

stackimage/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ WORKDIR /stacks/java-openliberty/priming-app
4747
ARG LIBERTY_RUNTIME_VERSION=20.0.0.10
4848

4949
RUN umask -S u=rwx,g=rwx,o=rx; mvn -B -e -DserverName=tmp -Dmaven.repo.local=/mvn/repository -Dliberty.runtime.version=${LIBERTY_RUNTIME_VERSION} -DskipITs=true install
50+
5051
#
5152
# A hack maybe but there's quite a few dependencies that only are detected when dev mode is executed, due to use of mojo executor, etc.
5253
#

stackimage/priming-app/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
<modelVersion>4.0.0</modelVersion>
2222

2323
<properties>
24-
<maven.compiler.target>11</maven.compiler.target>
25-
<maven.compiler.source>11</maven.compiler.source>
24+
<maven.compiler.target>1.8</maven.compiler.target>
25+
<maven.compiler.source>1.8</maven.compiler.source>
2626
<version.maven-war-plugin>3.3.1</version.maven-war-plugin>
2727
<version.maven-compiler-plugin>3.8.1</version.maven-compiler-plugin>
2828
<version.maven-surefire-plugin>3.0.0-M1</version.maven-surefire-plugin>

0 commit comments

Comments
 (0)