Skip to content

Organize

Organize #56

Workflow file for this run

name: Pipline
on:
push:
branches:
- main
env:
PROJECT_ID: named-signal-392608
BUCKET_NAME: gha-chart-packages
HELM_PACKAGE: nasa-app-1.${{ github.run_number }}.0.tgz
TAG: v1.${{ github.run_number }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Create Docker Env
run: |
echo "API_KEY=${{ secrets.API_KEY }}" > ./NASA/.env
- name: Build and Push Docker Image
uses: docker/build-push-action@v2
with:
context: ./NASA
file: ./NASA/Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/gha-pipeline:${{ env.TAG }}
- name: Create Helm Chart files
run: |
echo "apiVersion: v2" > ./chart/Chart.yaml
echo "name: nasa-app" >> ./chart/Chart.yaml
echo "version: 1.${{ github.run_number }}.0" >> ./chart/Chart.yaml
echo "description: A Helm chart for deploying Flask and Redis" >> ./chart/Chart.yaml
echo "TAG: v1.${{ github.run_number }}" > ./chart/values.yaml
- name: Package Helm Chart
run: |
helm package ./chart -d ./chart
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v0.3.0
with:
project_id: ${{ env.PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
export_default_credentials: true
- name: Upload Helm Chart to GCP
run: |
gsutil cp ./chart/${{ env.HELM_PACKAGE }} gs://${{ env.BUCKET_NAME }}
test:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v0.3.0
with:
project_id: ${{ env.PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
export_default_credentials: true
- name: Get GKE plugin
run: |
gcloud components install gke-gcloud-auth-plugin
- name: Configure kubectl
run: |
gcloud container clusters get-credentials test-cluster --region us-central1-a
- name: Download Helm chart from GCP bucket
run: |
gsutil cp gs://${{ env.BUCKET_NAME }}/${{ env.HELM_PACKAGE }} .
- name: Deploy Helm chart
run: |
helm upgrade --install nasa-app ${{ env.HELM_PACKAGE }}
- name: Run Helm Tests
run: |
helm test nasa-app
deploy:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v0.3.0
with:
project_id: ${{ env.PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
export_default_credentials: true
- name: Get GKE plugin
run: |
gcloud components install gke-gcloud-auth-plugin
- name: Configure kubectl
run: |
gcloud container clusters get-credentials prod-cluster --region us-central1-a
- name: Download Helm chart from GCP bucket
run: |
gsutil cp gs://${{ env.BUCKET_NAME }}/${{ env.HELM_PACKAGE }} .
- name: Deploy Helm chart
run: |
helm upgrade --install nasa-app ${{ env.HELM_PACKAGE }}
monitor:
needs: deploy
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v0.3.0
with:
project_id: ${{ env.PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
export_default_credentials: true
- name: Get GKE plugin
run: |
gcloud components install gke-gcloud-auth-plugin
- name: Configure kubectl
run: |
gcloud container clusters get-credentials prod-cluster --region us-central1-a
- name: Check and Install Prometheus and Grafana
run: |
if helm list -n monitoring | grep -q "prometheus"; then
echo "Prometheus is already installed."
else
kubectl create namespace monitoring
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install prometheus prometheus-community/kube-prometheus-stack --namespace monitoring
echo "Prometheus installed."
fi