-
Notifications
You must be signed in to change notification settings - Fork 63
fix(nodejs) : Fixed nodejs deployer scripts #1161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bb2243c
fix(nodejs) : Fixed nodejs deployer scripts
rpaliwal1997 e56b736
fix(nodejs) : Fixed nodejs docker deployer scripts
rpaliwal1997 403ebf2
fix(nodejs): update docker installation steps to fix nodejs issue.
vagrawal-newrelic 49659c8
fix(nodejs): update docker ansible playbook to remove code dublication
vagrawal-newrelic 40388b0
fix(nodejs): Add node application and docker file import in ansible
vagrawal-newrelic b2b1c28
fix(nodejs): Update ami image to make it more generic
vagrawal-newrelic 6baadee
fix(nodejs): Update app.js for test
vagrawal-newrelic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
18 changes: 18 additions & 0 deletions
18
test/deploy/linux/nodejs/docker-flow/roles/configure/tasks/main.yml
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
- debug: | ||
msg: Install Node.js, Create Dockerfile, and setup Node.js application | ||
# import the nodeJs sample application tasks | ||
- import_tasks: ../../../../nodejs/redhat/roles/configure/tasks/main.yml | ||
|
||
# create a sample Dockerfile | ||
- name: Create a sample Dockerfile | ||
copy: | ||
content: | | ||
FROM node:18 | ||
WORKDIR /app | ||
COPY . /app | ||
RUN npm install | ||
EXPOSE 3000 | ||
CMD ["node", "app.js"] | ||
dest: "/home/{{ ansible_user }}/myNodeApp/Dockerfile" | ||
mode: "0644" | ||
110 changes: 71 additions & 39 deletions
110
test/deploy/linux/nodejs/redhat/roles/configure/tasks/main.yml
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,85 @@ | ||
--- | ||
- debug: | ||
msg: Install Nodejs and docker | ||
msg: Install Node.js and setup Node.js application | ||
|
||
- name: update yum packages | ||
shell: yum update -y | ||
become: true | ||
# Create myNodeApp directory | ||
- name: Create myNodeApp directory | ||
file: | ||
path: "/home/{{ ansible_user }}/myNodeApp" | ||
state: directory | ||
|
||
- name: install docker | ||
shell: yum install docker | ||
become: true | ||
# Create package.json | ||
- name: Create package.json | ||
copy: | ||
content: | | ||
{ | ||
"name": "myNodeApp", | ||
"version": "1.0.0", | ||
"description": "A sample Node.js application", | ||
"main": "app.js", | ||
"scripts": { | ||
"start": "node app.js" | ||
}, | ||
"dependencies": { | ||
"express": "^4.17.1" | ||
} | ||
} | ||
dest: "/home/{{ ansible_user }}/myNodeApp/package.json" | ||
mode: "0644" | ||
|
||
- name: RHEL - Start docker service | ||
shell: "service docker start" | ||
# Install Node.js using NodeSource | ||
- name: Install Node.js using NodeSource | ||
become: yes | ||
shell: curl -sL https://rpm.nodesource.com/setup_18.x | bash - | ||
args: | ||
executable: /bin/bash | ||
|
||
# - name: RHEL - Granting permissions to docker from ec2-user | ||
# shell: "usermod -a -G docker ec2-user" | ||
- name: Install Node.js | ||
become: yes | ||
yum: | ||
name: nodejs | ||
state: present | ||
|
||
# - name: Install Node.js | ||
# shell: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash | ||
# become: true | ||
- name: Verify Node.js installation | ||
command: node -v | ||
register: node_version | ||
become_user: "{{ ansible_user }}" | ||
|
||
# - name: load nvm | ||
# shell: source ~/.bashrc | ||
- name: Print Node.js version | ||
debug: | ||
msg: "Node.js version installed: {{ node_version.stdout }}" | ||
|
||
# - name: install node.js 20.5.1 | ||
# shell: nvm install 20.5.1 | ||
# create a node app | ||
- name: Create sample Node.js application | ||
copy: | ||
content: | | ||
const http = require('http'); | ||
|
||
# - name: set node.js version 20.5.1 as default | ||
# shell: nvm alias default 20.5.1 | ||
const hostname = '127.0.0.1'; | ||
const port = 3000; | ||
|
||
# - name: Create node.js app directory | ||
# file: | ||
# path: /home/ec2-user/myNodeApp | ||
# state: directory | ||
const server = http.createServer((req, res) => { | ||
res.statusCode = 200; | ||
res.setHeader('Content-Type', 'text/plain'); | ||
res.end('Hello, Node.js!\n'); | ||
}); | ||
|
||
# - name: Copy files to myNodeApp directory | ||
# synchronize: | ||
# src: "{{ item }}" | ||
# dest: /home/ec2-user/myNodeApp | ||
# mode: push | ||
# with_fileglob: | ||
# - "../../../../templates/*" | ||
# become: true | ||
server.listen(port, hostname, () => { | ||
console.log(`Server running at http://${hostname}:${port}/`); | ||
}); | ||
dest: "/home/{{ ansible_user }}/myNodeApp/app.js" | ||
mode: "0644" | ||
Nandu-pns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# - name: create package.json | ||
# shell: cd /home/ec2-user/myNodeApp && npm init -y | ||
# become: true | ||
|
||
# - name: install express | ||
# shell: cd /home/ec2-user/myNodeApp && npm install express | ||
# become: true | ||
# install npm dependencies | ||
- name: Install npm dependencies | ||
shell: npm install | ||
args: | ||
chdir: "/home/{{ ansible_user }}/myNodeApp" | ||
become: yes | ||
become_user: "{{ ansible_user }}" | ||
|
||
# Give all permissions to the app.js file | ||
- name: Change permissions for the app.js file | ||
file: | ||
path: "/home/{{ ansible_user }}/myNodeApp/app.js" | ||
mode: "0755" |
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,27 @@ | ||
{ | ||
"global_tags": { | ||
"owning_team": "virtuoso", | ||
"Environment": "development", | ||
"Department": "product", | ||
"Product": "virtuoso" | ||
"owning_team": "virtuoso", | ||
"Environment": "development", | ||
"Department": "product", | ||
"Product": "virtuoso" | ||
}, | ||
|
||
"resources": [ | ||
{ | ||
"id": "nodelinux2", | ||
"provider": "aws", | ||
"type": "ec2", | ||
"size": "t3.micro", | ||
"ami_name": "newrelic-install-linux-node-pm2" | ||
} | ||
{ | ||
"id": "node-js", | ||
"provider": "aws", | ||
"type": "ec2", | ||
"size": "t2.medium", | ||
"ami_name": "al2023-ami-2023.6.20250128.0-kernel-6.1-x86_64", | ||
"user_name": "ec2-user" | ||
} | ||
], | ||
|
||
"services": [ | ||
{ | ||
"id": "nodetron", | ||
"source_repository": "https://github.com/newrelic/demo-nodetron.git", | ||
"deploy_script_path": "deploy/linux/pm2/roles", | ||
"port": 5001, | ||
"destinations": ["nodelinux2"], | ||
"files": [ | ||
{ | ||
"destination_filepath": "engine/cronjob.json", | ||
"content": [ | ||
{ | ||
"frequency": "* * * * *", | ||
"job": "for ((i=1;i<=30;i++)); do curl '[service:nodetron:url]/'; curl '[service:nodetron:url]/api/inventory'; sleep 1; done" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
{ | ||
"id": "nodejs", | ||
"source_repository": "https://github.com/newrelic/open-install-library.git", | ||
"deploy_script_path": "test/deploy/linux/nodejs/redhat/roles", | ||
"port": 80, | ||
"destinations": ["node-js"] | ||
} | ||
] | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.