Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI⚡️CD #52

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: replicate-cd

on:
push:
branches:
- main

jobs:
push:
runs-on: ubuntu-latest
env:
BASE_MODEL: 'replicate-internal/official-sdxl-prod'
PROD_MODEL: 'replicate-internal/official-sdxl-prod'

steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: what changed
id: what-changed
run: |
FILES_CHANGED=$(git diff --name-only --diff-filter=AMR ${{ github.event.before }} ${{ github.event.after }} | xargs)
echo "FILES_CHANGED=$FILES_CHANGED" >> $GITHUB_ENV
if echo "$FILES_CHANGED" | grep -q 'cog.yaml'; then
echo "cog-push=true" >> $GITHUB_OUTPUT
else
echo "cog-push=false" >> $GITHUB_OUTPUT
fi
if ${{ contains(github.event.head_commit.message, '[cog build]') }}; then
echo "cog-push=true" >> $GITHUB_OUTPUT
fi

# if cog.yaml changes - cog build and push. else - yolo build and push!
- name: did-it-tho
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did-it-tho

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hah the title of this step was borne out of ...debugging frustration.

but it shall stand.

env:
COG_PUSH: ${{ steps.what-changed.outputs.cog-push }}
run: |
echo "cog push?: $COG_PUSH"
echo "changed files: $FILES_CHANGED"

- name: setup-cog
if: steps.what-changed.outputs.cog-push == 'true'
uses: replicate/[email protected]
with:
token: ${{ secrets.REPLICATE_API_TOKEN }}
install-cuda: false
Comment on lines +46 to +49
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uses: replicate/[email protected]
with:
token: ${{ secrets.REPLICATE_API_TOKEN }}
install-cuda: false
uses: replicate/setup-cog@v2
with:
token: ${{ secrets.REPLICATE_API_TOKEN }}

Bumped to v2 here, where CUDA drivers are not installed by default.


- name: cog-build
if: steps.what-changed.outputs.cog-push == 'true'
run: |
cog build

Comment on lines +51 to +55
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- name: cog-build
if: steps.what-changed.outputs.cog-push == 'true'
run: |
cog build

Can you try taking this cog build step out entirely and letting cog push do it implicitly? I think there is some bug in Cog right now where sometimes cog build will fail on its own, but not if it's run as part of a push. Don't know what's that's about but I've seen it happen.

- name: cog-push
if: steps.what-changed.outputs.cog-push == 'true'
run: |
cog push r8.im/"$PROD_MODEL"

- name: install-yolo
run: |
sudo curl -o /usr/local/bin/yolo -L "https://github.com/replicate/yolo/releases/latest/download/yolo_$(uname -s)_$(uname -m)"
sudo chmod +x /usr/local/bin/yolo

# yolo as hack for pushing environment variables
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL 👀

- name: yolo-push-env
if: steps.what-changed.outputs.cog-push == 'true'
env:
REPLICATE_API_TOKEN: ${{secrets.REPLICATE_API_TOKEN}}
SENTRY_DSN: ${{secrets.SENTRY_DSN}}
run: |
touch meaningless_file.txt
echo "adding environment variables to $PROD_MODEL"
yolo push -e SENTRY_DSN="$SENTRY_DSN" --base $PROD_MODEL --dest $PROD_MODEL meaningless_file.txt

- name: yolo-push
if: steps.what-changed.outputs.cog-push == 'false'
env:
REPLICATE_API_TOKEN: ${{secrets.REPLICATE_API_TOKEN}}
SENTRY_DSN: ${{secrets.SENTRY_DSN}}
run: |
echo "pushing changes from $BASE_MODEL to $PROD_MODEL"
echo "changed files: $FILES_CHANGED"
yolo push -e SENTRY_DSN="$SENTRY_DSN" --base $BASE_MODEL --dest $PROD_MODEL $FILES_CHANGED

## TODO once it exists - use deployments API to update appropriate deployment
100 changes: 100 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: replicate-ci

on:
pull_request:
branches:
- main

jobs:
push:
runs-on: ubuntu-latest
env:
BASE_MODEL: 'replicate-internal/official-sdxl-prod'
STAGING_MODEL: 'replicate-internal/official-sdxl-staging'

steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: what changed
id: what-changed
run: |
FILES_CHANGED=$(git diff --name-only --diff-filter=AMR ${{ github.event.before }} ${{ github.event.after }} | xargs)
echo "FILES_CHANGED=$FILES_CHANGED" >> $GITHUB_ENV
if echo "$FILES_CHANGED" | grep -q 'cog.yaml'; then
echo "cog-push=true" >> $GITHUB_OUTPUT
else
echo "cog-push=false" >> $GITHUB_OUTPUT
fi
if ${{ contains(github.event.head_commit.message, '[cog build]') }}; then
echo "cog-push=true" >> $GITHUB_OUTPUT
fi

# if cog.yaml changes - cog build and push. else - yolo build and push!
- name: did-it-tho
env:
COG_PUSH: ${{ steps.what-changed.outputs.cog-push }}
run: |
echo "cog push?: $COG_PUSH"
echo "changed files: $FILES_CHANGED"

- name: setup-cog
if: steps.what-changed.outputs.cog-push == 'true'
uses: replicate/[email protected]
with:
token: ${{ secrets.REPLICATE_API_TOKEN }}
install-cuda: false

- name: cog-build
if: steps.what-changed.outputs.cog-push == 'true'
run: |
cog build

- name: cog-push
if: steps.what-changed.outputs.cog-push == 'true'
run: |
cog push r8.im/"$STAGING_MODEL"

- name: install-yolo
run: |
sudo curl -o /usr/local/bin/yolo -L "https://github.com/replicate/yolo/releases/latest/download/yolo_$(uname -s)_$(uname -m)"
sudo chmod +x /usr/local/bin/yolo

# TODO: once you confirm sentry works, remove from staging.
# yolo as hack for pushing environment variables
- name: yolo-push-env
if: steps.what-changed.outputs.cog-push == 'true'
env:
REPLICATE_API_TOKEN: ${{secrets.REPLICATE_API_TOKEN}}
SENTRY_DSN: ${{secrets.SENTRY_DSN}}
run: |
touch meaningless_file.txt
echo "adding environment variables to $STAGING_MODEL"
yolo push -e SENTRY_DSN="$SENTRY_DSN" --base $STAGING_MODEL --dest $STAGING_MODEL meaningless_file.txt

- name: yolo-push
if: steps.what-changed.outputs.cog-push == 'false'
env:
REPLICATE_API_TOKEN: ${{secrets.REPLICATE_API_TOKEN}}
SENTRY_DSN: ${{secrets.SENTRY_DSN}}
run: |
echo "pushing changes from $BASE_MODEL to $STAGING_MODEL"
echo "changed files: $FILES_CHANGED"
yolo push -e SENTRY_DSN="$SENTRY_DSN" --base $BASE_MODEL --dest $STAGING_MODEL $FILES_CHANGED

- uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: install python test deps
run: |
pip install -r requirements_test.txt

- name: test model
env:
REPLICATE_API_TOKEN: ${{secrets.REPLICATE_API_TOKEN}}
TEST_ENV: 'staging'
run: |
pytest tests/test_predict.py
1 change: 1 addition & 0 deletions cog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ build:
- "fire==0.5.0"
- "opencv-python>=4.1.0.25"
- "mediapipe==0.10.2"
- "sentry_sdk==1.40"

run:
- curl -o /usr/local/bin/pget -L "https://github.com/replicate/pget/releases/download/v0.0.3/pget" && chmod +x /usr/local/bin/pget
Expand Down
Loading