Java env builder with Maven (#783)
Java environment builder with support for Maven builds. Default build comman runs `mvn clean package` and picks up target/*with-dependencies.jar for function.
This commit is contained in:
@@ -94,9 +94,12 @@ func buildPackage(fissionClient *crd.FissionClient, envBuilderNamespace string,
|
|||||||
|
|
||||||
log.Printf("Build succeed, source package: %v, deployment package: %v", srcPkgFilename, buildResp.ArtifactFilename)
|
log.Printf("Build succeed, source package: %v, deployment package: %v", srcPkgFilename, buildResp.ArtifactFilename)
|
||||||
|
|
||||||
|
archivePackage := !env.Spec.KeepArchive
|
||||||
|
|
||||||
uploadReq := &fetcher.UploadRequest{
|
uploadReq := &fetcher.UploadRequest{
|
||||||
Filename: buildResp.ArtifactFilename,
|
Filename: buildResp.ArtifactFilename,
|
||||||
StorageSvcUrl: storageSvcUrl,
|
StorageSvcUrl: storageSvcUrl,
|
||||||
|
ArchivePackage: archivePackage,
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Start uploading deployment package: %v", buildResp.ArtifactFilename)
|
log.Printf("Start uploading deployment package: %v", buildResp.ArtifactFilename)
|
||||||
|
|||||||
@@ -42,8 +42,9 @@ type (
|
|||||||
// UploadRequest send from builder manager describes which
|
// UploadRequest send from builder manager describes which
|
||||||
// deployment package should be upload to storage service.
|
// deployment package should be upload to storage service.
|
||||||
UploadRequest struct {
|
UploadRequest struct {
|
||||||
Filename string `json:"filename"`
|
Filename string `json:"filename"`
|
||||||
StorageSvcUrl string `json:"storagesvcurl"`
|
StorageSvcUrl string `json:"storagesvcurl"`
|
||||||
|
ArchivePackage bool `json:"archivepackage"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UploadResponse defines the download url of an archive and
|
// UploadResponse defines the download url of an archive and
|
||||||
@@ -421,12 +422,22 @@ func (fetcher *Fetcher) UploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
srcFilepath := filepath.Join(fetcher.sharedVolumePath, req.Filename)
|
srcFilepath := filepath.Join(fetcher.sharedVolumePath, req.Filename)
|
||||||
dstFilepath := filepath.Join(fetcher.sharedVolumePath, zipFilename)
|
dstFilepath := filepath.Join(fetcher.sharedVolumePath, zipFilename)
|
||||||
|
|
||||||
err = fetcher.archive(srcFilepath, dstFilepath)
|
if req.ArchivePackage {
|
||||||
if err != nil {
|
err = fetcher.archive(srcFilepath, dstFilepath)
|
||||||
e := fmt.Sprintf("Error archiving zip file: %v", err)
|
if err != nil {
|
||||||
log.Println(e)
|
e := fmt.Sprintf("Error archiving zip file: %v", err)
|
||||||
http.Error(w, e, http.StatusInternalServerError)
|
log.Println(e)
|
||||||
return
|
http.Error(w, e, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = os.Rename(srcFilepath, dstFilepath)
|
||||||
|
if err != nil {
|
||||||
|
e := fmt.Sprintf("Error renaming the archive: %v", err)
|
||||||
|
log.Println(e)
|
||||||
|
http.Error(w, e, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Starting upload...")
|
log.Println("Starting upload...")
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
## Fission builder base image
|
||||||
|
ARG BUILDER_IMAGE=fission/builder:latest
|
||||||
|
FROM ${BUILDER_IMAGE}
|
||||||
|
|
||||||
|
## Section copied from the OpenJDK 8 Dockerfile
|
||||||
|
|
||||||
|
ENV LANG C.UTF-8
|
||||||
|
RUN { \
|
||||||
|
echo '#!/bin/sh'; \
|
||||||
|
echo 'set -e'; \
|
||||||
|
echo; \
|
||||||
|
echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \
|
||||||
|
} > /usr/local/bin/docker-java-home \
|
||||||
|
&& chmod +x /usr/local/bin/docker-java-home
|
||||||
|
ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk
|
||||||
|
ENV PATH $PATH:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin
|
||||||
|
|
||||||
|
ENV JAVA_VERSION 8u171
|
||||||
|
ENV JAVA_ALPINE_VERSION 8.171.11-r0
|
||||||
|
|
||||||
|
RUN set -x \
|
||||||
|
&& apk add --no-cache \
|
||||||
|
openjdk8="$JAVA_ALPINE_VERSION" \
|
||||||
|
&& [ "$JAVA_HOME" = "$(docker-java-home)" ]
|
||||||
|
|
||||||
|
## Section copied from the Maven Dockerfile
|
||||||
|
|
||||||
|
RUN apk add --no-cache curl tar bash procps
|
||||||
|
|
||||||
|
ARG MAVEN_VERSION=3.5.4
|
||||||
|
ARG USER_HOME_DIR="/root"
|
||||||
|
ARG SHA=ce50b1c91364cb77efe3776f756a6d92b76d9038b0a0782f7d53acf1e997a14d
|
||||||
|
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries
|
||||||
|
|
||||||
|
RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
|
||||||
|
&& curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
|
||||||
|
&& echo "${SHA} /tmp/apache-maven.tar.gz" | sha256sum -c - \
|
||||||
|
&& tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
|
||||||
|
&& rm -f /tmp/apache-maven.tar.gz \
|
||||||
|
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
|
||||||
|
|
||||||
|
ENV MAVEN_HOME /usr/share/maven
|
||||||
|
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"
|
||||||
|
|
||||||
|
## Fission builder specific section
|
||||||
|
ADD build.sh /usr/local/bin/build
|
||||||
|
EXPOSE 8001
|
||||||
Executable
+4
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eou pipefail
|
||||||
|
mvn clean package
|
||||||
|
cp ${SRC_PKG}/target/*with-dependencies.jar ${DEPLOY_PKG}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# This script allows you to build the jar without needing Maven & JDK installed locally.
|
# This script allows you to build the jar without needing Maven & JDK installed locally.
|
||||||
# You need docker, as it uses a Docker image to build source code
|
# You need docker, as it uses a Docker image to build source code
|
||||||
|
set -eou pipefail
|
||||||
docker run -it --rm -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3.5-jdk-8 mvn clean package
|
docker run -it --rm -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3.5-jdk-8 mvn clean package
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ build_and_push_env_runtime jvm $REPO/jvm-env:$TAG
|
|||||||
build_and_push_env_runtime go $REPO/go-env:$TAG
|
build_and_push_env_runtime go $REPO/go-env:$TAG
|
||||||
|
|
||||||
build_and_push_env_builder python $REPO/python-env-builder:$TAG $BUILDER_IMAGE:$TAG
|
build_and_push_env_builder python $REPO/python-env-builder:$TAG $BUILDER_IMAGE:$TAG
|
||||||
|
build_and_push_env_builder jvm $REPO/jvm-env-builder:$TAG $BUILDER_IMAGE:$TAG
|
||||||
build_and_push_env_builder go $REPO/go-env-builder:$TAG $BUILDER_IMAGE:$TAG
|
build_and_push_env_builder go $REPO/go-env-builder:$TAG $BUILDER_IMAGE:$TAG
|
||||||
|
|
||||||
build_and_push_fluentd $FLUENTD_IMAGE:$TAG
|
build_and_push_fluentd $FLUENTD_IMAGE:$TAG
|
||||||
|
|||||||
+75
@@ -0,0 +1,75 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
ROOT=$(dirname $0)/../../..
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
fission fn delete --name pbuilderhello
|
||||||
|
fission fn delete --name nbuilderhello
|
||||||
|
fission env delete --name java
|
||||||
|
}
|
||||||
|
|
||||||
|
test_fn() {
|
||||||
|
echo "Checking for valid response"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
response0=$(curl http://$FISSION_ROUTER/$1)
|
||||||
|
echo $response0 | grep -i $2
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
test_pkg() {
|
||||||
|
echo "Checking for valid response"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
response0=$(kubectl get -ndefault package $1 -o=jsonpath='{.status.buildstatus}')
|
||||||
|
echo $response0 | grep -i $2
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
export -f test_fn
|
||||||
|
export -f test_pkg
|
||||||
|
|
||||||
|
cd $ROOT/examples/jvm/java
|
||||||
|
|
||||||
|
log "Creating zip from source code"
|
||||||
|
zip -r java-src-pkg.zip *
|
||||||
|
|
||||||
|
log "Creating Java environment with Java Builder"
|
||||||
|
fission env create --name java --image gcr.io/fission-ci/jvm-env:test --version 2 --keeparchive --builder gcr.io/fission-ci/jvm-env-builder:test
|
||||||
|
|
||||||
|
log "Creating package from the source archive"
|
||||||
|
pkg_name=`fission package create --sourcearchive java-src-pkg.zip --env java|cut -d' ' -f 2|cut -d"'" -f 2`
|
||||||
|
log "Created package $pkg_name"
|
||||||
|
|
||||||
|
log "Checking the status of package"
|
||||||
|
timeout 300 bash -c "test_pkg $pkg_name 'succeeded'"
|
||||||
|
|
||||||
|
log "Creating pool manager & new deployment function for Java"
|
||||||
|
fission fn create --name nbuilderhello --pkg $pkg_name --env java --entrypoint io.fission.HelloWorld --executortype newdeploy --minscale 1 --maxscale 1
|
||||||
|
fission fn create --name pbuilderhello --pkg $pkg_name --env java --entrypoint io.fission.HelloWorld
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
log "Creating route for pool manager function"
|
||||||
|
fission route create --function pbuilderhello --url /pbuilderhello --method GET
|
||||||
|
|
||||||
|
log "Creating route for new deployment function"
|
||||||
|
fission route create --function nbuilderhello --url /nbuilderhello --method GET
|
||||||
|
|
||||||
|
log "Waiting for router & pools to catch up"
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
log "Testing pool manager function"
|
||||||
|
timeout 60 bash -c "test_fn pbuilderhello 'Hello'"
|
||||||
|
|
||||||
|
log "Testing new deployment function"
|
||||||
|
timeout 60 bash -c "test_fn nbuilderhello 'Hello'"
|
||||||
Reference in New Issue
Block a user