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

Python3.12 #3

Merged
merged 52 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b0bdb8c
WIP: for python3
smellman Dec 18, 2019
62c3ea4
fixes focus for operator
smellman Dec 18, 2019
3b80b73
fixes focus for operator
smellman Dec 18, 2019
023dbd5
fixes README for python3
smellman Dec 18, 2019
512db7e
fixes README for python3
smellman Dec 18, 2019
e83d913
fixes site-packages path
smellman Dec 20, 2019
d48c47c
process result return as bytes, fixes bytes to string before processing
smellman Dec 20, 2019
fb78663
use python 3.7 for circleci test
smellman Dec 20, 2019
a57787d
fixes code format by black
smellman Dec 20, 2019
f0baa5d
Merge pull request #107 from Georepublic/for_python3
jaygorrell Dec 29, 2019
c09a62d
Without this change, at the logs of the update function you get:
avipinto Jun 7, 2020
33143a2
Merge pull request #126 from avipinto/fix-issue-#125---Docker-file-no…
jdepp Apr 30, 2021
824f099
added cloudformation template to bootstrap infra creation
May 3, 2021
a97b50d
bumping av-scanner lambda memory up
May 3, 2021
bfd645d
updated readme for cloudformation create
jdepp May 3, 2021
a494d9a
updated readme for cloudformation create
jdepp May 3, 2021
a689f3a
updated readme for cloudformation create
jdepp May 3, 2021
26f45eb
updated pre commit hooks for cloudformation
jdepp May 3, 2021
34425a0
updated pre commit hooks for cloudformation
jdepp May 3, 2021
a984c6b
updated pre commit hooks for cloudformation
jdepp May 3, 2021
58110be
bumping pre-commit version to latest
jdepp May 3, 2021
7583865
bumping pre-commit version to latest
jdepp May 3, 2021
b773c9e
bumping pre-commit version to latest
jdepp May 3, 2021
4a3b0e5
bumping pre-commit version to latest
jdepp May 3, 2021
bee01c1
bumping pre-commit version to latest
jdepp May 3, 2021
6751dc5
modifying python black version
jdepp May 3, 2021
4cfab73
modifying cloudformation lint version
jdepp May 3, 2021
015a0fc
linted cloudformation template
jdepp May 3, 2021
d6ace6c
linted cloudformation template
jdepp May 3, 2021
d56d97e
linted precommit file
jdepp May 3, 2021
ee9b5a1
linted precommit file
jdepp May 3, 2021
2abe9d2
linted readme file
jdepp May 3, 2021
1b087b2
linted files
jdepp May 3, 2021
edc2f52
python version
jdepp May 3, 2021
3dba78d
Merge pull request #164 from upsidetravel/cloudformation-templates
jdepp May 4, 2021
20d5391
Add endpoint urls for AWS services
dmarkey May 20, 2021
50de02b
Take out unused imports
dmarkey May 20, 2021
5ef73fc
Update README
dmarkey May 23, 2021
c7a53ed
Fix typo
dmarkey May 23, 2021
0e86c59
Merge pull request #167 from dmarkey/master
jdepp May 26, 2021
f530379
#2 bump all packages, remove nose and add pytest, fixes warnings in test
smellman Jan 5, 2024
b192043
#2 downgrade urllib3 to supports python3.7
smellman Jan 10, 2024
1f4ad28
#2 fix: find command raise error
smellman Jan 10, 2024
473bce5
fixes missing 'ld'
smellman Jan 17, 2024
cdbed44
target: python 3.12, add localstack for testing
smellman Jan 19, 2024
4391036
remove coverage report directory from git
smellman Jan 19, 2024
11118e2
remove local script because can't run lambda by os module doesn't work
smellman Jan 19, 2024
1e201e1
enable to pre-commit with venv
smellman Jan 19, 2024
3ade626
add localstack test
smellman Jan 19, 2024
f973798
added workflow, add sleep in lambda
smellman Jan 19, 2024
5b070f4
fix typo, run on push only
smellman Jan 19, 2024
adeba9d
clean up
smellman Jan 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
96 changes: 0 additions & 96 deletions .circleci/config.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .coveragerc
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
@@ -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
@@ -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
@@ -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
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
@@ -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/
37 changes: 28 additions & 9 deletions Dockerfile
@@ -1,32 +1,51 @@
FROM amazonlinux:2
FROM amazonlinux:2023 as builder

