|
| 1 | +# syntax=docker/dockerfile:1.16.0@sha256:e2dd261f92e4b763d789984f6eab84be66ab4f5f08052316d8eb8f173593acf7 |
| 2 | +# check=error=true |
| 3 | + |
| 4 | +FROM local-image/hadoop/hadoop AS hadoop-builder |
| 5 | + |
| 6 | +FROM local-image/java-devel |
| 7 | + |
| 8 | +ARG AUTHORIZER_VERSION |
| 9 | +ARG HIVE_VERSION |
| 10 | +ARG HADOOP_HADOOP_VERSION |
| 11 | +# Reassign the arg to `HADOOP_VERSION` for better readability. |
| 12 | +ENV HADOOP_VERSION=${HADOOP_HADOOP_VERSION} |
| 13 | +ARG STACKABLE_USER_UID |
| 14 | +# Setting this to anything other than "true" will keep the cache folders around (e.g. for Maven, NPM etc.) |
| 15 | +# This can be used to speed up builds when disk space is of no concern. |
| 16 | +ARG DELETE_CACHES="true" |
| 17 | + |
| 18 | +USER ${STACKABLE_USER_UID} |
| 19 | +WORKDIR /stackable |
| 20 | + |
| 21 | +COPY --chown=${STACKABLE_USER_UID}:0 hive/hive-metastore-opa-authorizer/stackable/patches/patchable.toml /stackable/src/hive/hive-metastore-opa-authorizer/stackable/patches/patchable.toml |
| 22 | +COPY --chown=${STACKABLE_USER_UID}:0 hive/hive-metastore-opa-authorizer/stackable/patches/${AUTHORIZER_VERSION} /stackable/src/hive/hive-metastore-opa-authorizer/stackable/patches/${AUTHORIZER_VERSION} |
| 23 | + |
| 24 | +COPY --chown=${STACKABLE_USER_UID}:0 --from=hadoop-builder /stackable/patched-libs /stackable/patched-libs |
| 25 | + |
| 26 | +# Use bash for regex machting, otherwise docker lint is complaining: |
| 27 | +# hive/hive-metastore-opa-authorizer/Dockerfile:26 SC3015 warning: In POSIX sh, =~ regex matching is undefined. |
| 28 | +SHELL ["/bin/bash", "-c"] |
| 29 | + |
| 30 | +# Make expensive maven build a separate layer for better caching |
| 31 | +# Cache mounts are owned by root by default |
| 32 | +# We need to explicitly give the uid to use |
| 33 | +RUN --mount=type=cache,id=maven-hive-metastore-opa-authorizer-${AUTHORIZER_VERSION},uid=${STACKABLE_USER_UID},target=/stackable/.m2/repository <<EOF |
| 34 | +# for moving nested artifacts out of target folder |
| 35 | +mkdir -p /stackable/opa-authorizer-bin |
| 36 | +# for moving sources out of target folder |
| 37 | +mkdir -p /stackable/opa-authorizer-src |
| 38 | + |
| 39 | +cd "$(/stackable/patchable --images-repo-root=src checkout hive/hive-metastore-opa-authorizer ${AUTHORIZER_VERSION})" |
| 40 | + |
| 41 | +# Create snapshot of the source code including custom patches |
| 42 | +tar -czf /stackable/opa-authorizer-src/hive-metastore-opa-authorizer-${AUTHORIZER_VERSION}-hive-${HIVE_VERSION}-hadoop-${HADOOP_VERSION}-src.tar.gz . |
| 43 | + |
| 44 | +# Make Maven aware of custom Stackable libraries |
| 45 | +cp -r /stackable/patched-libs/maven/* /stackable/.m2/repository |
| 46 | + |
| 47 | +# Set version in the output jars(s) |
| 48 | +mvn versions:set -DnewVersion=${AUTHORIZER_VERSION} |
| 49 | + |
| 50 | +# The if part can be removed once we do no longer support Hive 3.x.x |
| 51 | +if [[ "${HIVE_VERSION}" =~ ^3 ]]; then |
| 52 | + mvn clean package -DskipTests -Dhive.version=${HIVE_VERSION} -Dhadoop.version=${HADOOP_VERSION} -f hms-v3/pom.xml |
| 53 | + |
| 54 | + mv hms-v3/target/com.bosch.bdps.hms3-${HIVE_VERSION}-${HADOOP_VERSION}-${AUTHORIZER_VERSION}.jar /stackable/opa-authorizer-bin |
| 55 | +else |
| 56 | + mvn clean package -DskipTests -Dhive.version=${HIVE_VERSION} -Dhadoop.version=${HADOOP_VERSION} -f hms-v4/pom.xml |
| 57 | + |
| 58 | + # The hive-metastore-opa-authorizer offers a shaded jar from version 4.x.x. Using the shaded jar leads to problems with schema tool at pod startup. |
| 59 | + # mv hms-v4/target/com.bosch.bdps.hms4-${HIVE_VERSION}-${HADOOP_VERSION}-dev.jar /stackable/opa-authorizer-bin |
| 60 | + mv hms-v4/target/hms4-${AUTHORIZER_VERSION}.jar /stackable/opa-authorizer-bin |
| 61 | +fi |
| 62 | + |
| 63 | +# We're removing these to make the intermediate layer smaller |
| 64 | +# This can be necessary even though it's only a builder image because the GitHub Action Runners only have very limited space available |
| 65 | +# and we are sometimes running into errors because we're out of space. |
| 66 | +# Therefore, we try to clean up all layers as much as possible. |
| 67 | +if [ "${DELETE_CACHES}" = "true" ] ; then |
| 68 | + rm -rf /stackable/.m2/repository/* |
| 69 | + rm -rf /stackable/.npm/* |
| 70 | + rm -rf /stackable/.cache/* |
| 71 | + rm -rf /stackable/src |
| 72 | +fi |
| 73 | + |
| 74 | +# fix permissions |
| 75 | +chmod --recursive g=u /stackable/opa-authorizer-bin |
| 76 | +EOF |
0 commit comments