ci: various build improvements
This commit is contained in:
parent
1c0a62ab7d
commit
a2aa45c804
15
Dockerfile
15
Dockerfile
@ -11,6 +11,7 @@ RUN apk upgrade -U --available --no-cache && \
|
|||||||
apk add --no-cache \
|
apk add --no-cache \
|
||||||
libstdc++
|
libstdc++
|
||||||
|
|
||||||
|
|
||||||
# Stage 2 - build function and dependencies
|
# Stage 2 - build function and dependencies
|
||||||
FROM python-alpine AS build-image
|
FROM python-alpine AS build-image
|
||||||
# Install aws-lambda-cpp build dependencies
|
# Install aws-lambda-cpp build dependencies
|
||||||
@ -38,14 +39,12 @@ COPY app/* ${FUNCTION_DIR}
|
|||||||
|
|
||||||
# Install requirements
|
# Install requirements
|
||||||
COPY requirements.txt requirements.txt
|
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
|
# Stage 3 - final runtime image
|
||||||
# Grab a fresh copy of the Python 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
|
# Include global arg in this stage of the build
|
||||||
ARG FUNCTION_DIR
|
ARG FUNCTION_DIR
|
||||||
# Set working directory to function root directory
|
# 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" ]
|
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]
|
||||||
CMD [ "app.handler" ]
|
CMD [ "app.handler" ]
|
||||||
|
|
||||||
|
|
||||||
|
# Tests
|
||||||
|
FROM release as test
|
||||||
|
ARG FUNCTION_DIR
|
||||||
|
|
||||||
|
COPY test.py .
|
||||||
|
RUN ./test.py
|
||||||
|
8
Makefile
8
Makefile
@ -17,7 +17,7 @@ endif
|
|||||||
all: build
|
all: build
|
||||||
|
|
||||||
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:
|
push:
|
||||||
aws ecr-public get-login-password --region $(REGION) | podman login --username AWS --password-stdin $(REGISTRY)
|
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)
|
trivy $(TRIVY_OPTS) $(REPOSITORY):$(TAG)
|
||||||
|
|
||||||
test:
|
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:
|
aws_lambda:
|
||||||
@[ -z $(AWS_LAMBDA) ] && { echo "Missing aws-lambda-rie in PATH"; exit 1;} || true
|
@[ -z $(AWS_LAMBDA) ] && { echo "Missing aws-lambda-rie in PATH"; exit 1;} || true
|
||||||
|
|
||||||
|
@ -228,4 +228,4 @@ def handler(event, context):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
body = sns["Message"]
|
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
2
dev-requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
flake8
|
||||||
|
codespell
|
@ -1,5 +0,0 @@
|
|||||||
boto3
|
|
||||||
apprise
|
|
||||||
humanize
|
|
||||||
awslambdaric
|
|
||||||
flake8
|
|
@ -1,3 +1,4 @@
|
|||||||
boto3
|
boto3
|
||||||
apprise
|
apprise
|
||||||
humanize
|
humanize
|
||||||
|
awslambdaric
|
||||||
|
2
test.py
2
test.py
@ -9,7 +9,7 @@ def send_event(event):
|
|||||||
requests.post('http://localhost:8080/2015-03-31/functions/function/invocations', json=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)
|
time.sleep(3)
|
||||||
|
|
||||||
# Cloudwatch Alarm
|
# Cloudwatch Alarm
|
||||||
|
Loading…
Reference in New Issue
Block a user