Update CI/CD workflows with Google Auth and latest actions #5
This file contains 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: CI/CD Pipeline | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.9' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
pip install pytest pytest-cov | |
- name: Run tests | |
run: | | |
pytest --cov=./ --cov-report=xml | |
- name: Upload coverage | |
uses: codecov/codecov-action@v3 # Обновлена версия | |
build: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
# Аутентификация в Google Cloud | |
- name: Google Auth | |
id: auth | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} | |
- name: Set up Cloud SDK | |
uses: google-github-actions/setup-gcloud@v2 | |
- name: Build and push Docker images | |
run: | | |
gcloud auth configure-docker | |
docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/telegram-bot:${{ github.sha }} ./telegram_bot_service | |
docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/translation-service:${{ github.sha }} ./translation_service | |
docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/transport-service:${{ github.sha }} ./transport_service | |
docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/telegram-bot:${{ github.sha }} | |
docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/translation-service:${{ github.sha }} | |
docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/transport-service:${{ github.sha }} | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
# Аутентификация в Google Cloud | |
- name: Google Auth | |
id: auth | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} | |
- name: Set up Cloud SDK | |
uses: google-github-actions/setup-gcloud@v2 | |
- name: Deploy to GKE | |
run: | | |
gcloud container clusters get-credentials ${{ secrets.GKE_CLUSTER }} --zone ${{ secrets.GKE_ZONE }} | |
kubectl apply -f k8s/ |