Merge branch 'main' into deploy #25
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
name: Deploy to AWS Lambda | |
on: | |
push: | |
branches: | |
- deploy | |
permissions: | |
contents: write | |
packages: write | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.12.1" | |
- name: Install dependencies | |
run: | | |
python -m pip install --user pipx | |
python -m pipx ensurepath | |
pipx install hatch | |
- name: Create .env file | |
run: | | |
echo "${{ secrets.SOLESEARCH_ENV_FILE }}" > .env | |
shell: bash | |
- name: Build zip | |
run: | | |
hatch build -t zipped-directory | |
dist_dir="dist/" | |
zip_file=$(find "$dist_dir" -type f -name "*.zip" -print -quit) | |
build_file=$(realpath "$zip_file") | |
echo "Zip file found: $build_file" | |
hatch env create | |
HATCH_SITE_PACKAGES_DIR=$(hatch env find)/lib/python3.12/site-packages | |
cd $HATCH_SITE_PACKAGES_DIR | |
zip -r $build_file * | |
cd ${{ github.workspace }} | |
cp $build_file ${{ github.workspace }}/deploy.zip | |
shell: bash | |
- name: Deploy to Lambda | |
uses: appleboy/[email protected] | |
with: | |
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws_region: us-east-1 | |
function_name: solesearch-api | |
zip_file: deploy.zip | |
timeout: 10 | |
handler: api.main.handler | |
runtime: python3.12 | |
role: arn:aws:iam::930702711470:role/service-role/solesearch-api-role-qr34kqa5 |