Skip to content
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

fix(nodejs) : Fixed nodejs deployer scripts #1161

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions test/deploy/linux/docker/install/roles/prepare/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,39 @@

when: ansible_pkg_mgr == 'apt'
become: yes

########################################
# Amazon Linux 2023 support for Docker installation
########################################
- block:
# Update the system packages
- name: Update all system packages
dnf:
name: "*"
state: latest

# Install Docker
- name: Install Docker
dnf:
name: docker
state: present

# Start and enable Docker service
- name: Start and enable Docker service
systemd:
name: docker
state: started
enabled: yes

# Add the ec2-user to the docker group
- name: Add ec2-user to the docker group
user:
name: ec2-user
groups: docker
append: yes

- debug:
msg: "Docker installation completed successfully."

when: ansible_distribution == 'Amazon' and ansible_distribution_version == '2023'
become: yes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- 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

#copy Docker file to remote
- name: Copy node application to remote
ansible.builtin.copy:
src: ../../../../templates/Dockerfile
dest: /home/ec2-user/myNodeApp/Dockerfile
mode: '0777'
become: true
92 changes: 45 additions & 47 deletions test/deploy/linux/nodejs/redhat/roles/configure/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,51 @@
---
- debug:
msg: Install Nodejs and docker

- name: update yum packages
shell: yum update -y
msg: Install Node.js and setup Node.js application

#copy node appllication to remote
- name: Copy node application to remote
ansible.builtin.copy:
src: ../../../../templates/myNodeApp
dest: /home/ec2-user
mode: '0777'
become: true

- name: install docker
shell: yum install docker
# 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: Install Node.js
become: yes
yum:
name: nodejs
state: present

- name: Verify Node.js installation
command: node -v
register: node_version
become_user: "{{ ansible_user }}"

- name: Print Node.js version
debug:
msg: "Node.js version installed: {{ node_version.stdout }}"

# Ensure the correct permissions for the myNodeApp directory
- name: Ensure the correct permissions for the myNodeApp directory
file:
path: /home/ec2-user/myNodeApp
state: directory
owner: ec2-user
group: ec2-user
mode: '0755'
become: true

- name: RHEL - Start docker service
shell: "service docker start"

# - name: RHEL - Granting permissions to docker from ec2-user
# shell: "usermod -a -G docker ec2-user"

# - name: Install Node.js
# shell: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# become: true

# - name: load nvm
# shell: source ~/.bashrc

# - name: install node.js 20.5.1
# shell: nvm install 20.5.1

# - name: set node.js version 20.5.1 as default
# shell: nvm alias default 20.5.1

# - name: Create node.js app directory
# file:
# path: /home/ec2-user/myNodeApp
# state: directory

# - name: Copy files to myNodeApp directory
# synchronize:
# src: "{{ item }}"
# dest: /home/ec2-user/myNodeApp
# mode: push
# with_fileglob:
# - "../../../../templates/*"
# become: true

# - 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 }}"
23 changes: 15 additions & 8 deletions test/deploy/linux/nodejs/templates/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
# Dockerfile

FROM node
#base image
FROM node:18

# Create app directory
WORKDIR /usr/src/app
WORKDIR /app

# Install app dependencies
COPY package*.json ./
RUN npm install
COPY . /app

# Bundle app source
COPY . .
RUN npm install

# Expose the port the app runs on
EXPOSE 3030
EXPOSE 3000

# Command to run the application
CMD [ "node", "index.js" ]
CMD ["node", "app.js"]








18 changes: 0 additions & 18 deletions test/deploy/linux/nodejs/templates/index.js

This file was deleted.

1 change: 1 addition & 0 deletions test/deploy/linux/nodejs/templates/myNodeApp/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello, World!');
12 changes: 12 additions & 0 deletions test/deploy/linux/nodejs/templates/myNodeApp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"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"
}
}
17 changes: 11 additions & 6 deletions test/manual/definitions/apm/node/node-js-docker.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@
"provider": "aws",
"type": "ec2",
"size": "t2.medium",
"ami_name": "amzn2-ami-hvm-2.0.????????.?-x86_64-gp2",
"ami_name": "al2023-ami-2023.?.????????.?-kernel-?.?-x86_64",
"user_name": "ec2-user"
}
],
"services": [
{
"id": "docker",
"source_repository": "https://github.com/newrelic/open-install-library.git",
"deploy_script_path": "test/deploy/linux/docker/install/roles",
"port": 9999,
"destinations": ["node-js-docker"]
},
{
"id": "nodejs",
"source_repository": "https://github.com/newrelic/open-install-library.git",
"deploy_script_path": "test/deploy/linux/nodejs/redhat/roles",
"port": 8080,
"destinations": [
"node-js-docker"
]
"deploy_script_path": "test/deploy/linux/nodejs/docker-flow/roles",
"port": 80,
"destinations": ["node-js-docker"]
}
]
}
52 changes: 20 additions & 32 deletions test/manual/definitions/apm/node/node-linux2.json
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.?.????????.?-kernel-?.?-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"]
}
]
}
}
Loading