-
Notifications
You must be signed in to change notification settings - Fork 0
Day 8: CI/CD workflows, Docker, pytest + Jest tests #8
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
71d48c6
Day 8: CI/CD workflows, Docker, pytest + Jest tests
deshanekanayaka 80f73b9
Fix CI failures: migrate DB name, train model in CI, fix ESLint errors
deshanekanayaka 85e4235
Fix CI and Docker issues
deshanekanayaka 899de54
Rewrite README: add before/after table, ML section, CI/CD, Docker, ba…
deshanekanayaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| name: Backend CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - 'backend/**' | ||
| - 'docker-compose.yml' | ||
| - '.github/workflows/backend-ci.yml' | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - 'backend/**' | ||
| - 'docker-compose.yml' | ||
| - '.github/workflows/backend-ci.yml' | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| services: | ||
| mysql: | ||
| image: mysql:8.0 | ||
| env: | ||
| MYSQL_ROOT_PASSWORD: rootpassword | ||
| MYSQL_DATABASE: diacify_db | ||
| ports: | ||
| - 3306:3306 | ||
| options: >- | ||
| --health-cmd="mysqladmin ping -h 127.0.0.1 -u root -prootpassword" | ||
| --health-interval=10s | ||
| --health-timeout=5s | ||
| --health-retries=10 | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js 20 | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
| cache-dependency-path: 'backend/package-lock.json' | ||
|
|
||
| - name: Install backend dependencies | ||
| run: npm ci | ||
| working-directory: backend | ||
|
|
||
| - name: Run database migrations | ||
| env: | ||
| MYSQL_HOST: 127.0.0.1 | ||
| MYSQL_PORT: 3306 | ||
| MYSQL_USER: root | ||
| MYSQL_PASSWORD: rootpassword | ||
| MYSQL_DATABASE: diacify_db | ||
| run: | | ||
| for file in backend/database/migrations/00[1-5]_*.sql; do | ||
| echo "Running migration: $file" | ||
| mysql -h 127.0.0.1 -P 3306 -u root -prootpassword diacify_db < "$file" | ||
| done | ||
|
|
||
| - name: Run tests | ||
| env: | ||
| NODE_ENV: test | ||
| TEST_DB_HOST: 127.0.0.1 | ||
| TEST_DB_PORT: 3306 | ||
| TEST_DB_USER: root | ||
| TEST_DB_PASSWORD: rootpassword | ||
| TEST_DB_NAME: diacify_db | ||
| CLERK_SECRET_KEY: ${{ secrets.CLERK_SECRET_KEY }} | ||
| ML_INTERNAL_SECRET: ${{ secrets.ML_INTERNAL_SECRET }} | ||
| ML_SERVICE_URL: http://localhost:8001 | ||
| run: npm test | ||
| working-directory: backend | ||
|
|
||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| needs: test | ||
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | ||
| steps: | ||
| - name: Trigger backend redeploy | ||
| run: curl --fail -X POST "${{ secrets.RENDER_BACKEND_HOOK }}" | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| name: Frontend CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - 'frontend/**' | ||
| - '.github/workflows/frontend-ci.yml' | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - 'frontend/**' | ||
| - '.github/workflows/frontend-ci.yml' | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
|
deshanekanayaka marked this conversation as resolved.
|
||
| - name: Setup Node.js 20 | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
| cache-dependency-path: 'frontend/package-lock.json' | ||
|
deshanekanayaka marked this conversation as resolved.
|
||
|
|
||
| - name: Install frontend dependencies | ||
| run: npm ci | ||
| working-directory: frontend | ||
|
|
||
| - name: Run linter | ||
| run: npm run lint | ||
| working-directory: frontend | ||
|
|
||
| - name: Build frontend | ||
| run: npm run build | ||
| working-directory: frontend | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| name: ML CI | ||
|
deshanekanayaka marked this conversation as resolved.
|
||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - 'machine-learning/**' | ||
| - 'docker-compose.yml' | ||
| - '.github/workflows/ml-ci.yml' | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - 'machine-learning/**' | ||
| - 'docker-compose.yml' | ||
| - '.github/workflows/ml-ci.yml' | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Python 3.11 | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
| cache: 'pip' | ||
| cache-dependency-path: 'machine-learning/requirements.txt' | ||
|
|
||
| - name: Install dependencies | ||
| run: pip install -r requirements.txt | ||
| working-directory: machine-learning | ||
|
|
||
| - name: Train model for tests | ||
| working-directory: machine-learning | ||
| run: python train_model.py | ||
|
|
||
| - name: Run pytest | ||
| env: | ||
| ML_INTERNAL_SECRET: ${{ secrets.ML_INTERNAL_SECRET || 'test_secret' }} | ||
| run: pytest tests/ -v | ||
|
deshanekanayaka marked this conversation as resolved.
|
||
| working-directory: machine-learning | ||
|
|
||
| - name: Build Docker image for validation | ||
| run: docker build -t diacify-ml:ci . | ||
| working-directory: machine-learning | ||
|
|
||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| needs: test | ||
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup 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.GHCR_TOKEN }} | ||
|
|
||
| - name: Build and push Docker image | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: machine-learning | ||
| push: true | ||
| tags: ghcr.io/${{ github.repository_owner }}/diacify-ml:${{ github.sha }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
|
|
||
| - name: Trigger ML service redeploy | ||
| run: curl --fail -X POST "${{ secrets.ML_DEPLOY_HOOK }}" | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.