diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f0545784..cbdcc7db 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,20 +1,29 @@ -name: CICD +name: CICD-PIPELINE on: push: - branches: [main,master] - + branches: [cicd-docker-ec2] + jobs: build: runs-on: [ubuntu-latest] steps: - - name: Checkout Source + - name: Checkout source uses: actions/checkout@v3 - - name: Set Node.js 16.x - uses: actions/setup-node@v3 - with: - node-version: 16.x - - name: Install Dependencies - run : npm install - - name: Test Project - run: npm test + - name: Login to docker hub + run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + - name: Build docker image + run: docker build -t integrationninjas/nodejs-app . + - name: Publish image to docker hub + run: docker push integrationninjas/nodejs-app:latest + + deploy: + needs: build + runs-on: [runner-ec2] + steps: + - name: Pull image from docker hub + run: docker pull integrationninjas/nodejs-app:latest + - name: Delete old container + run: docker rm -f nodejs-app-container + - name: Run docker container + run: docker run -d -p 5000:5000 --name nodejs-app-container integrationninjas/nodejs-app diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..7bc65fd9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM node:16.20.1 +WORKDIR /app +COPY package.json ./ +RUN npm install +COPY . . +EXPOSE 5000 +CMD ["npm","run","start"] diff --git a/README.md b/README.md index 00aeaf62..125ba7ed 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Nodejs app with rest and graphql example -An example of GraphQL queries/mutations with Node and Express js. +An example of GraphQL queries/mutations with Node and Expressjs With GraphQL, clients can specify exactly what data they need, and the server responds with only that data, reducing the amount of data transferred over the network.