1+ name : workflow
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ paths-ignore :
8+ - ' README.md'
9+
10+ permissions :
11+ id-token : write
12+ contents : read
13+
14+ jobs :
15+ integration :
16+ name : Continuous Integration
17+ runs-on : ubuntu-latest
18+ steps :
19+ - name : Checkout Code
20+ uses : actions/checkout@v5
21+
22+ - name : Lint code
23+ run : echo "Linting repository"
24+
25+ - name : Run unit tests
26+ run : echo "Running unit tests"
27+
28+ build-and-push-ecr-image :
29+ name : Continuous Delivery
30+ needs : integration
31+ runs-on : ubuntu-latest
32+ steps :
33+ - name : Checkout Code
34+ uses : actions/checkout@v5
35+
36+ - name : Install Utilities
37+ run : |
38+ sudo apt-get update
39+ sudo apt-get install -y jq unzip
40+ - name : Configure AWS credentials
41+ uses : aws-actions/configure-aws-credentials@v1
42+ with :
43+ aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
44+ aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
45+ aws-region : ${{ secrets.AWS_REGION }}
46+
47+ - name : Login to Amazon ECR
48+ id : login-ecr
49+ uses : aws-actions/amazon-ecr-login@v1
50+
51+ - name : Build, tag, and push image to Amazon ECR
52+ id : build-image
53+ env :
54+ ECR_REGISTRY : ${{ steps.login-ecr.outputs.registry }}
55+ ECR_REPOSITORY : ${{ secrets.ECR_REPOSITORY_NAME }}
56+ IMAGE_TAG : latest
57+ run : |
58+ # Build a docker container and
59+ # push it to ECR so that it can
60+ # be deployed to ECS.
61+ docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
62+ docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
63+ echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
64+
65+ Continuous-Deployment :
66+ needs : build-and-push-ecr-image
67+ runs-on : self-hosted
68+ steps :
69+ - name : Checkout
70+ uses : actions/checkout@v5
71+
72+ - name : Configure AWS credentials
73+ uses : aws-actions/configure-aws-credentials@v1
74+ with :
75+ aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
76+ aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
77+ aws-region : ${{ secrets.AWS_REGION }}
78+
79+ - name : Login to Amazon ECR
80+ id : login-ecr
81+ uses : aws-actions/amazon-ecr-login@v1
82+
83+ - name : Pull latest images
84+ run : |
85+ docker pull ${{secrets.AWS_ECR_LOGIN_URI}}/${{ secrets.ECR_REPOSITORY_NAME }}:latest
86+
87+ - name : Run Docker Image to serve users
88+ run : |
89+ docker run -d -p 8080:8080 --ipc="host" --name=networksecurity -e 'AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}' -e 'AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}' -e 'AWS_REGION=${{ secrets.AWS_REGION }}' ${{secrets.AWS_ECR_LOGIN_URI}}/${{ secrets.ECR_REPOSITORY_NAME }}:latest
90+ - name : Clean previous images and containers
91+ run : |
92+ docker system prune -f
0 commit comments