forked from unitycatalog/unitycatalog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuc-cli.dockerfile
169 lines (131 loc) · 4.87 KB
/
uc-cli.dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
ARG unitycatalog_uid=185
ARG unitycatalog_home="/opt/unitycatalog"
ARG unitycatalog_repo="${unitycatalog_home}/repo"
ARG unitycatalog_jar="examples/cli/target"
ARG unitycatalog_etc="etc"
ARG unitycatalog_bin="bin"
ARG unitycatalog_user_name="unitycatalog"
ARG unitycatalog_user_home="home"
ARG unitycatalog_user_basedir="${unitycatalog_home}/${unitycatalog_user_home}"
# Specify any custom parameters necessary to generate
# the Uber-Jar by SBT.
# Note: The default allocated heap memory size is too small
# and will cause the process to fail when attempting to compile
# and generate the Uber-Jar. Therefore it is important to choose
# a size large enough for the compiler to run.
ARG sbt_args="-J-Xmx5G"
# ###### STAGE 1 ###### #
# Building the Uber-Jar #
#########################
FROM eclipse-temurin:22-jdk-alpine AS build_uc
ARG unitycatalog_repo
ARG sbt_args
# Install any required packages
RUN <<EOF
set -ex;
apk update;
apk upgrade;
apk add bash git;
rm -R /var/cache/apk/*;
EOF
# Create temporary directories for initialization files
RUN mkdir -p "${unitycatalog_repo}";
WORKDIR "${unitycatalog_repo}"
COPY . .
RUN build/sbt ${sbt_args} cli/assembly
# ###### STAGE 2 ###### #
# Running the UC server #
#########################
FROM eclipse-temurin:22-jre-alpine AS run_uc
ARG unitycatalog_uid
ARG unitycatalog_home
ARG unitycatalog_repo
ARG unitycatalog_jar
ARG unitycatalog_etc
ARG unitycatalog_bin
ARG unitycatalog_user_name
ARG unitycatalog_user_home
ARG unitycatalog_user_basedir
ARG sbt_args
EXPOSE 8081
RUN <<EOF
set -ex;
apk update;
apk upgrade;
apk add bash libc6-compat;
rm -R /var/cache/apk/*;
EOF
# Define the shell used within the container
SHELL ["/bin/bash", "-i", "-c", "-o", "pipefail"]
ENV CLI_TARGET_DIR="${unitycatalog_home}/${unitycatalog_jar}"
ENV UC_CLI_BIN="${unitycatalog_home}/${unitycatalog_bin}/start-uc-cli"
# Create the UC directories
RUN <<-EOF
set -ex;
mkdir -p "${unitycatalog_home}";
mkdir -p "${unitycatalog_home}/${unitycatalog_jar}";
mkdir -p "${unitycatalog_home}/${unitycatalog_etc}";
mkdir -p "${unitycatalog_home}/${unitycatalog_bin}";
mkdir -p "${unitycatalog_home}/${unitycatalog_user_home}";
EOF
# Create system group and user for Unity Catalog
# ENsure the user created has their HOME pointing to the volume
# created to persist user data and the sbt cached files that
# are created as a result of compiling the unity catalog.
# This also ensures that the container can run independently from
# the storage, so we can have ephemeral docker instances with --rm
# and still be able to run the unity catalog each time without problems.
RUN <<-EOF
#!/usr/bin/env bash
set -ex;
addgroup --system --gid "${unitycatalog_uid}" "${unitycatalog_user_name}";
adduser --system --uid "${unitycatalog_uid}" \
--ingroup "${unitycatalog_user_name}" \
--home "${unitycatalog_user_basedir}" \
--shell /bin/bash \
"${unitycatalog_user_name}";
EOF
# Define volume to persist Unity Catalog data
# VOLUME "${unitycatalog_home}"
WORKDIR "$unitycatalog_home"
# Copy the Uber-Jar from the previous stage
COPY --from=build_uc "${unitycatalog_repo}/${unitycatalog_jar}/*.jar" "${unitycatalog_home}/${unitycatalog_jar}/"
# Copy the etc folder which contains the config files and the data folder
COPY --from=build_uc "${unitycatalog_repo}/${unitycatalog_etc}" "${unitycatalog_home}/${unitycatalog_etc}/"
# Create the script that executes the server
# The script looks for the JAR automatially and saves its
# path into a variable then runs the server.
COPY <<-"EOF" "${UC_CLI_BIN}"
#!/usr/bin/env bash
set -ex;
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
ROOT_DIR="$(dirname "$SCRIPT_DIR")"
# Find the jar and store its absolute path into a variable
CLI_JAR=$(find "$CLI_TARGET_DIR" -name "unitycatalog-cli-*.jar" | head -n 1)
if [ -z "$CLI_JAR" ]; then
echo "CLI JAR not found starting with 'unitycatalog-cli-*' in the target directory '$CLI_TARGET_DIR'."
exit 1
fi
# Create relative path to jar so that it is able to find the
# configuration files in etc/conf/...
relative_path_to_jar="${CLI_JAR//"$ROOT_DIR/"/}"
# Prepare the command to be executed
SERVER_JAVA_COMMAND="java -jar $relative_path_to_jar $@"
cd $ROOT_DIR
# alias
alias uc-cli="$SERVER_JAVA_COMMAND"
alias >> ~/.bashrc
echo 'echo "Use uc-cli to query the Unity Catalog. ex: uc-cli catalog list"' >> ~/.bashrc
exec /usr/bin/env bash
EOF
# Set ownership of directories and Unity Catalog home directory to a less
# priviledged user
RUN <<-"EOF"
#!/usr/bin/env bash
set -ex;
chown -R "${unitycatalog_user_name}":"${unitycatalog_user_name}" "$unitycatalog_home";
chmod u+x "$UC_CLI_BIN";
EOF
# Set the user for the container process
USER "${unitycatalog_user_name}"
ENTRYPOINT ["/bin/bash", "-ex", "bin/start-uc-cli"]