Skip to content

Commit 14b9f39

Browse files
Update build.yml
1 parent 3d33a4b commit 14b9f39

File tree

1 file changed

+9
-41
lines changed

1 file changed

+9
-41
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,78 +5,46 @@ on: [push]
55
jobs:
66
build-and-test:
77
runs-on: ubuntu-latest
8-
98
steps:
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
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
2918
3019
deploy_to_production:
3120
runs-on: ubuntu-latest
3221
needs: [build-and-test]
3322
steps:
3423
- uses: actions/checkout@v2
35-
3624
- name: Configure AWS Credentials
3725
run: |
3826
echo "${{ secrets.AWS_ACCESS_KEY_ID }}" > aws_access_key_id
3927
echo "${{ secrets.AWS_SECRET_ACCESS_KEY }}" > aws_secret_access_key
40-
4128
- name: Set AWS Region
4229
run: |
4330
echo "AWS_REGION=us-east-1" >> $GITHUB_ENV # Replace with your AWS region
44-
4531
- name: Deploy to EKS
4632
run: |
47-
# Install kubectl
4833
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
4934
chmod +x ./kubectl
5035
sudo mv ./kubectl /usr/local/bin/kubectl
51-
52-
# Install awscli
5336
pip install awscli --upgrade
5437
aws --version
55-
56-
# Configure AWS CLI with your credentials
5738
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
5839
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
5940
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${{ secrets.IMAGE_REGISTRY }}
6041
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
7242
LATEST_SHA=$(git rev-parse HEAD)
7343
docker build -t ${{ secrets.REPOSITORY }}:$LATEST_SHA .
7444
docker tag ${{ secrets.REPOSITORY }}:$LATEST_SHA ${{ secrets.IMAGE_REGISTRY }}:$LATEST_SHA
7545
docker push ${{ secrets.IMAGE_REGISTRY }}:$LATEST_SHA
76-
7746
docker tag ${{ secrets.REPOSITORY }}:$LATEST_SHA ${{ secrets.IMAGE_REGISTRY }}:latest
7847
docker push ${{ secrets.IMAGE_REGISTRY }}:latest
79-
8048
# Check if the deployment exists
8149
DEPLOYMENT_EXISTS=$(kubectl get deployment ${{ secrets.REPOSITORY }} -n default --ignore-not-found)
8250
if [ -z "$DEPLOYMENT_EXISTS" ]; then

0 commit comments

Comments
 (0)