diff --git a/src/serverless/devcontainer-feature.json b/src/serverless/devcontainer-feature.json new file mode 100644 index 000000000..da63d8983 --- /dev/null +++ b/src/serverless/devcontainer-feature.json @@ -0,0 +1,20 @@ +{ + "name": "Serverless Framework", + "id": "serverless", + "version": "1.1.5", + "description": "Serverless Framework is a widely used open-source IaC tool that allows you to build, and deploy serverless applications on multiple cloud providers.", + "documentationURL": "http://github.com/devcontainers-contrib/features/tree/main/src/serverless", + "installAfter": [ + "ghcr.io/devcontainers/features/python:latest" + ], + "options": { + "version": { + "type": "boolean", + "proposals": [ + "latest" + ], + "default": "latest", + "description": "Select the version of Serverless Framework to install." + } + } +} \ No newline at end of file diff --git a/src/serverless/install.sh b/src/serverless/install.sh new file mode 100644 index 000000000..bf947c6bc --- /dev/null +++ b/src/serverless/install.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# This code was generated by the DevContainers Feature Cookiecutter +# Docs: https://github.com/devcontainers-contrib/features/tree/main/pkgs/feature-template#readme +#------------------------------------------------------------------------------------------------------------- + +set -e + +# npm version for serverless +SERVERLESS_FRAMEWORK=${VERSION:-"latest"} + +# Clean up +rm -rf /var/lib/apt/lists/* + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +# Checks if packages are installed and installs them if not +check_packages() { + if ! dpkg -s "$@" >/dev/null 2>&1; then + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi + apt-get -y install --no-install-recommends "$@" + fi +} + +# install node+npm if does not exists +if ! type npm >/dev/null 2>&1; then + echo "Installing node and npm..." + check_packages curl + curl -fsSL https://raw.githubusercontent.com/devcontainers/features/main/src/node/install.sh | $SHELL + export NVM_DIR=/usr/local/share/nvm + [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" + [ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" +fi + +if [ "$SERVERLESS_FRAMEWORK" != "none" ]; then + if [ "$SERVERLESS_FRAMEWORK" = "latest" ]; then + util_command="serverless" + else + util_command="serverless@$SERVERLESS_FRAMEWORK" + fi + npm install -g --omit=dev ${util_command} +fi + +# Clean up +rm -rf /var/lib/apt/lists/* + +echo "Done!" diff --git a/test/serverless/test.sh b/test/serverless/test.sh new file mode 100644 index 000000000..a31b50509 --- /dev/null +++ b/test/serverless/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +source dev-container-features-test-lib + +check "serverless --version" serverless --version + +reportResults