From 75a4a63b371f08cda38f9ba7cd180ca3180c1fa5 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 3 Jan 2025 16:31:18 +0100 Subject: [PATCH 1/2] Update app.js --- app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 2aaad68..73e4031 100644 --- a/app.js +++ b/app.js @@ -3,13 +3,13 @@ const app = express(); const hostname = '127.0.0.1'; // Your server ip address const port = 3000; -const version = '3,000,000'; +const version = '2'; app.get('/', (req, res) => { // set response content res.send(` -

[Version ${version}]: THis is AMAZING!!! Like & Subscribe!

+

[Version ${version}]: Home page

From e9ab80b28961f40cf98657e022464c82cdfb8956 Mon Sep 17 00:00:00 2001 From: Manuel Date: Wed, 8 Jan 2025 16:18:20 +0100 Subject: [PATCH 2/2] update --- Dockerfile | 32 ++++++++++++++++++++++++++++++++ app.js | 4 ++-- appspec.yml | 29 ++++++++--------------------- 3 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..087aca4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# Usamos Amazon Linux 2 como base +FROM amazonlinux:2 + +# Actualizamos el sistema e instalamos dependencias necesarias +RUN yum update -y && \ + yum install -y git htop wget curl ruby tar && \ + yum clean all + +# Configuramos el directorio de NVM +ENV NVM_DIR=/root/.nvm +ENV PATH=$NVM_DIR/versions/node/v16.20.0/bin:$PATH + +# Instalamos NVM, Node.js (versión 16 LTS) y PM2 +RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash && \ + . $NVM_DIR/nvm.sh && \ + nvm install 16.20.0 && \ + nvm use 16.20.0 && \ + nvm alias default 16.20.0 && \ + npm install -g pm2 + +# Clonamos el repositorio +RUN git clone https://github.com/JaviRabago/VsNodeGrupo.git /app +WORKDIR /app + +# Instalamos las dependencias de la aplicación +RUN . $NVM_DIR/nvm.sh && npm install + +# Exponemos el puerto de la aplicación +EXPOSE 3000 + +# Ejecutamos la aplicación con PM2 +CMD ["pm2-runtime", "start", "app.js", "--name=nodejs-express-app"] diff --git a/app.js b/app.js index 73e4031..a019ae9 100644 --- a/app.js +++ b/app.js @@ -1,9 +1,9 @@ const express = require('express'); const app = express(); -const hostname = '127.0.0.1'; // Your server ip address +const hostname = '0.0.0.0'; // Your server ip address const port = 3000; -const version = '2'; +const version = '5'; app.get('/', (req, res) => { // set response content diff --git a/appspec.yml b/appspec.yml index 3e56c9c..0150e50 100644 --- a/appspec.yml +++ b/appspec.yml @@ -1,22 +1,9 @@ version: 0.0 -os: linux -files: - - source: / - destination: /home/ec2-user/nodejs-aws-codedeploy-pipeline -hooks: -# ApplicationStop: -# DownloadBundle: -# BeforeInstall: -# - location: scripts/before_install.sh -# timeout: 300 -# runas: root -# Install: - AfterInstall: - - location: scripts/after_install.sh - timeout: 300 - runas: root - ApplicationStart: - - location: scripts/application_start.sh - timeout: 300 - runas: root -# ValidateService: +Resources: + - myECSService: + Type: AWS::ECS::Service + Properties: + TaskDefinition: arn:aws:ecs:us-east-1:713881791522:task-definition/nodejs-app-task:1 + LoadBalancerInfo: + ContainerName: nodejs-container + ContainerPort: 3000