Update README.md #4
This file contains hidden or 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 | |
| on: [push] | |
| jobs: | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - name: Set up Python | |
| uses: actions/setup-python@v2 | |
| with: | |
| python-version: '3.8' # You can use the version you need | |
| - name: Install Dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Run Tests | |
| run: | | |
| # If you're using pytest for tests, for example: | |
| pytest | |
| deploy_to_production: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - name: Configure AWS Credentials | |
| run: | | |
| echo "${{ secrets.AWS_ACCESS_KEY_ID }}" > aws_access_key_id | |
| echo "${{ secrets.AWS_SECRET_ACCESS_KEY }}" > aws_secret_access_key | |
| - name: Set AWS Region | |
| run: | | |
| echo "AWS_REGION=us-east-1" >> $GITHUB_ENV # Replace with your AWS region | |
| - name: Deploy to EKS | |
| run: | | |
| curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" | |
| chmod +x ./kubectl | |
| sudo mv ./kubectl /usr/local/bin/kubectl | |
| pip install awscli --upgrade | |
| aws --version | |
| aws eks update-kubeconfig --name my-cluster --region ${{ env.AWS_REGION }} | |
| LATEST_SHA=$(git rev-parse HEAD) | |
| docker build -t express-eks:$LATEST_SHA . | |
| docker tag express-eks:$LATEST_SHA ${{ secrets.IMAGE_REGISTRY }}/express-eks:$LATEST_SHA | |
| docker push ${{ secrets.IMAGE_REGISTRY }}/express-eks:$LATEST_SHA | |
| docker tag express-eks:$LATEST_SHA ${{ secrets.IMAGE_REGISTRY }}/express-eks:latest | |
| docker push ${{ secrets.IMAGE_REGISTRY }}/express-eks:latest | |
| DEPLOY_CMD="./kubectl set image deployment/myapp myapp=${{ secrets.IMAGE_REGISTRY }}/express-eks:$LATEST_SHA -n default" | |
| if [[ ${{ steps.check_deployment.outputs.deployment_exists }} == "true" ]]; then | |
| $DEPLOY_CMD | |
| else | |
| echo "Creating new deployment" | |
| kubectl create deployment myapp --image=${{ secrets.IMAGE_REGISTRY }}/express-eks:$LATEST_SHA -n default | |
| fi |