Skip to content

Merge branch 'master' of https://github.com/srijan-shukla/flask-calcu… #8

Merge branch 'master' of https://github.com/srijan-shukla/flask-calcu…

Merge branch 'master' of https://github.com/srijan-shukla/flask-calcu… #8

# Name of the workflow
name: Python application build-push-deploy
# This workflow gets triggered on push events to the master branch
on:
push:
branches: [ master ]
# Environment variables accessible to all jobs
env:
ENVIRONMENT: staging
# Jobs to be run
jobs:
# Test job
test:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
<<<<<<< HEAD

Check failure on line 22 in .github/workflows/build-push-deploy.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/build-push-deploy.yml

Invalid workflow file

You have an error in your yaml syntax on line 22
<<<<<<< HEAD
- uses: actions/checkout@v2 # Checks-out your repository under $GITHUB_WORKSPACE
- name: Set up Python 3.9.6
=======
=======
>>>>>>> 1bd25ca33fe3259cfd1c406344b855b0ae4d9e14
- name: Checkout code
uses: actions/checkout@v2 # Checks-out your repository under $GITHUB_WORKSPACE
- name: Set up Python 3.9
<<<<<<< HEAD
>>>>>>> 3c1aca2 (Task3: CI/CD_with_GitHub_Actions Solution: Update Python version to 3.9)
=======
>>>>>>> 1bd25ca33fe3259cfd1c406344b855b0ae4d9e14
uses: actions/setup-python@v2 # Sets up a Python environment
with:
python-version: 3.9 # Version of Python to use
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install -r requirements.txt # Install Python dependencies
- name: Test with pytest
run: |
pip3 install pytest
pytest # Run tests
# Build job
build:
needs: test # This job needs the test job to complete successfully before it will run
runs-on: ubuntu-latest
steps:
- name: Checkout code
<<<<<<< HEAD
- uses: actions/checkout@v2
=======
uses: actions/checkout@v2
>>>>>>> 1bd25ca33fe3259cfd1c406344b855b0ae4d9e14
- name: Configure AWS Credentials
uses: aws-actions/[email protected] # Configure AWS credentials
with:
role-to-assume: ${{ secrets.AWS_ROLE_NAME }} # Assume this AWS IAM role
role-session-name: ${{ secrets.AWS_ROLE_SESSION_NAME }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }} # Set AWS region
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1 # Sets up Docker Buildx
- name: Build Docker image
run: |
docker build -t flask-calculator-app/{{ env.ENVIRONMENT }} . # Build Docker image
- name: Tag Docker image
run: |
COMMIT_ID=$(git rev-parse --short HEAD)
docker tag flask-calculator-app/${{ env.ENVIRONMENT }}:latest ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/flask-calculator-app/${{ env.ENVIRONMENT }}:$COMMIT_ID # Tag Docker image
- name: Login to AWS ECR
run: |
aws ecr get-login-password --region ${{ secrets.AWS_DEFAULT_REGION }} | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com # Login to AWS ECR
- name: Push Docker image to AWS ECR
run: |
docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/flask-calculator-app/${{ env.ENVIRONMENT }}:$COMMIT_ID # Push Docker image to AWS ECR
# Deploy job
deploy:
needs: build # This job needs the build job to complete successfully before it will run
runs-on: ubuntu-latest
steps:
- name : Checkout code
uses: actions/checkout@v2
- name: Install Helm
run: |
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh # Install Helm
- name: Update kubeconfig
run: aws eks --region ${{ secrets.AWS_DEFAULT_REGION }} update-kubeconfig --name prod-fca # Update kubeconfig for EKS cluster
- name: Deploy to Kubernetes # Deploy Helm chart to Kubernetes
run: |
helm upgrade --install flask-calculator-app helm-charts/flask-calculator-app -f helm-values/flask-calculator-app/values-flask-calculator-app.yaml --namespace ${{ env.ENVIRONMENT }} --set image.repository=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_DEFAULT_REGION }}.amazonaws.com/flask-calculator-app/${{ env.ENVIRONMENT }} --set image.tag=$COMMIT_ID --set CertificateArn=${{ secrets.CertificateArn }} --set SecurityGroupID=${{ secrets.SecurityGroupID }}