Skip to content

Commit

Permalink
add dockerfile and deploy.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Oct 30, 2024
1 parent 830f029 commit f900a6d
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 0 deletions.
141 changes: 141 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: Deploy app to Google Cloudrun
on:
pull_request:
paths:
- "src/**"
- ".github/workflows/deploy.yml"
push:
branches:
- main
paths:
- "src/**"
- ".github/workflows/deploy.yml"
tags:
- "release-*"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
CI: true
PROJECT_ID: ${{ secrets.PROJECT_ID }}
MAIN: ${{ github.ref == 'refs/heads/main' }}
SERVICE: app
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
ELEVENLABS_API_KEY: ${{ secrets.ELEVENLABS_API_KEY }}

jobs:
prepare:
runs-on: ubuntu-latest
outputs:
VERSION: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || format('main-{0}', steps.prepare_env.outputs.SHORT_SHA) }}
MAIN_OR_TAGGED: ${{ fromJSON(env.MAIN) || (fromJSON(steps.prepare_env.outputs.TAGGED) && steps.prepare_env.outputs.TAG_BRANCH_NAME == 'main') }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: prepare_env
run: |
echo "TAGGED=${{ startsWith(github.ref, 'refs/tags/api') }}" >> $GITHUB_OUTPUT
SHORT_SHA=$(git rev-parse --short HEAD)
echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_OUTPUT
RAW=$(git branch -r --contains $SHORT_SHA)
TAG_BRANCH_NAME="${RAW##*/}"
echo "TAG_BRANCH_NAME=$TAG_BRANCH_NAME" >> $GITHUB_OUTPUT
lint:
runs-on: ubuntu-latest
needs: prepare
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- id: setup-python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip" # caching pip dependencies
check-latest: true

- run: pip install --force-reinstall -r requirements.txt
if: ${{ steps.setup-python.outputs.cache-hit != 'true' }}

- run: pip install -r requirements.txt
if: ${{ steps.setup-python.outputs.cache-hit == 'true' }}

- uses: chartboost/ruff-action@v1

deploy:
runs-on: ubuntu-latest
needs: [prepare, lint]
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip" # caching pip dependencies
check-latest: true

- uses: google-github-actions/auth@v2
with:
credentials_json: "${{ secrets.GCP_SA_KEY }}"

- uses: google-github-actions/setup-gcloud@v2
- run: gcloud config set app/cloud_build_timeout 300

- id: deploy
uses: google-github-actions/deploy-cloudrun@v2
with:
service: ${{ env.SERVICE }}
source: ./
tag: ${{ needs.prepare.outputs.VERSION }}
no_traffic: true
timeout: "5m"
gcloud_version: "482.0.0"
env_vars: |
ENV=prod
OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}
GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}
ANTHROPIC_API_KEY=${{ secrets.ANTHROPIC_API_KEY }}
ELEVENLABS_API_KEY=${{ secrets.ELEVENLABS_API_KEY }}
flags: "--allow-unauthenticated --memory=32Gi --cpu=8 --execution-environment=gen2"

- name: health-check
run: curl -f "${{ steps.deploy.outputs.url }}"
- uses: marocchino/sticky-pull-request-comment@v2
with:
header: api
message: |
app: ${{ steps.deploy.outputs.url }} (${{ github.event.pull_request.head.sha }})
promote:
runs-on: ubuntu-latest
if: (needs.prepare.outputs.MAIN_OR_TAGGED == 'true')
needs: [prepare, deploy, lint]
timeout-minutes: 3
steps:
- uses: google-github-actions/auth@v2
with:
credentials_json: "${{ secrets.GCP_SA_KEY }}"

- uses: google-github-actions/setup-gcloud@v2
- run: gcloud run services update-traffic ${{ env.SERVICE }} --to-tags=${{ needs.prepare.outputs.VERSION }}=100 --project=${{ env.PROJECT_ID }} --region=us-central1

cleanup:
runs-on: ubuntu-latest
needs: promote
timeout-minutes: 3
steps:
- uses: google-github-actions/auth@v2
with:
credentials_json: "${{ secrets.GCP_SA_KEY }}"
- uses: google-github-actions/setup-gcloud@v2
- name: cleanup old revisions
run: |
gcloud run revisions list --service=${{ env.SERVICE }} --project=${{ env.PROJECT_ID }} --region=us-central1 --sort-by=CREATE_TIME --format="value(REVISION)" | tail -n +4 | xargs -I {} gcloud run revisions delete {} --project=${{ env.PROJECT_ID }} --region=us-central1 --quiet
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.12-slim

# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True
ENV PYTHONDONTWRITEBYTECODE 1

WORKDIR /app

# Install FFmpeg and any other required dependencies
RUN apt-get -yqq update && apt-get -yqq install build-essential ffmpeg && \
rm -rf /var/lib/apt/lists/*

COPY . ./

# Install production dependencies.
RUN pip install --no-cache-dir -r requirements.txt

ENV HOST '0.0.0.0'
EXPOSE $PORT
HEALTHCHECK CMD curl --fail http://$HOST:$PORT/_stcore/health

CMD exec streamlit run app.py --server.port=$PORT --server.address=$HOST
38 changes: 38 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from setuptools import find_packages, setup

setup(
name="audiora",
version="1.0.0",
description="Learn or listen to anything, anytime, through the power of AI-generated audio",
author="Chukwuma Nwaugha",
author_email="chuks@veedo.ai",
url="https://github.com/nwaughachukwuma/audiora",
packages=find_packages(),
install_requires=[
"streamlit",
"httpx",
"asyncio",
"openai",
"anthropic",
"pyperclip",
"python-multipart",
"python-slugify",
"python-dotenv",
"pydub",
"firebase-admin",
"google-auth",
"google-cloud-storage",
"google-api-python-client",
"google-generativeai",
"ruff"
],
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
)

0 comments on commit f900a6d

Please sign in to comment.