File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Build and Deploy to ECR
2+
3+ on :
4+ push :
5+ branches : ["main"]
6+ pull_request :
7+ branches : ["main"]
8+
9+ env :
10+ AWS_REGION : us-east-2 # Set this to your desired region
11+ ECR_REPOSITORY : syntaxmakers1 # Set this to your repository name
12+ IMAGE_TAG : ${{ github.sha }} # Using commit SHA as image tag
13+
14+ permissions :
15+ contents : read
16+
17+ jobs :
18+ build-release :
19+ name : Build and Release to ECR
20+ runs-on : self-hosted
21+
22+ steps :
23+ - name : Checkout code
24+ uses : actions/checkout@v3
25+
26+ - name : Configure AWS credentials
27+ uses : aws-actions/configure-aws-credentials@v1
28+ with :
29+ aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
30+ aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
31+ aws-region : ${{ env.AWS_REGION }}
32+
33+ - name : Login to Amazon ECR
34+ id : login-ecr
35+ uses : aws-actions/amazon-ecr-login@v1
36+
37+ - name : Build, tag, and push image to Amazon ECR
38+ env :
39+ ECR_REGISTRY : ${{ steps.login-ecr.outputs.registry }}
40+ run : |
41+ # Build the Docker image
42+ docker build --platform linux/amd64 -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
43+ docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
44+
45+ # Push the Docker image
46+ docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
47+ docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
You can’t perform that action at this time.
0 commit comments