mode 5 gke-gcloud-auth-plugin_v2 #15
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@v4 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
build: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- 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: Configure Docker | |
run: | | |
gcloud auth configure-docker ${{ secrets.GCP_REGION }}-docker.pkg.dev | |
- name: Build and Push Docker Image | |
run: | | |
docker build -t europe-west12-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/telegram-bot/telegram-bot-service:${{ github.sha }} ./telegram_bot_service | |
gcloud auth configure-docker europe-west12-docker.pkg.dev | |
docker push europe-west12-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/telegram-bot/telegram-bot-service:${{ github.sha }} | |
- name: Check kubectl | |
run: | | |
which kubectl | |
kubectl version --client | |
- name: Install gke-gcloud-auth-plugin | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y apt-transport-https ca-certificates gnupg | |
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list | |
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - | |
sudo apt-get update && sudo apt-get install -y google-cloud-sdk-gke-gcloud-auth-plugin | |
- name: Deploy to GKE | |
env: | |
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} | |
GITHUB_SHA: ${{ github.sha }} | |
run: | | |
gcloud container clusters get-credentials ${{ secrets.GKE_CLUSTER }} --region ${{ secrets.GKE_ZONE }} | |
sed -i "s/\${PROJECT_ID}/$PROJECT_ID/g" k8s/telegram-bot/deployment.yaml | |
sed -i "s/\${GITHUB_SHA}/$GITHUB_SHA/g" k8s/telegram-bot/deployment.yaml | |
kubectl apply -f k8s/telegram-bot/ | |
kubectl apply -f k8s/translation-service/ | |
kubectl apply -f k8s/transport-service/ |