ci: various build improvements

This commit is contained in:
Stefan Reimer 2022-02-09 23:24:12 +01:00
parent 1c0a62ab7d
commit a2aa45c804
8 changed files with 19 additions and 18 deletions

View File

@ -11,6 +11,7 @@ RUN apk upgrade -U --available --no-cache && \
apk add --no-cache \
libstdc++
# Stage 2 - build function and dependencies
FROM python-alpine AS build-image
# Install aws-lambda-cpp build dependencies
@ -38,14 +39,12 @@ COPY app/* ${FUNCTION_DIR}
# Install requirements
COPY requirements.txt requirements.txt
RUN python${RUNTIME_VERSION} -m pip install -r requirements.txt --target ${FUNCTION_DIR}
RUN export MAKEFLAGS="-j$(nproc)"; pip install -r requirements.txt --target ${FUNCTION_DIR}
# Install Lambda Runtime Interface Client for Python
RUN python${RUNTIME_VERSION} -m pip install awslambdaric --target ${FUNCTION_DIR}
# Stage 3 - final runtime image
# Grab a fresh copy of the Python image
FROM python-alpine
FROM python-alpine as release
# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Set working directory to function root directory
@ -55,3 +54,11 @@ COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]
CMD [ "app.handler" ]
# Tests
FROM release as test
ARG FUNCTION_DIR
COPY test.py .
RUN ./test.py

View File

@ -17,7 +17,7 @@ endif
all: build
build:
podman build --rm --squash-all -t $(REPOSITORY):$(TAG) -t $(REPOSITORY):latest .
podman build --target release --rm -t $(REPOSITORY):$(TAG) -t $(REPOSITORY):latest .
push:
aws ecr-public get-login-password --region $(REGION) | podman login --username AWS --password-stdin $(REGISTRY)
@ -31,13 +31,9 @@ scan:
trivy $(TRIVY_OPTS) $(REPOSITORY):$(TAG)
test:
@echo "Not implemented (yet)"
podman build --target test --rm -t $(REPOSITORY):$(TAG) -t $(REPOSITORY):latest .
pytest:
flake8 --ignore=E501 app/app.py
./test.py
aws_lambda:
@[ -z $(AWS_LAMBDA) ] && { echo "Missing aws-lambda-rie in PATH"; exit 1;} || true

View File

@ -5,4 +5,4 @@ AWS SNS/Lambda central alert hub taking SNS messages, parsing and formatting the
## Resources
- https://gallery.ecr.aws/zero-downtime/sns-alert-hub
- https://github.com/caronc/apprise
- https://github.com/caronc/apprise

View File

@ -228,4 +228,4 @@ def handler(event, context):
else:
body = sns["Message"]
apobj.notify(body=body, title="Unknow message type", notify_type=apprise.NotifyType.WARNING)
apobj.notify(body=body, title="Unknown message type", notify_type=apprise.NotifyType.WARNING)

2
dev-requirements.txt Normal file
View File

@ -0,0 +1,2 @@
flake8
codespell

View File

@ -1,5 +0,0 @@
boto3
apprise
humanize
awslambdaric
flake8

View File

@ -1,3 +1,4 @@
boto3
apprise
humanize
awslambdaric

View File

@ -9,7 +9,7 @@ def send_event(event):
requests.post('http://localhost:8080/2015-03-31/functions/function/invocations', json=event)
p = subprocess.Popen('cd app && aws-lambda-rie /usr/bin/python -m awslambdaric app.handler', shell=True)
p = subprocess.Popen('aws-lambda-rie /usr/bin/python -m awslambdaric app.handler', shell=True)
time.sleep(3)
# Cloudwatch Alarm