-
Notifications
You must be signed in to change notification settings - Fork 8
Optimize docker builds and auto-deploy #103
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,8 +112,10 @@ jobs: | |
| tags: | | ||
| ${{ secrets.DOCKER_REGISTRY_URL }}/stars-backend:${{ needs.check_version_update.outputs.backend_version }} | ||
| ${{ secrets.DOCKER_REGISTRY_URL }}/stars-backend:latest | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
| cache-from: type=registry,ref=${{ secrets.DOCKER_REGISTRY_URL }}/stars-backend:cache | ||
| cache-to: type=registry,ref=${{ secrets.DOCKER_REGISTRY_URL }}/stars-backend:cache,mode=max | ||
| # Use docker registry cache not to exceed GitHub Actions storage limits | ||
| # Builds will be slower but won't fail due to storage limits | ||
|
|
||
| - name: Backend Build Summary | ||
| run: | | ||
|
|
@@ -203,3 +205,51 @@ jobs: | |
| echo "⏭️ (SKIP) Frontend: No version change detected" | ||
| fi | ||
| echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" | ||
|
|
||
| deploy-backend: | ||
| name: Restart Backend Deployment | ||
| if: github.event.pull_request.merged && needs.build-backend.result == 'success' | ||
| needs: [check_version_update, build-backend] | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Set up kubectl | ||
| uses: azure/setup-kubectl@v3 | ||
| with: | ||
| version: 'latest' | ||
|
marcorosa marked this conversation as resolved.
|
||
|
|
||
| - name: Configure kubectl for SAP BTP Kyma | ||
| run: | | ||
| mkdir -p ~/.kube | ||
| echo "${{ secrets.KUBECONFIG }}" | base64 -d > ~/.kube/config | ||
| chmod 600 ~/.kube/config | ||
|
Comment on lines
+220
to
+224
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The kubectl configuration step has potential security improvements. Consider using a temporary file with proper cleanup and more restrictive permissions. - name: Configure kubectl for SAP BTP Kyma
run: |
KUBECONFIG_FILE=$(mktemp)
echo "${{ secrets.KUBECONFIG }}" | base64 -d > "$KUBECONFIG_FILE"
chmod 400 "$KUBECONFIG_FILE"
export KUBECONFIG="$KUBECONFIG_FILE"
# Your kubectl commands here
rm -f "$KUBECONFIG_FILE" |
||
|
|
||
| - name: Restart Backend Deployment | ||
| run: | | ||
| echo "🔄 Restarting backend deployment to pull latest image..." | ||
| kubectl rollout restart deployment/stars-backend -n stars | ||
| kubectl rollout status deployment/stars-backend -n stars --timeout=10m | ||
| echo "✅ Backend deployment restarted successfully" | ||
|
|
||
| deploy-frontend: | ||
| name: Restart Frontend Deployment | ||
| if: github.event.pull_request.merged && needs.build-frontend.result == 'success' | ||
| needs: [check_version_update, build-frontend] | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Set up kubectl | ||
| uses: azure/setup-kubectl@v3 | ||
| with: | ||
| version: 'latest' | ||
|
|
||
| - name: Configure kubectl for SAP BTP Kyma | ||
| run: | | ||
| mkdir -p ~/.kube | ||
| echo "${{ secrets.KUBECONFIG }}" | base64 -d > ~/.kube/config | ||
| chmod 600 ~/.kube/config | ||
|
|
||
| - name: Restart Frontend Deployment | ||
| run: | | ||
| echo "🔄 Restarting frontend deployment to pull latest image..." | ||
| kubectl rollout restart deployment/stars-frontend -n stars | ||
| kubectl rollout status deployment/stars-frontend -n stars --timeout=10m | ||
| echo "✅ Frontend deployment restarted successfully" | ||
|
Comment on lines
+209
to
+255
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The deployment jobs have significant code duplication. Consider extracting the common kubectl configuration into a reusable composite action or using a matrix strategy to reduce maintenance overhead. deploy:
name: Restart Deployments
if: github.event.pull_request.merged && (needs.build-backend.result == 'success' || needs.build-frontend.result == 'success')
needs: [check_version_update, build-backend, build-frontend]
runs-on: ubuntu-latest
strategy:
matrix:
service:
- { name: backend, condition: "needs.build-backend.result == 'success'" }
- { name: frontend, condition: "needs.build-frontend.result == 'success'" }
steps:
- name: Set up kubectl
uses: azure/setup-kubectl@v3
with:
version: 'latest'
- name: Configure kubectl for SAP BTP Kyma
run: |
mkdir -p ~/.kube
echo "${{ secrets.KUBECONFIG }}" | base64 -d > ~/.kube/config
chmod 600 ~/.kube/config
- name: Restart ${{ matrix.service.name }} Deployment
if: ${{ matrix.service.condition }}
run: |
echo "🔄 Restarting ${{ matrix.service.name }} deployment to pull latest image..."
kubectl rollout restart deployment/stars-${{ matrix.service.name }} -n stars
kubectl rollout status deployment/stars-${{ matrix.service.name }} -n stars --timeout=10m
echo "✅ ${{ matrix.service.name }} deployment restarted successfully" |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| # Caches | ||
| **/__pycache__ | ||
| cache | ||
| **/.cache | ||
| **/.mypy_cache | ||
|
|
||
| # Libraries | ||
| venv* | ||
|
|
@@ -13,10 +15,28 @@ logger.log | |
| result_gptfuzz.txt | ||
| prompt_success.txt | ||
|
|
||
| # Non-relevant files and folders | ||
| README.md | ||
| *.md | ||
| docs/ | ||
| examples/ | ||
| build/ | ||
| dist/ | ||
| *.egg-info/ | ||
|
|
||
| # Sensitive data | ||
| .env | ||
| .env* | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
||
| # Development files | ||
| # Development files and folders | ||
| .vscode | ||
| .gitignore | ||
| README.md | ||
| .git | ||
| **/*.pyc | ||
| **/*.pyo | ||
| **/*.pyd | ||
| **/.pytest_cache | ||
| **/test* | ||
| **/Test* | ||
| **/.coverage | ||
| **/htmlcov | ||
| **/.tox | ||
|
Comment on lines
+35
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good improvements to the .dockerignore file! However, the test exclusion patterns might be too broad and could exclude legitimate files. Consider being more specific with test patterns. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cache configuration change from GitHub Actions cache to registry cache is good for avoiding storage limits. However, consider adding error handling and fallback mechanisms to ensure builds don't fail if the registry cache is unavailable.