Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
[java-spring-boot2]: Fix version update (#37)
Browse files Browse the repository at this point in the history
* ⬆️ 0.3: Fix parent pom version update

pre-create missing local maven repository
Move user code to /project/user-app

* review comments (0.3)
  • Loading branch information
Erin Schnabel authored and neeraj-laad committed Jul 2, 2019
1 parent 78c7ae7 commit ba0b6d1
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 37 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
**/*.log
**/target
**/.settings
**/.project
**/.project
.*.swp
2 changes: 2 additions & 0 deletions incubator/java-spring-boot2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The Spring Boot 2 stack uses a parent Maven project object model (POM) to manage

The [Spring Developer Tools](https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html#using-boot-devtools) module is also included to support automatic restarts and live reloading during development.

**Note:** Maven is provided by the Appsody stack container, allowing you to build, test, and debug your Java application without installing Maven locally. We recommend installing Maven locally for the best IDE experience.

## Templates

Templates are used to create your local project and start your development.
Expand Down
21 changes: 9 additions & 12 deletions incubator/java-spring-boot2/image/Dockerfile-stack
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,27 @@ RUN apt-get -qq update \
COPY ./project /project
COPY ./mvn-stack-settings.xml /usr/share/maven/conf/settings.xml
COPY ./mvn-stack-settings.xml /project/.mvn-stack-settings.xml
COPY ./java-spring-boot2-build.sh /project/java-spring-boot2-build.sh

WORKDIR "/project"

RUN mkdir -p /project/target && chmod 777 /project/target
WORKDIR /project/user-app

ENV APPSODY_USER_RUN_AS_LOCAL=true

ENV APPSODY_MOUNTS="src:/project/src;pom.xml:/project/pom.xml;~/.m2/repository:/mvn/repository"
ENV APPSODY_MOUNTS=".:/project/user-app;~/.m2/repository:/mvn/repository"
ENV APPSODY_DEPS=

ENV APPSODY_WATCH_DIR="/project"
ENV APPSODY_WATCH_IGNORE_DIR="/project/target"
ENV APPSODY_WATCH_DIR="/project/user-app/src"
ENV APPSODY_WATCH_IGNORE_DIR=""
ENV APPSODY_WATCH_REGEX=""

ENV APPSODY_RUN="./java-spring-boot2-build.sh run"
ENV APPSODY_RUN_ON_CHANGE="./java-spring-boot2-build.sh recompile"
ENV APPSODY_RUN="/project/java-spring-boot2-build.sh run"
ENV APPSODY_RUN_ON_CHANGE="/project/java-spring-boot2-build.sh recompile"
ENV APPSODY_RUN_KILL=false

ENV APPSODY_DEBUG="./java-spring-boot2-build.sh debug"
ENV APPSODY_DEBUG="/project/java-spring-boot2-build.sh debug"
ENV APPSODY_DEBUG_ON_CHANGE=""
ENV APPSODY_DEBUG_KILL=false

ENV APPSODY_TEST="./java-spring-boot2-build.sh test"
ENV APPSODY_TEST="/project/java-spring-boot2-build.sh test"
ENV APPSODY_TEST_ON_CHANGE=""
ENV APPSODY_TEST_KILL=true

Expand All @@ -43,4 +40,4 @@ ENV PORT=8080
EXPOSE 8080
EXPOSE 5005
EXPOSE 35729
ENTRYPOINT ["./java-spring-boot2-build.sh", "run"]
ENTRYPOINT ["/project/java-spring-boot2-build.sh", "run"]
3 changes: 3 additions & 0 deletions incubator/java-spring-boot2/image/project/.appsody-init.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if not exist %SystemDrive%%HOMEPATH%\.m2\repository\ (
mkdir %SystemDrive%%HOMEPATH%\.m2\repository
)
19 changes: 19 additions & 0 deletions incubator/java-spring-boot2/image/project/.appsody-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
if [ -n "$TERM" ] && [ "$TERM" != "dumb" ] && [ -x /usr/bin/tput ] && [[ `tput colors` != "0" ]]; then
color_prompt="yes"
else
color_prompt=
fi

if [[ "$color_prompt" == "yes" ]]; then
BLUE="\033[0;34m"
NO_COLOR="\033[0m"
else
BLUE=""
NO_COLOUR=""
fi

if [ ! -d ~/.m2/repository ]; then
echo -e "${BLUE}Creating local maven repository: ~/.m2/repository${NO_COLOR}"
mkdir -p ~/.m2/repository
fi
11 changes: 6 additions & 5 deletions incubator/java-spring-boot2/image/project/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,28 @@ RUN apt-get -qq update \
&& apt-get -qq install -y curl wget xmlstarlet \
&& DEBIAN_FRONTEND=noninteractive apt-get -qq upgrade -y \
&& apt-get -qq clean \
&& rm -rf /tmp/* /var/lib/apt/lists/*
&& rm -rf /tmp/* /var/lib/apt/lists/* \
&& mkdir -p /mvn/repository

#setup project folder for java build step
COPY . /project
COPY ./.mvn-stack-settings.xml /usr/share/maven/conf/settings.xml

WORKDIR /project
WORKDIR /project/user-app

RUN mkdir -p /mvn/repository && ./java-spring-boot2-build.sh package
RUN /project/java-spring-boot2-build.sh package

####
FROM adoptopenjdk:8-jdk-openj9

ARG artifactId=serverless
ARG artifactId=appsody-spring
ARG version=1.0-SNAPSHOT
ENV JVM_ARGS=""

LABEL maintainer="IBM Java Engineering at IBM Cloud"
LABEL org.opencontainers.image.version=${version}
LABEL org.opencontainers.image.title=${artifactId}

COPY --from=compile /project/target/app.jar /app.jar
COPY --from=compile /project/user-app/target/app.jar /app.jar

ENTRYPOINT [ "sh", "-c", "java $JVM_ARGS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>dev.appsody</groupId>
<artifactId>spring-boot2-stack</artifactId>
<version>0.2.1</version>
<version>0.3.0</version>
<packaging>pom</packaging>

<name>Appsody Spring Boot2 stack</name>
Expand Down Expand Up @@ -33,11 +33,12 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.5.RELEASE</version>
<version>2.1.6.RELEASE</version>
</parent>

<properties>
<!-- Required library versions -->
<spring-boot.version>2.1.6.RELEASE</spring-boot.version>
<opentracing-spring-jaeger-web-starter.version>2.0.0</opentracing-spring-jaeger-web-starter.version>

<java.version>1.8</java.version>
Expand Down Expand Up @@ -138,7 +139,7 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-plugin.version}</version>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ run_mvn () {
}

version() {
if [ ! -f $1 ]; then
error "$1 does not exist."
exit 1
fi

# get version from specified POM
xmlstarlet sel -T -N x="http://maven.apache.org/POM/4.0.0" -t \
-o "export GROUP_ID=" -v "/x:project/x:groupId" -n \
Expand All @@ -57,17 +62,21 @@ common() {
fi

# Get parent pom information (appsody-boot2-pom.xml)
eval $(version appsody-boot2-pom.xml)
eval $(version /project/appsody-boot2-pom.xml)

# Install parent pom
note "Installing parent ${GROUP_ID}:${ARTIFACT_ID}:${VERSION}"
run_mvn install -q -f appsody-boot2-pom.xml
if ! $(mvn -N dependency:get -q -o -Dartifact=${GROUP_ID}:${ARTIFACT_ID}:${VERSION} -Dpackaging=pom >/dev/null)
then
# Install parent pom
note "Installing parent ${GROUP_ID}:${ARTIFACT_ID}:${VERSION}"
run_mvn install -q -f /project/appsody-boot2-pom.xml
fi

local groupId=$(xmlstarlet sel -T -N x="http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:parent/x:groupId" pom.xml)
local artifactId=$(xmlstarlet sel -T -N x="http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:parent/x:artifactId" pom.xml)
local p_groupId=$(xmlstarlet sel -T -N x="http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:parent/x:groupId" pom.xml)
local p_artifactId=$(xmlstarlet sel -T -N x="http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:parent/x:artifactId" pom.xml)
local p_version=$(xmlstarlet sel -T -N x="http://maven.apache.org/POM/4.0.0" -t -v "/x:project/x:parent/x:version" pom.xml)

# Require parent in pom.xml
if [ "${groupId}" != "${GROUP_ID}" ] || [ "${artifactId}" != "${ARTIFACT_ID}" ]; then
if [ "${p_groupId}" != "${GROUP_ID}" ] || [ "${p_artifactId}" != "${ARTIFACT_ID}" ]; then
error "Project is missing required parent:
<parent>
Expand All @@ -80,11 +89,14 @@ common() {
exit 1
fi

major=$(echo ${VERSION} | cut -d'.' -f1)
((next=major+1))
if [ "${p_version}" != "${VERSION}" ]; then
major=$(echo ${VERSION} | cut -d'.' -f1)
((next=major+1))

note "Updating parent version"
run_mvn -q versions:update-parent "-DparentVersion=[${major},${next})"
fi

note "Updating parent version"
run_mvn -q versions:update-parent "-DparentVersion=[${major},${next})"
unset GROUP_ID ARTIFACT_ID VERSION
}

Expand Down
2 changes: 1 addition & 1 deletion incubator/java-spring-boot2/stack.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id: java-spring-boot2
name: Java application using Spring Boot 2
version: 0.2.1
version: 0.3.0
description: Spring Boot 2 project with health and metrics actuators enabled. Metrics support is provided by Micrometer, and is configured with Prometheus support.
maintainer: Erin Schnabel <[email protected]>
default-template: default
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
stack: appsody/java-spring-boot2:0.2
stack: appsody/java-spring-boot2:0.3
2 changes: 0 additions & 2 deletions incubator/java-spring-boot2/templates/default/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/target/*
!.keep


### STS ###
.apt_generated
Expand Down
7 changes: 6 additions & 1 deletion incubator/java-spring-boot2/templates/default/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent><!--required parent POM-->
<groupId>dev.appsody</groupId>
<artifactId>spring-boot2-stack</artifactId>
<version>0.2.1</version>
<version>0.3.0</version>
<relativePath/>
</parent>

Expand All @@ -22,6 +22,11 @@
-->

<dependencies>
<!-- From parent:
org.springframework.boot:spring-boot-starter
org.springframework.boot:spring-boot-starter-actuator
org.springframework.boot:spring-boot-starter-test
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down

0 comments on commit ba0b6d1

Please sign in to comment.