diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 58c79cde54..0000000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Publish Docker image - -on: - push: - branches: ['master'] - -jobs: - push_to_registry: - name: Push Docker image to Docker Hub - runs-on: ubuntu-latest - steps: - - name: Check out the repo - uses: actions/checkout@v3 - - - name: Log in to Docker Hub - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 - with: - images: thetips4you/testjodejsapp - - - name: Build and push Docker image - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 0000000000..591d4a4d4d --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,58 @@ +# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs + +name: Node.js CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + deploy: + + runs-on: self-hosted + + strategy: + matrix: + node-version: [14.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - run: npm ci + - run: npm run build --if-present + - run: npm install + + - name: install the gcloud cli + uses: google-github-actions/setup-gcloud@v0.2.0 + with: + project_id: ${{ secrets.GOOGLE_PROJECT }} + service_account_key: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} + install_components: 'gke-gcloud-auth-plugin' + export_default_credentials: true + + - name: build and push the docker image + env: + GOOGLE_PROJECT: ${{ secrets.GOOGLE_PROJECT }} + run: | + gcloud auth configure-docker us-central1-docker.pkg.dev + docker build -t us-central1-docker.pkg.dev/goldengate-1/test-project/node:latest . + docker push us-central1-docker.pkg.dev/goldengate-1/test-project/node:latest + - name: deploy to gke + env: + GOOGLE_PROJECT: ${{ secrets.GOOGLE_PROJECT }} + run: | + gcloud container clusters get-credentials test-cluster --region asia-south1-c + sed -i "s/GOOGLE_PROJECT/$GOOGLE_PROJECT/g" deployment.yaml + sed -i "s/GOOGLE_PROJECT/$GOOGLE_PROJECT/g" service.yaml + kubectl delete -f deployment.yaml + kubectl apply -f deployment.yaml + kubectl apply -f service.yaml + diff --git a/README.md b/README.md new file mode 100644 index 0000000000..6d26216298 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Node.js Application diff --git a/deployment.yml b/deployment.yaml similarity index 80% rename from deployment.yml rename to deployment.yaml index 8468bbd661..00ed737ef7 100644 --- a/deployment.yml +++ b/deployment.yaml @@ -16,6 +16,6 @@ spec: spec: containers: - name: nodeserver - image: thetips4you/nodeapp:latest + image: us-central1-docker.pkg.dev/goldengate-1/test-project/node:latest ports: - containerPort: 3000 diff --git a/deploymentservice.yml b/deploymentservice.yml deleted file mode 100644 index ab6f0b707d..0000000000 --- a/deploymentservice.yml +++ /dev/null @@ -1,38 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: nodeapp-deployment - labels: - app: nodeapp -spec: - replicas: 1 - selector: - matchLabels: - app: nodeapp - template: - metadata: - labels: - app: nodeapp - spec: - containers: - - name: nodeserver - image: thetips4you/nodeapp:latest - ports: - - containerPort: 3000 - - ---- - -apiVersion: v1 -kind: Service -metadata: - name: nodeapp-service -spec: - selector: - app: nodeapp - type: LoadBalancer - ports: - - protocol: TCP - port: 5000 - targetPort: 3000 - nodePort: 31110 diff --git a/index.js b/index.js index 668a9f8ed6..847dee8655 100644 --- a/index.js +++ b/index.js @@ -2,11 +2,11 @@ var express = require('express'); var app = express(); app.get('/', function (req, res) { - res.send('{ "response": "Hello From Thetips4you" }'); + res.send('{ "response": "Welcome to Inno-demoproject " }'); }); app.get('/will', function (req, res) { - res.send('{ "response": "Hello World" }'); + res.send('{ "response": "Welcome" }'); }); app.get('/ready', function (req, res) { res.send('{ "response": " Great!, It works!" }'); diff --git a/service.yml b/service.yaml similarity index 81% rename from service.yml rename to service.yaml index 1a0ab51485..d26c2b0f39 100644 --- a/service.yml +++ b/service.yaml @@ -1,3 +1,4 @@ +--- apiVersion: v1 kind: Service metadata: @@ -8,6 +9,6 @@ spec: type: LoadBalancer ports: - protocol: TCP - port: 5000 + port: 8000 targetPort: 3000 - nodePort: 31110 + nodePort: 31000 diff --git a/test/test.js b/test/test.js index 2794ef1f03..bf4f29c332 100644 --- a/test/test.js +++ b/test/test.js @@ -1,7 +1,7 @@ var request = require('supertest'); var app = require('../index.js'); describe('GET /will', function() { - it('respond with hello world', function(done) { - request(app).get('/will').expect('{ "response": "Hello World" }', done); + it('respond with Welcome', function(done) { + request(app).get('/will').expect('{ "response": "Welcome" }', done); }); -}); \ No newline at end of file +});