CI/CD configuration examples

Use the following files as a starting point for your automatic deployments. We have included the minimum you need to make your deployments, and hopefully you find them easy to extend.

We use Poetry in our examples but you can adapt to your favorite dependency manager, or use requirements.txt files directly.

Global requirements

In every case you need the following environment variables:

  • PD_API_KEY - The api key that you get to authenticate with Python Deploy. You can find it in your user profile page.
  • PD_APP_ID - The unique ID of the app that you are deploying. This is shown inside each application's page.

Gitlab

# .gitlab-ci.yml
#
# The environment variables can be configured at:
# https://gitlab.com/{YOU}/{YOUR_PROJECT}/-/settings/ci_cd
#
# Use the AWS Lambda image for your Python version. 
image: "lambci/lambda:build-python3.8"

python_deploy:
  stage: deploy
  # Run only when commiting to "main"
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'
  script:
    # We need a requirements.txt file for the dependencies.
    # This step is not required if you have a requirements.txt file already.
    - poetry export -f requirements.txt -o requirements.txt --without-hashes
    - pipx run --spec "pd_aws_lambda[deploy]~=1.0" pd_build_and_deploy

    # Do you have migrations or additional commmands?
    # Then add --wait to the deploy command:
    #
    # - pipx run --spec "pd_aws_lambda[deploy]~=1.0" pd_build_and_deploy --wait
    # - pipx run --spec "pd_aws_lambda[deploy]~=1.0" pd_run -- python3 manage.py migrate

Github

# .github/workflows/python_deploy.yml
#
# The environment variables can be configured at:
# https://github.com/{YOU}/{YOUR_PROJECT}/settings/secrets/actions

# Run only when commiting to "main"
on:
  push:
    branches:
      - main

jobs:
  python_deploy:
    # Use the AWS Lambda image for your Python version. 
    container: lambci/lambda:build-python3.8
    name: Build and Deploy with PythonDeploy
    runs-on: ubuntu-latest
    env:
      PD_API_KEY: ${{ secrets.PD_API_KEY }}
      PD_APP_ID: ${{ secrets.PD_APP_ID }}
    steps:
      - uses: actions/[email protected]
      # We need a requirements.txt file for the dependencies.
      # This step is not required if you have a requirements.txt file already.
      - run: poetry export -f requirements.txt -o requirements.txt --without-hashes
      - run: pipx run --spec "pd_aws_lambda[deploy]~=1.0" pd_build_and_deploy

      # Do you have migrations or additional commmands?
      # Then add --wait to the deploy command:
      #
      # - run: pipx run --spec "pd_aws_lambda[deploy]~=1.0" pd_build_and_deploy --wait
      # - run: pipx run --spec "pd_aws_lambda[deploy]~=1.0" pd_run -- python3 manage.py migrate

Something missing? → [email protected]