Skip to content
This repository has been archived by the owner on Jan 12, 2025. It is now read-only.

Commit

Permalink
Merge pull request #113 from devcontainers-contrib/releases/automated…
Browse files Browse the repository at this point in the history
…-feature-generation-serverless.yaml-3565365667

Automated feature generation - serverless.yaml
  • Loading branch information
danielbraun89 authored Nov 28, 2022
2 parents 03e6fb4 + 51dc015 commit 0deb15e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/serverless/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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."
}
}
}
53 changes: 53 additions & 0 deletions src/serverless/install.sh
Original file line number Diff line number Diff line change
@@ -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!"
9 changes: 9 additions & 0 deletions test/serverless/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -e

source dev-container-features-test-lib

check "serverless --version" serverless --version

reportResults

0 comments on commit 0deb15e

Please sign in to comment.