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@v3
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@v3
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+
66+ Continuous-Deployment :
67+ needs : build-and-push-ecr-image
68+ runs-on : self-hosted
69+ steps :
70+ - name : Checkout
71+ uses : actions/checkout@v3
72+
73+ - name : Configure AWS credentials
74+ uses : aws-actions/configure-aws-credentials@v1
75+ with :
76+ aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
77+ aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
78+ aws-region : ${{ secrets.AWS_REGION }}
79+
80+ - name : Login to Amazon ECR
81+ id : login-ecr
82+ uses : aws-actions/amazon-ecr-login@v1
83+
84+
85+ - name : Pull latest images
86+ run : |
87+ docker pull ${{secrets.AWS_ECR_LOGIN_URI}}/${{ secrets.ECR_REPOSITORY_NAME }}:latest
88+
89+ # - name: Stop and remove container if running
90+ # run: |
91+ # docker ps -q --filter "name=mltest" | grep -q . && docker stop mltest && docker rm -fv mltest
92+
93+ - name : Run Docker Image to serve users
94+ run : |
95+ docker run -d -p 8080:8080 --ipc="host" --name=mltest -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
96+ - name : Clean previous images and containers
97+ run : |
98+ docker system prune -f
0 commit comments