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

Feat/package - part 2 #162

Merged
merged 6 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ RUN apt-get update && apt-get install -y \
vim \
&& rm -rf /var/lib/apt/lists/*

COPY backend/requirements.txt ./backend/
RUN pip install -r backend/requirements.txt
COPY backend/pyproject.toml ./backend/
RUN pip install ./backend/

# Install Node.js for frontend development
RUN curl -fsSL https://deb.nodesource.com/setup_23.x | bash - \
Expand Down
81 changes: 78 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release Docker Images
name: Release

on:
release:
Expand All @@ -9,15 +9,46 @@ env:
BACKEND_IMAGE_NAME: ${{ github.repository }}-backend

jobs:
build-and-push:
update-version:
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
version: ${{ steps.get-version.outputs.version }}
steps:
- uses: actions/checkout@v4

- name: Get version from tag
id: get-version
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

- name: Update pyproject.toml version
run: |
VERSION=${{ steps.get-version.outputs.version }}
sed -i "s/version = \".*\"/version = \"$VERSION\"/" backend/pyproject.toml

- name: Commit and push version update
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git add backend/pyproject.toml
git commit -m "chore: update version to ${{ steps.get-version.outputs.version }}"
git push

build-and-push-docker:
needs: update-version
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
image_name: ${{ steps.meta-backend.outputs.tags }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.release.tag_name }}

- name: Log in to the Container registry
uses: docker/login-action@v3
Expand All @@ -43,4 +74,48 @@ jobs:
push: true
target: production
tags: ${{ steps.meta-backend.outputs.tags }}
labels: ${{ steps.meta-backend.outputs.labels }}
labels: ${{ steps.meta-backend.outputs.labels }}

publish-to-pypi:
needs: [update-version, build-and-push-docker]
runs-on: ubuntu-latest
permissions:
id-token: write
packages: read
defaults:
run:
working-directory: ./backend

steps:
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build package in Docker
run: |
# Create a temporary container from the production image
CONTAINER_ID=$(docker create ${{ needs.build-and-push-docker.outputs.image_name }})

# Start the container
docker start $CONTAINER_ID

# Create dist directory
mkdir -p dist

# Build the package inside the container
docker exec $CONTAINER_ID pip install build
docker exec $CONTAINER_ID python -m build

# Copy the built package from the container
docker cp $CONTAINER_ID:/pyspur/backend/dist/. dist/

# Clean up
docker rm -f $CONTAINER_ID

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/
4 changes: 2 additions & 2 deletions Dockerfile.backend
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ RUN apt-get update && apt-get install -y \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /pyspur/backend
COPY backend/requirements.txt .
RUN pip install -r requirements.txt
COPY backend/pyproject.toml .
RUN pip install .

# Development stage
FROM base AS development
Expand Down
5 changes: 3 additions & 2 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies = [
"docx2txt==0.8",
"docx2python==3.3.0",
"fastapi==0.115.6",
"genanki==0.13.1",
"google-api-python-client==2.159.0",
"grpcio==1.69.0",
"Jinja2==3.1.5",
Expand All @@ -33,7 +34,8 @@ dependencies = [
"ollama==0.4.5",
"pandas==2.2.3",
"pinecone==5.4.2",
# "psycopg2==2.9.10",
"praw==7.8.1",
"psycopg2-binary==2.9.10",
"pydantic==2.10.5",
"pypdf==5.1.0",
"python-dotenv==1.0.1",
Expand All @@ -50,7 +52,6 @@ dependencies = [
"retrying==1.3.4",
"slack_sdk==3.34.0",
"SQLAlchemy==2.0.36",
"psycopg2-binary==2.9.10",
"supabase==2.11.0",
"six==1.17.0",
"tenacity==8.3.0",
Expand Down
52 changes: 0 additions & 52 deletions backend/requirements.txt

This file was deleted.