Skip to content

Commit

Permalink
Merge branch 'HERMES-SOC:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
rstrub authored Jan 23, 2024
2 parents f3c5cdb + 92f63ac commit 7e7c350
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 44 deletions.
102 changes: 60 additions & 42 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,70 @@
{
"name": "Ubuntu 20.04 Python 3",
// Repo where this image's Dockerfile is maintained: https://github.com/HERMES-SOC/docker-lambda-base
"image": "public.ecr.aws/w5r9l1c8/swsoc-docker-lambda-base:latest",
"initializeCommand": "docker logout public.ecr.aws && docker pull public.ecr.aws/w5r9l1c8/swsoc-docker-lambda-base:latest",
// Set *default* container specific settings.json values on container create.
"settings": {
"python.pythonPath": "/usr/bin/python3",
"python.languageServer": "Pylance",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.blackPath": "/usr/local/bin/black",
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length",
"100"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.linting.lintOnSave": true,
"python.linting.flake8Enabled": true,
"editor.formatOnSave": true,
"python.linting.banditPath": "/usr/local/bin/bandit",
"python.linting.flake8Path": "/usr/local/bin/flake8",
"python.linting.mypyPath": "/usr/local/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/bin/pydocstyle",
"python.linting.pylintPath": "/usr/bin/pylint",
"terminal.integrated.defaultProfile.linux": "bash (login)",
"terminal.integrated.profiles.linux": {
"bash (login)": {
"path": "bash"
}
}
"image": "public.ecr.aws/w5r9l1c8/dev-swsoc-docker-lambda-base:latest",
"initializeCommand": "docker logout public.ecr.aws && docker pull public.ecr.aws/w5r9l1c8/dev-swsoc-docker-lambda-base:latest",
// If you want to run the production version of the container, comment out the image and initializeCommand lines above and uncomment the line below.
// "image": "public.ecr.aws/w5r9l1c8/swsoc-docker-lambda-base:latest",
// "initializeCommand": "docker logout public.ecr.aws && docker pull public.ecr.aws/w5r9l1c8/swsoc-docker-lambda-base:latest",
"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"python.pythonPath": "/usr/bin/python3",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.languageServer": "Pylance",

//PyLint Settings
"pylint.enabled": true,
"pylint.path": ["/usr/bin/pylint"],
"pylint.lintOnChange": true,

// Black Settings
"python.editor.defaultFormatter": "ms-python.black-formatter",
"python.editor.formatOnSave": true,
"black-formatter.path": ["/usr/local/bin/black"],
"black-formatter.args": [
"--line-length",
"100"
],

// Flake8 Settings
"flake8.path": ["/usr/local/bin/flake8"],
"flake8.lintOnChange": true,

// Terminal Settings
"terminal.integrated.defaultProfile.linux": "bash (login)",
"terminal.integrated.profiles.linux": {
"bash (login)": {
"path": "bash"
}
}
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.pylint",
"ms-python.black-formatter",
"ms-python.flake8",
"marklarah.pre-commit-vscode",
"ms-toolsai.jupyter",
"ms-toolsai.jupyter-renderers",
"ms-toolsai.jupyter-keymap",
"jithurjacob.nbpreviewer"
],
}
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"marklarah.pre-commit-vscode",
"ms-toolsai.jupyter",
"ms-toolsai.jupyter-renderers",
"ms-toolsai.jupyter-keymap",
"jithurjacob.nbpreviewer"
],

// Mount to a volume if you'd like to persist data to your disk
// "mounts": ["source=<add your /path/on/host here>, target=/workspaces/hermes_core, type=bind"],
"mounts": [
"source=${localEnv:HOME}/.bash_profile,target=/home/vscode/.bashrc,type=bind,consistency=cached"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
//"postCreateCommand": "bash -i -c 'pip3 install --user .[all]'",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
Expand Down
84 changes: 84 additions & 0 deletions .github/workflows/calibration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Test Lambda Function Locally and Upload Artifacts

on: [pull_request_target]

jobs:
test-and-upload:
permissions:
pull-requests: write
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Build Lambda Docker Image
run: |
cd ..
git clone https://github.com/HERMES-SOC/sdc_aws_processing_lambda.git
cd sdc_aws_processing_lambda/lambda_function
BRANCH_URL="git+https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git@${{ github.event.pull_request.head.ref }}"
echo "Branch URL: $BRANCH_URL"
sed -i "s|hermes_eea @ git+https://github.com/HERMES-SOC/hermes_eea.git|hermes_eea @ $BRANCH_URL|" requirements.txt
docker build -t processing_function:latest . --network host
- name: Run Lambda Docker Container
run: |
docker run -d -p 9000:8080 -e USE_INSTRUMENT_TEST_DATA=True processing_function:latest
container_id=$(docker ps -qf "ancestor=processing_function:latest")
echo "Container ID: $container_id"
- name: Wait for Container to Initialize
run: sleep 5

- name: Test Lambda Function with curl
id: test-lambda
run: |
cd ../sdc_aws_processing_lambda/
# Run curl and write the HTTP status code to a variable
HTTP_STATUS=$(curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d @lambda_function/tests/test_data/test_eea_event.json)
echo "HTTP Status: $HTTP_STATUS"
# Grep the HTTP status code from the curl output for 200 (success)
STATUS_CODE=$(echo $HTTP_STATUS | grep -oP '200')
echo "Status Code: $STATUS_CODE"
# If the HTTP status code is 200, then the test is successful
if [ "$STATUS_CODE" == "200" ]; then
echo "Success: HTTP status is 200"
echo "test_success=true" >> $GITHUB_OUTPUT
exit 0 # Exit with success
else
echo "Error or unexpected HTTP status: $HTTP_STATUS"
echo "test_success=false" >> $GITHUB_OUTPUT
exit 1 # Exit with failure
fi
- name: Copy Processed Files from Container
if: steps.test-lambda.outputs.test_success == 'true'
run: |
container_id=$(docker ps -qf "ancestor=processing_function:latest")
# Create a directory for processed files
mkdir processed_files
# Copy the files from the container to the host
docker cp $container_id:/test_data/. processed_files/
- name: Upload Processed Files as Artifact
id: artifact-upload-step
if: steps.test-lambda.outputs.test_success == 'true'
uses: actions/upload-artifact@v4
with:
name: processed-files
path: processed_files/

- name: Echo Artifact URL
if: steps.test-lambda.outputs.test_success == 'true'
run: echo "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.artifact-upload-step.outputs.artifact-id }}"

- name: Comment PR
if: steps.test-lambda.outputs.test_success == 'true'
uses: thollander/actions-comment-pull-request@v2
# Only comment if triggered by a pull request target event
with:
message: |
The processed files are available as an artifact: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.artifact-upload-step.outputs.artifact-id }}
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ repos:
# E902 - IOError
# F822: undefined name in __all__
# F823: local variable name referenced before assignment
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
args: ['--count', '--select', 'E101,E11,E111,E112,E113,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E133,E20,E211,E231,E241,E242,E251,E252,E26,E265,E266,E27,E301,E302,E303,E304,E305,E306,E401,E402,E502,E701,E711,E712,E713,E714,E722,E731,E901,E902,F822,F823,W191,W291,W292,W293,W391,W601,W602,W603,W604,W605,W690']
Expand Down

0 comments on commit 7e7c350

Please sign in to comment.