Repository navigation
feat: Add Docker deployment guide and update docker-compose configura⦠#24
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Release version (e.g., v1.0.0)' | |
| required: true | |
| type: string | |
| push: | |
| tags: | |
| - 'v*' | |
| permissions: | |
| contents: write | |
| pages: write | |
| id-token: write | |
| packages: write | |
| jobs: | |
| create-release: | |
| runs-on: ubuntu-latest | |
| if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: 3.11.x | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Set release version | |
| id: version | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| VERSION="${{ github.event.inputs.version }}" | |
| else | |
| VERSION=${GITHUB_REF#refs/tags/} | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "version_number=${VERSION#v}" >> $GITHUB_OUTPUT | |
| - name: Generate changelog | |
| id: changelog | |
| run: | | |
| # Generate changelog from git commits since last tag | |
| LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | |
| if [ -z "$LAST_TAG" ]; then | |
| CHANGES=$(git log --pretty=format:"- %s" --no-merges) | |
| else | |
| CHANGES=$(git log --pretty=format:"- %s" --no-merges $LAST_TAG..HEAD) | |
| fi | |
| # Create changelog content | |
| cat > CHANGELOG_TEMP.md << EOF | |
| ## What's Changed | |
| $CHANGES | |
| ## π Features | |
| - Enhanced Django REST API functionality | |
| - Improved test coverage and CI/CD pipeline | |
| - Updated documentation and README | |
| ## π Bug Fixes | |
| - Various bug fixes and improvements | |
| ## π§ Technical Improvements | |
| - Code quality improvements | |
| - Security enhancements | |
| - Performance optimizations | |
| **Full Changelog**: https://github.com/${{ github.repository }}/compare/$LAST_TAG...${{ steps.version.outputs.version }} | |
| EOF | |
| - name: Run tests | |
| run: | | |
| python manage.py check | |
| pytest --verbose | |
| - name: Create source distribution | |
| run: | | |
| # Create a clean source archive | |
| mkdir -p dist/ | |
| git archive --format=tar.gz --prefix=SecCodeSmith-backend-${{ steps.version.outputs.version_number }}/ HEAD > dist/SecCodeSmith-backend-${{ steps.version.outputs.version_number }}.tar.gz | |
| git archive --format=zip --prefix=SecCodeSmith-backend-${{ steps.version.outputs.version_number }}/ HEAD > dist/SecCodeSmith-backend-${{ steps.version.outputs.version_number }}.zip | |
| - name: Generate deployment artifacts | |
| run: | | |
| # Create deployment script | |
| cat > dist/deploy.sh << 'EOF' | |
| #!/bin/bash | |
| # SecCodeSmith Backend Deployment Script | |
| set -e | |
| echo "π Starting SecCodeSmith Backend deployment..." | |
| # Update system packages | |
| sudo apt-get update | |
| # Install Python and dependencies | |
| sudo apt-get install -y python3 python3-pip python3-venv postgresql postgresql-contrib redis-server | |
| # Create virtual environment | |
| python3 -m venv .venv | |
| source .venv/bin/activate | |
| # Install Python dependencies | |
| pip install -r requirements.txt | |
| # Set up database | |
| python manage.py migrate | |
| # Collect static files (if applicable) | |
| python manage.py collectstatic --noinput || true | |
| # Create superuser (optional) | |
| echo "To create a superuser, run: python manage.py createsuperuser" | |
| # Start services | |
| echo "β Deployment complete!" | |
| echo "To start the server, run: python manage.py runserver" | |
| EOF | |
| chmod +x dist/deploy.sh | |
| - name: Create Release | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ steps.version.outputs.version }} | |
| release_name: SecCodeSmith Backend ${{ steps.version.outputs.version }} | |
| body_path: CHANGELOG_TEMP.md | |
| draft: false | |
| prerelease: false | |
| - name: Upload Source Archive (tar.gz) | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: ./dist/SecCodeSmith-backend-${{ steps.version.outputs.version_number }}.tar.gz | |
| asset_name: SecCodeSmith-backend-${{ steps.version.outputs.version_number }}.tar.gz | |
| asset_content_type: application/gzip | |
| - name: Upload Source Archive (zip) | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: ./dist/SecCodeSmith-backend-${{ steps.version.outputs.version_number }}.zip | |
| asset_name: SecCodeSmith-backend-${{ steps.version.outputs.version_number }}.zip | |
| asset_content_type: application/zip | |
| - name: Upload Deployment Script | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: ./dist/deploy.sh | |
| asset_name: deploy.sh | |
| asset_content_type: application/x-shellscript | |
| docker-release: | |
| runs-on: ubuntu-latest | |
| needs: create-release | |
| if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ghcr.io/${{ github.repository }} | |
| tags: | | |
| type=ref,event=tag | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |