-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
190 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
**/__pycache__ | ||
**/.venv | ||
**/.classpath | ||
**/.dockerignore | ||
**/.env | ||
**/.git | ||
**/.gitignore | ||
**/.project | ||
**/.settings | ||
**/.toolstarget | ||
**/.vs | ||
**/.vscode | ||
**/*.*proj.user | ||
**/*.dbmdl | ||
**/*.jfm | ||
**/bin | ||
**/charts | ||
**/docker-compose* | ||
**/compose* | ||
**/Dockerfile* | ||
**/node_modules | ||
**/npm-debug.log | ||
**/obj | ||
**/secrets.dev.yaml | ||
**/values.dev.yaml | ||
LICENSE | ||
README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Build and Push Docker Image | ||
|
||
on: | ||
push | ||
|
||
env: | ||
IMAGE_NAME: ghcr.io/cloudacademy/azure-vcf | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set outputs | ||
id: vars | ||
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to GHCR | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v4 | ||
with: | ||
push: true | ||
platforms: linux/amd64,linux/arm64 | ||
tags: ${{ env.IMAGE_NAME }}:${{ github.ref_name }},${{ env.IMAGE_NAME }}:{{ github.ref_name }}-${{ steps.vars.outputs.sha_short }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
venv/ | ||
__pycache__ | ||
.DS_Store | ||
.DS_Store | ||
.config.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"type": "docker-build", | ||
"label": "docker-build", | ||
"platform": "python", | ||
"dockerBuild": { | ||
"tag": "azurevcfenv:latest", | ||
"dockerfile": "${workspaceFolder}/Dockerfile", | ||
"context": "${workspaceFolder}", | ||
"pull": true | ||
} | ||
}, | ||
{ | ||
"type": "docker-run", | ||
"label": "docker-run: debug", | ||
"dependsOn": [ | ||
"docker-build" | ||
], | ||
"python": { | ||
"file": "src/entry.py" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# For more information, please refer to https://aka.ms/vscode-docker-python | ||
FROM python:3.9-slim | ||
|
||
# Keeps Python from generating .pyc files in the container | ||
ENV PYTHONDONTWRITEBYTECODE=1 | ||
|
||
# Turns off buffering for easier container logging | ||
ENV PYTHONUNBUFFERED=1 | ||
|
||
# Install dependencies for pip install and clean up | ||
RUN apt-get install debian-archive-keyring && \ | ||
apt-get update --allow-insecure-repositories && \ | ||
apt-get install -y build-essential libssl-dev libffi-dev python-dev-is-python3 && \ | ||
apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Install dev dependencies | ||
RUN python -m pip install --upgrade python-dotenv==1.0.0 | ||
|
||
# Install pip requirements | ||
COPY requirements.txt prune_azure_mgmt_libs.sh / | ||
RUN python -m pip install -r requirements.txt | ||
# Prune libs like in prod to keep lambda layer size down | ||
RUN bash prune_azure_mgmt_libs.sh | ||
|
||
WORKDIR /app | ||
COPY . /app | ||
# move config.env to .env if .config.env exists | ||
RUN test -f .config.env && mv .config.env .env | ||
|
||
# Creates a non-root user with an explicit UID and adds permission to access the /app folder | ||
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers | ||
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app | ||
USER appuser | ||
|
||
# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug | ||
CMD ["python", "src/entry.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
# Trim Azure mgmt packages included api versions | ||
keep_api_versions=1 | ||
mgmt_client_dir=venv/lib/python*/site-packages/azure/mgmt | ||
skip_clients=( "eventhub" "monitor" "keyvault") # skip clients requiring more than latest version of the API | ||
for client_dir in $mgmt_client_dir/*; do | ||
if [[ " ${skip_clients[*]} " =~ " $(basename ${client_dir}) " ]]; then | ||
echo "skipping pruning $client_dir" | ||
continue | ||
fi | ||
old_IFS=$IFS; IFS=$'\n' | ||
api_dirs=($(find $client_dir -maxdepth 1 -type d -regex "$client_dir/v[0-9][0-9][0-9][0-9].*" | sort)) | ||
unset IFS; IFS=$old_IFS | ||
if [[ ${#api_dirs[@]} -le $keep_api_versions ]]; then | ||
continue | ||
fi | ||
for i in $(seq 0 1 $(( ${#api_dirs[@]} - $(( $keep_api_versions + 1 )) )) ); do | ||
rm -rf ${api_dirs[i]} | ||
done | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from dotenv import load_dotenv | ||
load_dotenv() | ||
|
||
import time | ||
from config import EVENT_CONFIG | ||
from vcf import handler | ||
|
||
|
||
def timed_handler(event, context): | ||
start = time.time() | ||
result = handler(event, context) | ||
end = time.time() | ||
print(end - start) | ||
return result | ||
|
||
def entry(): | ||
result = timed_handler(EVENT_CONFIG, None) | ||
print(result) | ||
|
||
if __name__ == "__main__": | ||
entry() |