From afdfed032ce47c675bd5274e902c59b2ee245046 Mon Sep 17 00:00:00 2001 From: Luxshan2000 Date: Fri, 29 Sep 2023 02:49:07 +0530 Subject: [PATCH] workflow editted --- .github/workflows/backend.yml | 32 ------------------- .github/workflows/frontend.yml | 34 -------------------- .github/workflows/workflow.yml | 57 ++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 66 deletions(-) delete mode 100644 .github/workflows/backend.yml delete mode 100644 .github/workflows/frontend.yml create mode 100644 .github/workflows/workflow.yml diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml deleted file mode 100644 index 426b95e..0000000 --- a/.github/workflows/backend.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: CICD Backend - -on: - push: - branches: [main] - -jobs: - build: - runs-on: [ubuntu-latest] - steps: - - name: Checkout source - uses: actions/checkout@v3 - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build docker image - run: docker build -t luxshan/aws-pipeline/backend ./backend - - name: Publish image to docker hub - run: docker push luxshan/aws-pipeline/backend:latest - - deploy: - needs: build - runs-on: [aws-ec2] - steps: - - name: Pull image from docker hub - run: docker pull luxshan/aws-pipeline/backend:latest - - name: Delete old container - run: docker rm -f aws-pipeline-backend-container - - name: Run docker container - run: docker run -d -p 3000:3000 --name aws-pipeline-backend-container luxshan/aws-pipeline/backend diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml deleted file mode 100644 index 8a5c04a..0000000 --- a/.github/workflows/frontend.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: CICD Frontend - -on: - push: - branches: [main] - -jobs: - build: - runs-on: [ubuntu-latest] - steps: - - name: Checkout source - uses: actions/checkout@v3 - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build docker image - run: docker build -t luxshan/aws-pipeline/frontend ./frontend - - name: Publish image to docker hub - run: docker push luxshan/aws-pipeline/frontend - - - - deploy: - needs: build - runs-on: [aws-ec2] - steps: - - name: Pull image from docker hub - run: docker pull luxshan/aws-pipeline/frontend:latest - - name: Delete old container - run: docker rm -f aws-pipeline-frontend-container - - name: Run docker container - run: docker run -d -p 3000:3000 --name aws-pipeline-frontend-container luxshan/aws-pipeline/frontend diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 0000000..6ac712f --- /dev/null +++ b/.github/workflows/workflow.yml @@ -0,0 +1,57 @@ +name: CICD + +on: + push: + branches: + - main + +jobs: + build-frontend: + runs-on: ubuntu-latest + steps: + - name: Checkout source + uses: actions/checkout@v2 + + - name: Build and push frontend Docker image + run: | + cd frontend + docker build -t luxshan/frontend:latest . + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker push luxshan/frontend:latest + + build-backend: + runs-on: ubuntu-latest + steps: + - name: Checkout source + uses: actions/checkout@v2 + + - name: Build and push backend Docker image + run: | + cd backend + docker build -t luxshan/backend:latest . + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker push luxshan/backend:latest + + deploy: + needs: [build-frontend, build-backend] + runs-on: self-hosted + steps: + - name: Pull frontend and backend images from Docker Hub + run: | + docker pull luxshan/frontend:latest + docker pull luxshan/backend:latest + + - name: Stop and remove old containers + run: | + docker stop frontend-container || true + docker rm frontend-container || true + docker stop backend-container || true + docker rm backend-container || true + + - name: Run frontend container + run: | + docker run -d -p 3000:3000 --name frontend-container luxshan/frontend:latest + + - name: Run backend container + run: | + docker run -d -p 5000:5000 --name backend-container luxshan/backend:latest