Skip to content

Commit

Permalink
Add test case improve install.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Oct 14, 2024
1 parent 6e26c5d commit 02eca6e
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 37 deletions.
14 changes: 11 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ RUN apt-get update \
&& usermod -aG sudo user \
&& echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
&& chown -R user /test \
&& chmod -R 500 /test/*
&& chmod -R 700 /test

# Debian Base (user)
FROM debian_root AS debian_user
Expand Down Expand Up @@ -151,6 +151,14 @@ FROM test_debian_user_wget AS test_debian_user_pip
RUN metacall pip3 install -r /test/requirements.txt \
&& metacall /test/requirements.py | grep '123456'

# Test npm installation
FROM test_debian_user_wget AS test_debian_user_npm

WORKDIR /test

RUN metacall npm install \
&& metacall /test/package.js | grep 'eyJhbGciOiJIUzI1NiJ9.eWVldA.bS3dTiCfusUIIqeH3484ByiBZC_cH0y8G5vonpPdqXA'

# Test PYTHONPATH
FROM test_debian_user_wget AS test_debian_user_pythonpath

Expand All @@ -175,7 +183,7 @@ RUN dnf update -y \
&& usermod -aG wheel user \
&& echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
&& chown -R user /test \
&& chmod -R 500 /test/*
&& chmod -R 700 /test

# Fedora Base (user)
FROM fedora_root AS fedora_user
Expand Down Expand Up @@ -230,7 +238,7 @@ RUN apk update \
&& adduser --disabled-password --gecos "" user \
&& echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
&& chown -R user /test \
&& chmod -R 500 /test/*
&& chmod -R 700 /test

# Alpine Base (user)
FROM alpine_root AS alpine_user
Expand Down
48 changes: 16 additions & 32 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ dependencies() {
print "Checking system dependencies."

# Check if required programs are installed
programs_required uname tar grep echo printf rm id head chmod chown ln tee touch read cat
programs_required uname tar grep echo printf rm id head chmod chown ln tee touch read

# Check if download programs are installed
if [ $OPT_FROM_PATH -eq 0 ]; then
Expand Down Expand Up @@ -372,7 +372,7 @@ uncompress() {
# the dot . so they are written as ./ for uncompressing them
${CMD_SUDO} tar -tf "${tmp}" | sed 's/^\.//' | while IFS= read -r file; do
if [ ! -e "${file}" ]; then
echo ".${file}" >> ${install_tmp_list}
echo "${file}" >> ${install_tmp_list}
fi
done

Expand All @@ -390,19 +390,26 @@ uncompress() {
# Give read write permissions for all
${CMD_SUDO} chmod 666 ${install_tmp_list}

# Uncompress the tarball. Use the install list to uncompress only the files
# that are new in the filesystem, don't restore mtime (-m) and don't restore user:group (-o).
# Ignore stderr and return error, the linux tarball is broken and gives errors
${CMD_SUDO} tar xzf "${tmp}" -T ${install_tmp_list} -m -o -C / 2>/dev/null || true
# Uncompress the tarball. Use the install list to uncompress only the files that are new in the filesystem,
# don't restore mtime (-m), don't restore user:group (-o) and avoid overwriting existing files (-k).
local user="$(id -u)"
local group="$(id -g)"
${CMD_SUDO} tar xzf "${tmp}" -m -o -k -C /

# Check for valid uncompression
if [ ! -e "${PLATFORM_PREFIX}" ]; then
err "The tarball could not be uncompressed properly. Aborting installation."
${CMD_SUDO} rm -rf "/tmp/metacall-tarball.tar.gz"
exit 1
fi

# Create shared directory
if [ ! -d "${share_dir}" ]; then
${CMD_SUDO} mkdir -p ${share_dir}
fi

# Remove first char of each path in the list and move the install list to the share directory
${CMD_SUDO} cut -c2- "${install_tmp_list}" | ${CMD_SUDO} tee -a ${install_list} > /dev/null
${CMD_SUDO} rm "${install_tmp_list}"
# Move the install list to the share directory
${CMD_SUDO} mv "${install_tmp_list}" "${install_list}"

# Create additional dependencies folder and add it to the install list
${CMD_SUDO} mkdir -p ${deps_dir}
Expand All @@ -411,29 +418,6 @@ uncompress() {
# Store the install list itself
printf "${install_list}" | ${CMD_SUDO} tee -a ${install_list} > /dev/null

# TODO: Remove this
cat "${install_list}"

# Disable debug info
if [ -n "${INSTALL_DEBUG:-}" ]; then
set +x
fi

# Give execution permissions and ownership
local user="$(id -u)"
local group="$(id -g)"

${CMD_SUDO} cat ${install_list} | sed 's/^\.//' | while IFS= read -r file; do
if [ -e "${file}" ]; then
${CMD_SUDO} chmod 775 "${file}"
${CMD_SUDO} chown ${user}:${group} "${file}"
fi
done

if [ -n "${INSTALL_DEBUG:-}" ]; then
set -x
fi

# TODO: Tag with a timestamp the files in order to uninstall them later on
# only if they have not been modified since the install time

Expand Down
10 changes: 8 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,32 @@ for test in ${TEST_LIST}; do
--network host \
${METACALL_INSTALL_DNS} \
-t metacall/install:${test} .

result=$?
if [[ $result -ne 0 ]]; then
echo "Test ${test} failed. Abort."
exit 1
fi

# Clean test on each iteration in order to not clog the disk
docker system prune -f --all
if [[ "${CI:-}" == "true" ]]; then
docker system prune -f --all
fi
done

# Clear the proxy
docker stop metacall_install_nginx

# Clean
docker system prune -f --all

# Test Docker Install
DOCKER_HOST_PATH="${SCRIPT_DIR}/test"

if [ "${METACALL_INSTALL_CERTS}" = "certificates_local" ]; then
DOCKER_ADDITIONAL_VOLUME="-v ${SCRIPT_DIR}/install.sh:/bin/install.sh"
DOCKER_INSTALL_CMD="sh /bin/install.sh"
DOCKER_FALLBACK_CMD="echo"
DOCKER_FALLBACK_CMD="true"
else
DOCKER_ADDITIONAL_VOLUME=""
DOCKER_INSTALL_CMD="wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | sh -s --"
Expand Down
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__pycache__
node_modules
138 changes: 138 additions & 0 deletions test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const jwt = require('jsonwebtoken');

console.log(jwt.sign('yeet', '123'))
8 changes: 8 additions & 0 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "test",
"version": "1.0.0",
"main": "package.js",
"dependencies": {
"jsonwebtoken": "^9.0.2"
}
}

0 comments on commit 02eca6e

Please sign in to comment.