@@ -5,46 +5,78 @@ on: [push]
55jobs :
66 build-and-test :
77 runs-on : ubuntu-latest
8+
89 steps :
9- - uses : actions/checkout@v2
10- - name : Set up Python
11- uses : actions/setup-python@v2
12- with :
13- python-version : ' 3.8' # You can use the version you need
14- - name : Install Dependencies
15- run : |
16- python -m pip install --upgrade pip
17- pip install -r requirements.txt
10+ - uses : actions/checkout@v2
11+ - name : Set up Python
12+ uses : actions/setup-python@v2
13+ with :
14+ python-version : ' 3.8' # You can use the version you need
15+
16+ # Cache Python dependencies
17+ - name : Cache Python dependencies
18+ uses : actions/cache@v2
19+ with :
20+ path : ~/.cache/pip
21+ key : ${{ runner.os }}-python-${{ hashFiles('**/requirements.txt') }}
22+ restore-keys : |
23+ ${{ runner.os }}-python-
24+
25+ - name : Install Dependencies
26+ run : |
27+ python -m pip install --upgrade pip
28+ pip install -r requirements.txt
1829
1930 deploy_to_production :
2031 runs-on : ubuntu-latest
2132 needs : [build-and-test]
2233 steps :
2334 - uses : actions/checkout@v2
35+
2436 - name : Configure AWS Credentials
2537 run : |
2638 echo "${{ secrets.AWS_ACCESS_KEY_ID }}" > aws_access_key_id
2739 echo "${{ secrets.AWS_SECRET_ACCESS_KEY }}" > aws_secret_access_key
40+
2841 - name : Set AWS Region
2942 run : |
3043 echo "AWS_REGION=us-east-1" >> $GITHUB_ENV # Replace with your AWS region
44+
3145 - name : Deploy to EKS
3246 run : |
47+ # Install kubectl
3348 curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
3449 chmod +x ./kubectl
3550 sudo mv ./kubectl /usr/local/bin/kubectl
51+
52+ # Install awscli
3653 pip install awscli --upgrade
3754 aws --version
55+
56+ # Configure AWS CLI with your credentials
3857 aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
3958 aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
4059 aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${{ secrets.IMAGE_REGISTRY }}
4160 aws eks update-kubeconfig --name my-cluster --region ${{ env.AWS_REGION }}
61+
62+ # Cache Docker layers
63+ echo "Cache Docker layers"
64+ DOCKER_CACHE_DIR=/tmp/.buildx-cache
65+ mkdir -p $DOCKER_CACHE_DIR
66+
67+ # Cache Docker layers
68+ docker buildx create --use
69+ docker buildx build --cache-from type=local,src=$DOCKER_CACHE_DIR --cache-to type=local,dest=$DOCKER_CACHE_DIR,mode=max --tag ${{ secrets.IMAGE_REGISTRY }}:$LATEST_SHA .
70+
71+ # Build and tag the Docker image
4272 LATEST_SHA=$(git rev-parse HEAD)
4373 docker build -t ${{ secrets.REPOSITORY }}:$LATEST_SHA .
4474 docker tag ${{ secrets.REPOSITORY }}:$LATEST_SHA ${{ secrets.IMAGE_REGISTRY }}:$LATEST_SHA
4575 docker push ${{ secrets.IMAGE_REGISTRY }}:$LATEST_SHA
76+
4677 docker tag ${{ secrets.REPOSITORY }}:$LATEST_SHA ${{ secrets.IMAGE_REGISTRY }}:latest
4778 docker push ${{ secrets.IMAGE_REGISTRY }}:latest
79+
4880 # Check if the deployment exists
4981 DEPLOYMENT_EXISTS=$(kubectl get deployment ${{ secrets.REPOSITORY }} -n default --ignore-not-found)
5082 if [ -z "$DEPLOYMENT_EXISTS" ]; then
0 commit comments