Integrate into CI/CD
You can integrate Beam into an existing CI/CD process to deploy your code automatically.
Automated Deploys
It’s fairly straightforward to setup automation for deploying your code to Beam. At a high level, the following steps are all you need:
curl https://raw.githubusercontent.com/slai-labs/get-beam/main/get-beam.sh -sSfL | sh
pip3 install --upgrade pip
pip3 install beam-sdk
beam configure --clientId=$BEAM_CLIENT_ID --clientSecret=$BEAM_CLIENT_SECRET --profile=$PROFILE
beam deploy app.py --$PROFILE
Example: Github Actions
You can setup a Github workflow to deploy your code whenever a new commit is made to your Git repo.
Setup Environment Variables
First, add your BEAM_CLIENT_ID
and BEAM_CLIENT_SECRET
to your Github Secrets:
Create Actions file
For a detailed walk-through of this step, Github’s documentation is the best resource.
- Create a directory called
.github/workflows
in your project. - In the
.github/workflows
directory, create a file namedbeam-actions.yml
Deploying to Different Environments
You might want to setup separate Beam apps for your staging
or prod
environments.
In your Beam app, you can setup your app name to dynamically update based on the Github branch you’ve deployed to. BEAM_DEPLOY_ENV
will get set in our Github Actions script, based on the branch name:
app = App(
name=f'sentiment-analysis-{os.getenv("BEAM_DEPLOY_ENV", "staging")}',
runtime=Runtime(),
)
If you push to the main
branch, the app sentiment-analysis-prod
will be deployed. If you push to the staging
branch, sentiment-analysis-staging
will be deployed. You can customize this with your own branch names.
Here’s what the Github Action looks like. Make sure you’ve added a BEAM_CLIENT_ID
and BEAM_CLIENT_SECRET
to your Github Secrets:
name: Deploy to Beam
on:
push:
branches:
- main
- staging
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set environment variables
run: |
if [[ "${{ github.ref }}" == 'refs/heads/main' ]]; then
echo "Setting environment variables: PROD"
echo "BEAM_DEPLOY_ENV=prod" >> $GITHUB_ENV
elif [[ "${{ github.ref }}" == 'refs/heads/staging' ]]; then
echo "Setting environment variables: STAGING"
echo "BEAM_DEPLOY_ENV=staging" >> $GITHUB_ENV
fi
- name: Authenticate and deploy to Beam
env:
BEAM_CLIENT_ID: ${{ secrets.BEAM_CLIENT_ID }}
BEAM_CLIENT_SECRET: ${{ secrets.BEAM_CLIENT_SECRET }}
run: |
curl https://raw.githubusercontent.com/slai-labs/get-beam/main/get-beam.sh -sSfL | sh
pip3 install --upgrade pip
pip3 install beam-sdk
pip3 install fastapi
echo "beam configure --clientId $BEAM_CLIENT_ID --clientSecret $BEAM_CLIENT_SECRET"
beam configure --clientId $BEAM_CLIENT_ID --clientSecret $BEAM_CLIENT_SECRET
beam deploy app.py
When you push to either main
or staging
, a new app will be deployed for each push:
Was this page helpful?