diff --git a/Dockerfile b/Dockerfile index 145cf49..4726cd6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/install.sh b/install.sh index cae631d..bd75c1e 100755 --- a/install.sh +++ b/install.sh @@ -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 @@ -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 @@ -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} @@ -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 diff --git a/test.sh b/test.sh index 92c03e2..715abe9 100755 --- a/test.sh +++ b/test.sh @@ -65,6 +65,7 @@ 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." @@ -72,19 +73,24 @@ for test in ${TEST_LIST}; do 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 --" diff --git a/test/.gitignore b/test/.gitignore index bee8a64..6320fb6 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1 +1,2 @@ __pycache__ +node_modules diff --git a/test/package-lock.json b/test/package-lock.json new file mode 100644 index 0000000..b056d3a --- /dev/null +++ b/test/package-lock.json @@ -0,0 +1,138 @@ +{ + "name": "test", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "test", + "version": "1.0.0", + "dependencies": { + "jsonwebtoken": "^9.0.2" + } + }, + "node_modules/buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==" + }, + "node_modules/ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, + "node_modules/jsonwebtoken": { + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz", + "integrity": "sha512-PRp66vJ865SSqOlgqS8hujT5U4AOgMfhrwYIuIhfKaoSCZcirrmASQr8CX7cUg+RMih+hgznrjp99o+W4pJLHQ==", + "dependencies": { + "jws": "^3.2.2", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^7.5.4" + }, + "engines": { + "node": ">=12", + "npm": ">=6" + } + }, + "node_modules/jwa": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz", + "integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==", + "dependencies": { + "buffer-equal-constant-time": "1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/jws": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz", + "integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==", + "dependencies": { + "jwa": "^1.4.1", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==" + }, + "node_modules/lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==" + }, + "node_modules/lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==" + }, + "node_modules/lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==" + }, + "node_modules/lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==" + }, + "node_modules/lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==" + }, + "node_modules/lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==" + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/semver": { + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + } + } +} diff --git a/test/package.js b/test/package.js new file mode 100644 index 0000000..08e2007 --- /dev/null +++ b/test/package.js @@ -0,0 +1,3 @@ +const jwt = require('jsonwebtoken'); + +console.log(jwt.sign('yeet', '123')) diff --git a/test/package.json b/test/package.json new file mode 100644 index 0000000..af86775 --- /dev/null +++ b/test/package.json @@ -0,0 +1,8 @@ +{ + "name": "test", + "version": "1.0.0", + "main": "package.js", + "dependencies": { + "jsonwebtoken": "^9.0.2" + } +}