Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added post-install script to install deploy and faas #25

Closed
66 changes: 51 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,17 @@ FROM debian_root AS test_debian_root_wget_from_path

RUN wget https://github.com/metacall/distributable-linux/releases/download/v0.7.0/metacall-tarball-linux-amd64.tar.gz \
&& wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | bash -s -- --from-path /metacall-tarball-linux-amd64.tar.gz \
&& metacall /test/script.js | grep '123456'
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*'

# Test install Debian with root and curl
FROM debian_root AS test_debian_root_curl

RUN curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | bash \
&& metacall /test/script.js | grep '123456'
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*'

# Test certificates in Debian with root (comparing against <!doctype html> in buffer format)
FROM test_debian_root_curl AS test_debian_root_certificates
Expand All @@ -87,13 +91,17 @@ RUN export WEB_RESULT="`printf 'load py /test/script.py\ninspect\ncall fetch_htt
FROM debian_root AS test_debian_root_wget

RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | bash \
&& metacall /test/script.js | grep '123456'
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*'

# Test install Debian without root and curl
FROM debian_user AS test_debian_user_curl

RUN curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | bash \
&& metacall /test/script.js | grep '123456'
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*'

# Test certificates in Debian with user (comparing against <!doctype html> in buffer format)
FROM test_debian_user_curl AS test_debian_user_certificates
Expand All @@ -106,13 +114,17 @@ RUN export WEB_RESULT="`printf 'load py /test/script.py\ninspect\ncall fetch_htt
FROM debian_user AS test_debian_user_wget

RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | bash \
&& metacall /test/script.js | grep '123456'
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*'

# Test reinstall Debian without root and wget
FROM test_debian_user_wget AS test_debian_user_wget_reinstall

RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | bash -s -- --update \
&& metacall /test/script.js | grep '123456'
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*'

# Test pip installation
FROM test_debian_user_wget AS test_debian_user_pip
Expand Down Expand Up @@ -153,25 +165,34 @@ USER user
FROM fedora_root AS test_fedora_root_curl

RUN curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | bash \
&& metacall /test/script.js | grep '123456'
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*'

# Test install Fedora with root and wget
FROM fedora_root AS test_fedora_root_wget

RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | bash \
&& metacall /test/script.js | grep '123456'
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*'

# Test install Fedora without root and curl
FROM fedora_user AS test_fedora_user_curl

RUN curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | bash \
&& metacall /test/script.js | grep '123456'
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*'

# Test install Fedora without root and wget
FROM fedora_user AS test_fedora_user_wget

RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | bash \
&& metacall /test/script.js | grep '123456'
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*'


# Alpine Base (root)
FROM alpine:latest AS alpine_root
Expand Down Expand Up @@ -200,25 +221,37 @@ USER user
FROM alpine_root AS test_alpine_root_curl

RUN curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | sh \
&& metacall /test/script.js | grep '123456'
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -E '^v.*\..*\..*' \
&& metacall faas --version | grep -E '^v.*\..*\..*'


# Test install Alpine with root and wget
FROM alpine_root AS test_alpine_root_wget

RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | sh \
&& metacall /test/script.js | grep '123456'
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -E '^v.*\..*\..*' \
&& metacall faas --version | grep -E '^v.*\..*\..*'


# Test install Alpine without root and curl
FROM alpine_user AS test_alpine_user_curl

RUN curl -sL https://raw.githubusercontent.com/metacall/install/master/install.sh | sh \
&& metacall /test/script.js | grep '123456'
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -E '^v.*\..*\..*' \
&& metacall faas --version | grep -E '^v.*\..*\..*'


# Test install Alpine without root and wget
FROM alpine_user AS test_alpine_user_wget

RUN wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | sh \
&& metacall /test/script.js | grep '123456'
&& metacall /test/script.js | grep '123456' \
&& metacall deploy --version | grep -E '^v.*\..*\..*' \
&& metacall faas --version | grep -E '^v.*\..*\..*'


# Test update Alpine
FROM test_alpine_user_wget AS test_alpine_user_wget_update
Expand Down Expand Up @@ -253,4 +286,7 @@ FROM test_busybox_base AS test_busybox_without_certificates

