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

feat(runtimes): additional runtime support #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions yolo/build.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import hashlib
import logging
import os
import subprocess
import time

import docker

from yolo import utils
from yolo.exceptions import YoloError

LOG = logging.getLogger(__name__)

Expand All @@ -21,7 +23,39 @@
STATUS_EXITED = 'exited'


def python_build_lambda_function(service_cfg):
def build_lambda_function(service_cfg):
runtime = service_cfg['deploy']['lambda_function_configuration']['Runtime']

BUILD_FUNCTIONS = {
'python2.7': build_python,
'python3.6': build_python,
'go1.x': build_go1x,
'nodejs6.10': not_supported_yet,
'nodejs8.10': not_supported_yet,
'java8': not_supported_yet,
'dotnetcore1.0': not_supported_yet,
'dotnetcore2.0': not_supported_yet
}

BUILD_FUNCTIONS[runtime](service_cfg, runtime)


def not_supported_yet(service_cfg, runtime):
raise YoloError('Runtime "{}" is not supported yet.'.format(runtime))


def build_go1x(service_cfg, runtime):
# get package dependencies
subprocess.call('go get -t ./...', shell=True)
# create clean 'dist' directory
subprocess.call('rm -rf ./dist && mkdir ./dist', shell=True)
# build GO lambda bin
subprocess.call('GOOS=linux GOARCH=amd64 go build -o ./dist/main main.go', shell=True)
# zip the previously built GO package for deployment
subprocess.call('zip ./dist/lambda_function.zip ./dist/main', shell=True)


def build_python(service_cfg, runtime):
build_config = service_cfg['build']
try:
# Allow connecting to older Docker versions (e.g. CircleCI 1.0)
Expand All @@ -36,7 +70,6 @@ def python_build_lambda_function(service_cfg):
dist_dir = os.path.abspath(build_config['dist_dir'])
# List of files/dirs to include from `working_dir`
include = build_config['include']
runtime = service_cfg['deploy']['lambda_function_configuration']['Runtime']
# TODO: check if the file actually exists
dependencies_path = os.path.join(working_dir, build_config['dependencies'])
with open(dependencies_path) as fp:
Expand Down
10 changes: 10 additions & 0 deletions yolo/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,13 @@
# This tells deployed applications where to find config/secrets in SSM.
SSM_CONFIG_VERSION = 'SSM_CONFIG_VERSION'
S3_UPLOAD_EXTRA_ARGS = dict(ACL='private', ServerSideEncryption='AES256')
SUPPORTED_LAMBDA_RUNTIMES = [
'python2.7',
'python3.6',
'go1.x',
'nodejs6.10',
'nodejs8.10',
'java8',
'dotnetcore1.0',
'dotnetcore2.0',
]
2 changes: 1 addition & 1 deletion yolo/services/lambda_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def build(self, service, stage):
)

# Use yolo's built-in Lambda build function.
yolo.build.python_build_lambda_function(service_cfg)
yolo.build.build_lambda_function(service_cfg)

def push(self, service, stage, bucket):
"""Push a local build of a Lambda service up into S3.
Expand Down
7 changes: 2 additions & 5 deletions yolo/yolo_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import yolo.exceptions
from yolo import utils
from yolo import const

PY3 = sys.version_info >= (2, 8)
if PY3:
Expand Down Expand Up @@ -84,10 +85,6 @@ class YoloFile(object):
}],
},
})
SUPPORTED_RUNTIMES = [
'python2.7',
'python3.6',
]
YOKE_LAMBDA_FN_CFG = volup.Schema({
volup.Required('FunctionName'): STRING_SCHEMA,
volup.Required('Role'): STRING_SCHEMA,
Expand All @@ -102,7 +99,7 @@ class YoloFile(object):
volup.Optional('Environment'): {
'Variables': {STRING_SCHEMA: STRING_SCHEMA},
},
volup.Optional('Runtime'): volup.Any(*SUPPORTED_RUNTIMES),
volup.Optional('Runtime'): volup.Any(*const.SUPPORTED_LAMBDA_RUNTIMES),
volup.Optional('TracingConfig'): {
volup.Required('Mode'): volup.Any('Active', 'PassThrough'),
},
Expand Down