Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #14 from mention-me/update-3.9
Browse files Browse the repository at this point in the history
Update to Python 3.9
  • Loading branch information
edhgoose authored Apr 22, 2024
2 parents 54b52f5 + fd4ca87 commit 5a62223
Show file tree
Hide file tree
Showing 27 changed files with 601 additions and 651 deletions.
96 changes: 0 additions & 96 deletions .circleci/config.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ omit =
*/python?.?/*
*/site-packages/nose/*
show_missing = true

[html]
directory = coverage_html_report
1 change: 0 additions & 1 deletion .github/CODEOWNERS

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.12'
- name: Create virtualenv
run: |
python -m venv venv
source venv/bin/activate
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: Run pytest
run: |
pytest -v
- name: Run pre-commit
run: |
pip install pre-commit
pre-commit install-hooks
pre-commit run --all-files
63 changes: 63 additions & 0 deletions .github/workflows/lambda.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Test with LocalStack

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: sudo apt update && sudo apt install -y make wget
- name: build docker image
run: make archive
- name: Start LocalStack
uses: LocalStack/setup-localstack@main
with:
image-tag: 'latest'
install-awslocal: 'true'
- name: Run tests against localstack
run: |
awslocal s3 mb s3://antivirus-definitions
awslocal s3 mb s3://test-bucket
wget https://secure.eicar.org/eicar_com.zip
awslocal s3 cp eicar_com.zip s3://test-bucket/eicar_com.zip
awslocal lambda create-function \
--function-name update-clamav \
--runtime python3.12 \
--handler update.lambda_handler \
--role arn:aws:iam::123456789012:role/lambda-role \
--zip-file fileb://./build/lambda.zip \
--timeout 120 \
--environment "Variables={AV_DEFINITION_S3_BUCKET=antivirus-definitions}"
sleep 30
awslocal lambda invoke \
--function-name update-clamav \
--invocation-type RequestResponse \
--log-type Tail \
--payload '{}' \
response.json \
--query 'LogResult' | tr -d '"' | base64 -d
awslocal lambda create-function \
--function-name scan-clamav \
--runtime python3.12 \
--handler scan.lambda_handler \
--role arn:aws:iam::123456789012:role/lambda-role \
--zip-file fileb://./build/lambda.zip \
--timeout 120 \
--environment "Variables={AV_DEFINITION_S3_BUCKET=antivirus-definitions,AV_DELETE_INFECTED_FILES=True}"
sleep 30
awslocal lambda invoke \
--function-name scan-clamav \
--invocation-type RequestResponse \
--log-type Tail \
--payload '{"Records": [{"s3": {"bucket": {"name": "test-bucket"}, "object": {"key": "eicar_com.zip"}}}]}' \
response.json \
--query 'LogResult' | tr -d '"' | base64 -d
result=$(awslocal s3 ls s3://test-bucket)
if [ -z "$result" ]; then
echo "Bucket is empty"
else
echo "Bucket is not empty"
exit 1
fi
26 changes: 26 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: pre-commit

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.12'
- name: Create virtualenv
run: |
python -m venv venv
source venv/bin/activate
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: Run pre-commit
run: |
pip install pre-commit
pre-commit install-hooks
pre-commit run --all-files
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,9 @@ tmp/

# EICAR Files
*eicar*

# response.json
response.json

# coverage report
coverage_html_report/
25 changes: 18 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
repos:

- repo: https://github.com/ambv/black
rev: stable
rev: 23.12.1
hooks:
- id: black
language_version: python3.7
language_version: python3.12
exclude: >
(?x)^(
scripts/gen-docs-index|
)$
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v2.2.3
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-ast
- id: check-json
- id: check-merge-conflict
- id: check-yaml
exclude: deploy/
- id: debug-statements
- id: detect-private-key
- id: fix-encoding-pragma
- id: flake8
- id: trailing-whitespace

- repo: git://github.com/igorshubovych/markdownlint-cli
rev: v0.17.0
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.38.0
hooks:
- id: markdownlint
entry: markdownlint --ignore .github/*.md

- repo: https://github.com/aws-cloudformation/cfn-python-lint
rev: v0.84.0
hooks:
- id: cfn-python-lint
files: deploy/
68 changes: 57 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM amazonlinux:2
FROM --platform=linux/x86_64 public.ecr.aws/lambda/python:3.9


WORKDIR /opt/app
Expand All @@ -12,30 +12,76 @@ COPY ./*.py /opt/app/
COPY requirements.txt /opt/app/requirements.txt

# Install packages
RUN yum update -y
RUN yum install -y cpio python3-pip yum-utils zip unzip less
RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# update security
RUN : \
&& yum -y update --security \
&& yum clean all \
&& rm -rf /var/cache/yum \
&& :

# This had --no-cache-dir, tracing through multiple tickets led to a problem in wheel
RUN pip3 install -r requirements.txt
RUN rm -rf /root/.cache/pip
# Install required packages
RUN : \
&& yum update -y \
&& yum install -y \
cpio \
python3 \
python3-pip \
yum-utils \
zip \
unzip \
less \
libtool-ltdl \
binutils \
&& yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
&& pip3 install -r /opt/app/requirements.txt \
&& yum clean all \
&& rm -rf /var/cache/yum \
&& :

# Download libraries we need to run in lambda
WORKDIR /tmp
RUN yumdownloader -x \*i686 --archlist=x86_64 clamav clamav-lib clamav-update json-c pcre2 libprelude gnutls libtasn1 lib64nettle nettle
RUN yumdownloader -x \*i686 --archlist=x86_64 \
clamav \
clamav-lib \
clamav-scanner-systemd \
clamav-update \
elfutils-libs \
json-c \
lz4 \
pcre2 \
systemd-libs \
libprelude \
gnutls \
libtasn1 \
lib64nettle \
nettle \
libtool-ltdl \
libxml2 \
xz-libs \
xz-devel

RUN rpm2cpio clamav-0*.rpm | cpio -idmv
RUN rpm2cpio clamav-lib*.rpm | cpio -idmv
RUN rpm2cpio clamav-update*.rpm | cpio -idmv
RUN rpm2cpio clamd-0*.rpm | cpio -idmv
RUN rpm2cpio elfutils-libs*.rpm | cpio -idmv
RUN rpm2cpio json-c*.rpm | cpio -idmv
RUN rpm2cpio lz4*.rpm | cpio -idmv
RUN rpm2cpio pcre*.rpm | cpio -idmv
RUN rpm2cpio systemd-libs*.rpm | cpio -idmv
RUN rpm2cpio gnutls* | cpio -idmv
RUN rpm2cpio nettle* | cpio -idmv
RUN rpm2cpio libtasn1* | cpio -idmv
RUN rpm2cpio libtool-ltdl* | cpio -idmv
RUN rpm2cpio libxml2* | cpio -idmv
RUN rpm2cpio xz-libs* | cpio -idmv
RUN rpm2cpio xz-devel* | cpio -idmv
RUN rpm2cpio lib* | cpio -idmv
RUN rpm2cpio *.rpm | cpio -idmv
RUN rpm2cpio libtasn1* | cpio -idmv

# Copy over the binaries and libraries
RUN cp /tmp/usr/bin/clamscan /tmp/usr/bin/freshclam /tmp/usr/lib64/* /opt/app/bin/
RUN cp -r /tmp/usr/bin/clamscan /tmp/usr/bin/freshclam /tmp/usr/lib64/* /opt/app/bin/

# Fix the freshclam.conf settings
RUN echo "DatabaseMirror database.clamav.net" > /opt/app/bin/freshclam.conf
Expand All @@ -45,7 +91,7 @@ RUN echo "CompressLocalDatabase yes" >> /opt/app/bin/freshclam.conf
WORKDIR /opt/app
RUN zip -r9 --exclude="*test*" /opt/app/build/lambda.zip *.py bin

WORKDIR /usr/local/lib/python3.7/site-packages
WORKDIR /var/lang/lib/python3.9/site-packages
RUN zip -r9 /opt/app/build/lambda.zip *

WORKDIR /opt/app
WORKDIR /opt/app
Loading

0 comments on commit 5a62223

Please sign in to comment.