# Set up working directories
RUN mkdir -p /opt/python

# Install packages
RUN dnf update -y
RUN dnf install -y gcc openssl-devel bzip2-devel libffi-devel zlib-devel wget make tar xz

# Download and install Python 3.12
WORKDIR /opt
RUN wget https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tar.xz
RUN tar xvf Python-3.12.1.tar.xz
WORKDIR /opt/Python-3.12.1
RUN ./configure --enable-optimizations --prefix=/opt/python
RUN make -j
RUN make install

FROM amazonlinux:2023

# Set up working directories
RUN mkdir -p /opt/app
RUN mkdir -p /opt/app/build
RUN mkdir -p /opt/app/bin/

# Copy over the python binaries
COPY --from=builder /opt/python /opt/python

# Copy in the lambda source
WORKDIR /opt/app
COPY ./*.py /opt/app/
COPY requirements.txt /opt/app/requirements.txt

# Install packages
RUN yum update -y
RUN yum install -y cpio python2-pip yum-utils zip unzip less
RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
RUN dnf update -y
RUN dnf install -y cpio openssl bzip2 libffi yum-utils zip unzip less

# This had --no-cache-dir, tracing through multiple tickets led to a problem in wheel
RUN pip install -r requirements.txt
RUN /opt/python/bin/pip3 install -r requirements.txt
RUN rm -rf /root/.cache/pip

# 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
RUN yumdownloader -x \*i686 --archlist=x86_64 clamav clamav-lib clamav-update libtool-ltdl
RUN rpm2cpio clamav-0*.rpm | cpio -idmv
RUN rpm2cpio clamav-lib*.rpm | cpio -idmv
RUN rpm2cpio clamav-update*.rpm | cpio -idmv
RUN rpm2cpio json-c*.rpm | cpio -idmv
RUN rpm2cpio pcre*.rpm | cpio -idmv
RUN rpm2cpio libtool-ltdl* | cpio -idmv

# Copy over the binaries and libraries
RUN cp /tmp/usr/bin/clamscan /tmp/usr/bin/freshclam /tmp/usr/lib64/* /opt/app/bin/
Expand All @@ -39,7 +58,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/lib/python2.7/site-packages
WORKDIR /opt/python/lib/python3.12/site-packages
RUN zip -r9 /opt/app/build/lambda.zip *

WORKDIR /opt/app
19 changes: 6 additions & 13 deletions Makefile
Expand Up @@ -29,7 +29,8 @@ clean: ## Clean build artifacts
rm -rf build/
rm -rf tmp/
rm -f .coverage
find ./ -type d -name '__pycache__' -delete
rm -rf .pytest_cache/
find ./ -type d -name '__pycache__' | xargs rm -rf
find ./ -type f -name '*.pyc' -delete

.PHONY: archive
Expand All @@ -40,8 +41,8 @@ archive: clean ## Create the archive for AWS lambda

.PHONY: pre_commit_install ## Ensure that pre-commit hook is installed and kept up to date
pre_commit_install: .git/hooks/pre-commit ## Ensure pre-commit is installed
.git/hooks/pre-commit: /usr/local/bin/pre-commit
pip install pre-commit==1.18.3
.git/hooks/pre-commit: venv ## Ensure venv is created first
pip install pre-commit
pre-commit install
pre-commit install-hooks

Expand All @@ -51,16 +52,8 @@ pre_commit_tests: ## Run pre-commit tests

.PHONY: test
test: clean ## Run python tests
nosetests
pytest --no-cov

.PHONY: coverage
coverage: clean ## Run python tests with coverage
nosetests --with-coverage

.PHONY: scan
scan: ./build/lambda.zip ## Run scan function locally
scripts/run-scan-lambda $(TEST_BUCKET) $(TEST_KEY)

.PHONY: update
update: ./build/lambda.zip ## Run update function locally
scripts/run-update-lambda
pytest --cov=. --cov-report html