Skip to content

Commit

Permalink
feat(python): allow installing a version from git directly (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfonseca authored Oct 11, 2022
1 parent f9b3290 commit 6175186
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion layer/Python/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ USER root
WORKDIR /tmp

# PACKAGE_SUFFIX = '[all]==2.0.0'
# PACKAGE_SUFFIX = '[all] @ git+https://github.com/awslabs/aws-lambda-powertools-python@v2'
# PACKAGE_SUFFIX = '[all]'
# PACKAGE_SUFFIX = '=='2.0.0'
# PACKAGE_SUFFIX = ' @ git+https://github.com/awslabs/aws-lambda-powertools-python@v2'
# PACKAGE_SUFFIX = ''

RUN yum update -y && yum install -y zip unzip wget tar gzip binutils
Expand All @@ -29,7 +31,7 @@ RUN yum install -y \
# Install cython to generate native code
RUN pip install --upgrade pip wheel && pip install --upgrade cython
# Optimize binary size and strip debugging symbols for optimum size
RUN CFLAGS="-Os -g0 -s" pip install --no-binary pydantic -t /asset/python aws-lambda-powertools$PACKAGE_SUFFIX
RUN CFLAGS="-Os -g0 -s" pip install --no-binary pydantic -t /asset/python "aws-lambda-powertools$PACKAGE_SUFFIX"

# Removing nonessential files
RUN cd /asset && \
Expand Down
6 changes: 5 additions & 1 deletion src/lambda-powertools-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ export class LambdaPowertoolsLayer extends lambda.LayerVersion {
suffix = '[all]';
}
if (version) {
suffix = `${suffix}==${version}`;
if (version.startsWith('git')) {
suffix = `${suffix} @ ${version}`;
} else {
suffix = `${suffix}==${version}`;
}
}
break;
case lambda.RuntimeFamily.NODEJS:
Expand Down
14 changes: 14 additions & 0 deletions test/lambda-powertools-python-layer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ describe('construct build args for Dockerfile', () => {
expect(args).toEqual('[all]');
});

test('returns a git url with extras when a git url is provided', () => {
const version = 'git+https://github.com/awslabs/aws-lambda-powertools-python@v2';
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, true, version);

expect(args).toEqual(`[all] @ ${version}`);
});

test('returns only version when no extras flag provided', () => {
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, undefined, '1.11.0');

Expand All @@ -129,4 +136,11 @@ describe('construct build args for Dockerfile', () => {
expect(args).toEqual('');
});

test('returns a git url when a git url is provided and extras provided', () => {
const version = 'git+https://github.com/awslabs/aws-lambda-powertools-python@v2';
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, false, version);

expect(args).toEqual(` @ ${version}`);
});

});

0 comments on commit 6175186

Please sign in to comment.