Merge branch 'development-v2' into production #36
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CICD | |
on: | |
push: | |
branches: [production] | |
jobs: | |
build-and-deploy: | |
runs-on: [ubuntu-latest] | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "20" # Specify your Node.js version here | |
- name: Install dependencies and run tests in item_service | |
working-directory: ./item_service | |
env: | |
NODE_ENV: test | |
MONGO_URI: ${{ secrets.MONGO_URI }} | |
run: | | |
npm install | |
npm test | |
- name: Check test results | |
if: failure() | |
run: | | |
echo "Tests failed, stopping the workflow." | |
exit 1 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v3 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
with: | |
mask-password: "true" | |
- name: Notify Build Failure | |
if: failure() && steps.build-push.conclusion == 'failure' | |
run: echo "Build or push failed, taking recovery steps or notifying stakeholders." | |
# Here, you could include a script to send notifications via Slack, email, or another service. | |
- name: Build, tag, and push image to Amazon ECR | |
id: build-image | |
continue-on-error: true | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
IMAGE_TAG: latest | |
REPOSITORY: auth_service | |
run: | | |
# Build a docker container and | |
# push it to ECR so that it can | |
# be deployed to ECS. | |
docker build -t $ECR_REGISTRY/$REPOSITORY:$IMAGE_TAG ./auth_service | |
docker push $ECR_REGISTRY/$REPOSITORY:$IMAGE_TAG | |
echo "image=$ECR_REGISTRY/$REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
- name: Build, tag, and push image to Amazon ECR | |
id: build-image2 | |
continue-on-error: true | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
IMAGE_TAG: latest | |
REPOSITORY: item_service | |
run: | | |
# Build a docker container and | |
# push it to ECR so that it can | |
# be deployed to ECS. | |
docker build -t $ECR_REGISTRY/$REPOSITORY:$IMAGE_TAG ./item_service | |
docker push $ECR_REGISTRY/$REPOSITORY:$IMAGE_TAG | |
echo "image=$ECR_REGISTRY/$REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
- name: Fill in the new image ID in the Amazon ECS task definition | |
id: task-def | |
uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
with: | |
task-definition: ecom-app-task-definition-revision.json | |
container-name: auth_service | |
image: ${{ steps.build-image.outputs.image }} | |
- name: Fill in the new image ID in the Amazon ECS task definition | |
id: task-def1 | |
uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
with: | |
task-definition: ecom-app-task-definition-revision.json | |
container-name: item_service | |
image: ${{ steps.build-image.outputs.image }} | |
- name: Deploy Amazon ECS task definition | |
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | |
with: | |
task-definition: ${{ steps.task-def.outputs.task-definition }} | |
service: ecom-app-service | |
cluster: DevCluster | |
wait-for-service-stability: true |