Files
OALabs-hashdb/.github/workflows/deploy.yml
T
2021-08-17 16:26:24 -04:00

67 lines
2.4 KiB
YAML

# This is a basic workflow to help you get started with Actions
name: aws-layer-deploy
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Runs a single command using the runners shell
- name: Setup distribution package
run: |
echo "Building distribution package"
mkdir ./dist
mkdir ./dist/python
mkdir ./dist/python/algorithms
cp *.py ./dist/python
cp -r ./algorithms/* ./dist/python/algorithms/
cd ./dist
zip -r hashdb.zip ./python
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install AWS CLI and tools
run: |
python -m pip install --upgrade pip
pip install awscli
sudo apt-get update
sudo apt-get install -y jq
- name: Publish to AWS Lambda Layer
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
LAMBDA_LAYER_ARN: ${{ secrets.LAMBDA_LAYER_ARN }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }}
DEPENDENT_LAMBDA_FUNCTION: ${{ secrets.DEPENDENT_LAMBDA_FUNCTION }}
run: |
echo "Publishing as a layer..."
RESULT_DATA=$(aws lambda publish-layer-version --layer-name "$LAMBDA_LAYER_ARN" --zip-file fileb://dist/hashdb.zip)
LAYER_VERSION=$(jq '.Version' <<< "$RESULT_DATA")
echo "Updating dependent lambda functions to use layer version $LAYER_VERSION..."
UPDATE_RESULT_DATA=$(aws lambda update-function-configuration --function-name "$DEPENDENT_LAMBDA_FUNCTION" --layers "$LAMBDA_LAYER_ARN:$LAYER_VERSION")
echo '::set-output name=SELECTED_COLOR::green'
echo "Done"