Skip to content

Commit e7f20bf

Browse files
committed
fixed hive docker
1 parent 6f69f1b commit e7f20bf

File tree

8 files changed

+50
-45
lines changed

8 files changed

+50
-45
lines changed

packaging/src/docker/Dockerfile

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,17 @@ RUN tar -xzvf /opt/hadoop-$HADOOP_VERSION.tar.gz -C /opt/ && \
5959

6060
FROM eclipse-temurin:21.0.3_9-jre-ubi9-minimal AS run
6161

62+
ARG UID=1000
6263
ARG HADOOP_VERSION
6364
ARG HIVE_VERSION
6465
ARG TEZ_VERSION
65-
COPY --from=env /opt/hadoop-$HADOOP_VERSION /opt/hadoop
66-
COPY --from=env /opt/apache-hive-$HIVE_VERSION-bin /opt/hive
67-
COPY --from=env /opt/apache-tez-$TEZ_VERSION-bin /opt/tez
6866

6967
# Install dependencies
7068
RUN set -ex; \
7169
microdnf update -y; \
7270
microdnf -y install procps; \
73-
rm -rf /var/lib/apt/lists/*
71+
microdnf clean all; \
72+
useradd --no-create-home -s /sbin/nologin -c "" --uid $UID hive
7473

7574
# Set necessary environment variables.
7675
ENV HADOOP_HOME=/opt/hadoop \
@@ -80,23 +79,21 @@ ENV HADOOP_HOME=/opt/hadoop \
8079

8180
ENV PATH=$HIVE_HOME/bin:$HADOOP_HOME/bin:$PATH
8281

83-
COPY entrypoint.sh /
84-
COPY conf $HIVE_HOME/conf
85-
RUN chmod +x /entrypoint.sh
82+
COPY --from=env --chown=hive /opt/hadoop-$HADOOP_VERSION $HADOOP_HOME
83+
COPY --from=env --chown=hive /opt/apache-hive-$HIVE_VERSION-bin $HIVE_HOME
84+
COPY --from=env --chown=hive /opt/apache-tez-$TEZ_VERSION-bin $TEZ_HOME
8685

86+
COPY --chown=hive entrypoint.sh /
87+
COPY --chown=hive conf $HIVE_HOME/conf
8788

88-
ARG UID=1000
89-
RUN useradd --no-create-home -s /sbin/nologin -c "" --uid $UID hive && \
90-
chown hive /opt/tez && \
91-
chown hive /opt/hive && \
92-
chown hive /opt/hadoop && \
93-
chown hive /opt/hive/conf && \
94-
mkdir -p /opt/hive/data/warehouse && \
95-
chown hive /opt/hive/data/warehouse && \
89+
RUN chmod +x /entrypoint.sh && \
90+
mkdir -p $HIVE_HOME/data/warehouse && \
91+
chown hive $HIVE_HOME/data/warehouse && \
9692
mkdir -p /home/hive/.beeline && \
9793
chown hive /home/hive/.beeline
9894

9995
USER hive
10096
WORKDIR /opt/hive
10197
EXPOSE 10000 10002 9083
98+
10299
ENTRYPOINT ["sh", "-c", "/entrypoint.sh"]

packaging/src/docker/conf/hive-site.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@
5656
<name>tez.local.mode</name>
5757
<value>true</value>
5858
</property>
59-
<property>
60-
<name>hive.metastore.warehouse.dir</name>
61-
<value>/opt/hive/data/warehouse</value>
62-
</property>
6359
<property>
6460
<name>hive.metastore.event.db.notification.api.auth</name>
6561
<value>false</value>

packaging/src/docker/docker-compose.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,18 @@ services:
3333
- hive
3434

3535
metastore:
36-
image: apache/hive:${HIVE_VERSION}
36+
image: apache/hive:standalone-metastore-${HIVE_VERSION}
3737
depends_on:
3838
- postgres
3939
restart: unless-stopped
4040
container_name: metastore
4141
hostname: metastore
4242
environment:
43+
HIVE_OPTS: >
44+
-hiveconf fs.s3a.access.key=${AWS_ACCESS_KEY_ID}
45+
-hiveconf fs.s3a.secret.key=${AWS_SECRET_ACCESS_KEY}
46+
-hiveconf fs.s3a.endpoint=${FS_S3A_ENDPOINT}
47+
HADOOP_CLASSPATH: /opt/hadoop/share/hadoop/tools/lib/*
4348
DB_DRIVER: postgres
4449
SERVICE_NAME: 'metastore'
4550
SERVICE_OPTS: '-Xmx1G -Djavax.jdo.option.ConnectionDriverName=org.postgresql.Driver
@@ -53,6 +58,8 @@ services:
5358
- type: bind
5459
source: ${POSTGRES_LOCAL_PATH}
5560
target: /opt/hive/lib/postgres.jar
61+
# Mount local jars to a temporary staging area (Read-Only)
62+
- ./jars:/tmp/ext-jars:ro
5663
networks:
5764
- hive
5865

@@ -63,6 +70,9 @@ services:
6370
restart: unless-stopped
6471
container_name: hiveserver2
6572
environment:
73+
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
74+
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
75+
HADOOP_CLASSPATH: /opt/hadoop/share/hadoop/tools/lib/*
6676
HIVE_SERVER2_THRIFT_PORT: 10000
6777
SERVICE_OPTS: '-Xmx1G -Dhive.metastore.uris=thrift://metastore:9083'
6878
IS_RESUME: 'true'
@@ -72,6 +82,8 @@ services:
7282
- '10002:10002'
7383
volumes:
7484
- warehouse:/opt/hive/data/warehouse
85+
# Mount local jars to a temporary staging area (Read-Only)
86+
- ./jars:/tmp/ext-jars:ro
7587
networks:
7688
- hive
7789

packaging/src/docker/entrypoint.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@
1919

2020
set -x
2121

22+
# =========================================================================
23+
# DYNAMIC JAR LOADER (AWS/S3 Support)
24+
# =========================================================================
25+
STAGING_DIR="/tmp/ext-jars"
26+
27+
# Checks if /tmp/ext-jars is mounted (via Docker volume).
28+
if [ -d "$STAGING_DIR" ]; then
29+
if ls "$STAGING_DIR"/*.jar 1> /dev/null 2>&1; then
30+
echo "--> Copying custom jars from volume to Hive..."
31+
cp -vf "$STAGING_DIR"/*.jar "${HIVE_HOME}/lib/"
32+
else
33+
echo "--> Volume mounted at $STAGING_DIR, but no jars found."
34+
fi
35+
fi
36+
2237
: "${DB_DRIVER:=derby}"
2338

2439
SKIP_SCHEMA_INIT="${IS_RESUME:-false}"

standalone-metastore/packaging/src/docker/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ Note: Hadoop 3.4.1 requires both AWS SDK V1 and V2 for its S3A connector:
139139
wget https://repo1.maven.org/maven2/com/amazonaws/aws-java-sdk-bundle/1.12.770/aws-java-sdk-bundle-1.12.770.jar -P jars/
140140
wget https://repo1.maven.org/maven2/software/amazon/awssdk/bundle/2.26.19/bundle-2.26.19.jar -P jars/
141141

142-
Then add the following configs to the `metastore-site.xml` under the conf directory:
143-
- fs.s3a.endpoint
144-
- fs.s3a.access.key
145-
- fs.s3a.secret.key
142+
Then add the following ENV variables:
143+
- AWS_ACCESS_KEY_ID
144+
- AWS_SECRET_ACCESS_KEY
145+
- FS_S3A_ENDPOINT
146146

147147
Then,
148148
```shell

standalone-metastore/packaging/src/docker/conf/metastore-site.xml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,4 @@
3232
<name>metastore.catalog.servlet.auth</name>
3333
<value>none</value>
3434
</property>
35-
36-
<!--
37-
<property>
38-
<name>fs.s3a.endpoint</name>
39-
<value>s3.us-west-2.amazonaws.com</value>
40-
</property>
41-
<property>
42-
<name>fs.s3a.access.key</name>
43-
<value>YOUR_AWS_ACCESS_KEY</value>
44-
</property>
45-
<property>
46-
<name>fs.s3a.secret.key</name>
47-
<value>YOUR_AWS_SECRET_KEY</value>
48-
</property>
49-
-->
5035
</configuration>

standalone-metastore/packaging/src/docker/docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ services:
4040
container_name: metastore
4141
hostname: metastore
4242
environment:
43+
HIVE_OPTS: >
44+
-hiveconf fs.s3a.access.key=${AWS_ACCESS_KEY_ID}
45+
-hiveconf fs.s3a.secret.key=${AWS_SECRET_ACCESS_KEY}
46+
-hiveconf fs.s3a.endpoint=${FS_S3A_ENDPOINT}
47+
HADOOP_CLASSPATH: /opt/hadoop/share/hadoop/tools/lib/*
4348
DB_DRIVER: postgres
4449
SERVICE_NAME: 'metastore'
4550
SERVICE_OPTS: '-Xmx1G -Djavax.jdo.option.ConnectionDriverName=org.postgresql.Driver

standalone-metastore/packaging/src/docker/entrypoint.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@ set -x
2424
# =========================================================================
2525
STAGING_DIR="/tmp/ext-jars"
2626

27-
TOOLS_LIB="${HADOOP_HOME}/share/hadoop/tools/lib"
28-
HIVE_LIB="${HIVE_HOME}/lib/"
29-
3027
# Checks if /tmp/ext-jars is mounted (via Docker volume).
3128
if [ -d "$STAGING_DIR" ]; then
3229
if ls "$STAGING_DIR"/*.jar 1> /dev/null 2>&1; then
3330
echo "--> Copying custom jars from volume to Hive..."
34-
cp -vf "$STAGING_DIR"/*.jar "$HIVE_LIB/"
31+
cp -vf "$STAGING_DIR"/*.jar "${HIVE_HOME}/lib/"
3532
else
3633
echo "--> Volume mounted at $STAGING_DIR, but no jars found."
3734
fi
@@ -74,6 +71,4 @@ if [[ "${SKIP_SCHEMA_INIT}" == "false" ]]; then
7471
fi
7572

7673
export METASTORE_PORT=${METASTORE_PORT:-9083}
77-
78-
echo "Starting Hive Metastore on port $METASTORE_PORT..."
7974
exec "$HIVE_HOME/bin/start-metastore"

0 commit comments

Comments
 (0)