RUN wget --no-check-certificate -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | sh \
-s -- --no-check-certificate \
&& sh /usr/local/bin/metacall /test/script.js | grep '123456'
&& sh /usr/local/bin/metacall /test/script.js | grep '123456' \
&& sh /usr/local/bin/metacall deploy --version | grep -e '^v.*\..*\..*' \
&& sh /usr/local/bin/metacall faas --version | grep -e '^v.*\..*\..*'

66 changes: 66 additions & 0 deletions install.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,67 @@ uninstall() {
fi
}

install_metacall_additional_packages() {
local component=$1
local install_dir="/gnu/local/${component}"
local bin_file="/gnu/bin/${component}"
local install_success=false

# Locate shebang
find_shebang

title "\n Metacall ${component^} Installation"

# Create the installation directory if it does not exist
mkdir -p ${install_dir}

if [ "$component" == "deploy" ]; then
metacall npm install --global --prefix=${install_dir} @metacall/deploy
echo -e "#!${CMD_SHEBANG}\nmetacall node ${install_dir}/lib/node_modules/@metacall/deploy/dist/index.js \$@" > ${bin_file}
elif [ "$component" == "faas" ]; then
local faas_tarball="/tmp/faas.tar.gz"
local author="metacall"
local repo="faas"

# Fetch tags using curl and grep instead of jq
local tags=$(curl -s "https://api.github.com/repos/$author/$repo/tags" | grep '"name"' | sed -E 's/.*"([^"]+)".*/\1/')
local latest_tag=$(echo "$tags" | head -n 1)
local version_number=${latest_tag#v}
local faas_url="https://github.com/metacall/faas/archive/refs/tags/${latest_tag}.tar.gz"

# Download and extract using tar
if curl -L -o ${faas_tarball} ${faas_url}; then
tar -xzf ${faas_tarball} -C ${install_dir}
cd "${install_dir}/${repo}-${version_number}"
metacall npm install
metacall npm run build

if [ -f "${install_dir}/${repo}-${version_number}/dist/index.js" ]; then
echo -e "#!${CMD_SHEBANG}\nmetacall node ${install_dir}/${repo}-${version_number}/dist/index.js \$@" > ${bin_file}
fi

rm ${faas_tarball}
else
err "Failed to download Metacall FAAS. Check your network connection and try again."
return
fi
else
err "Unknown Package: ${component}"
return
fi

chmod +x ${bin_file}
install_success=$(metacall $component --version | grep -E '^v|^V' > /dev/null && echo true || echo false)

if [ "$install_success" == "true" ]; then
printf "%b\n"
success "metcall ${component} has been installed." \
"Run 'metacall ${component} --help' for more information about Metacall ${component} commands."
else
err "Failed to install Metacall ${component}"
fi
}

main() {
# Check if the tarball is correct
if [ $OPT_FROM_PATH -eq 1 ]; then
Expand Down Expand Up @@ -642,10 +703,15 @@ main() {
" Run 'source /etc/profile' to make 'metacall' command available to your current terminal instance."
fi


# Show information
success "MetaCall has been installed." \
" Run 'metacall' command for start the CLI and type help for more information about CLI commands."
}

# Run main
main

# Installing Additional Packages
install_metacall_additional_packages deploy
install_metacall_additional_packages faas
9 changes: 7 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ docker run --rm \
sh -c "wget -O - https://raw.githubusercontent.com/metacall/install/master/install.sh | sh -s -- --docker-install \
&& mkdir -p ${DOCKER_HOST_PATH} \
&& cd ${DOCKER_HOST_PATH} \
&& metacall script.js | grep '123456'"
&& metacall script.js | grep '123456'" \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*'


result=$?
if [[ $result -ne 0 ]]; then
Expand All @@ -106,7 +109,9 @@ docker run --rm \
&& sh ./install.sh \
&& mkdir -p ${DOCKER_HOST_PATH} \
&& cd ${DOCKER_HOST_PATH} \
&& metacall script.js | grep '123456'"
&& metacall script.js | grep '123456'" \
&& metacall deploy --version | grep -e '^v.*\..*\..*' \
&& metacall faas --version | grep -e '^v.*\..*\..*'

result=$?
if [[ $result -ne 0 ]]; then
Expand Down
Loading