Skip to content
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
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
6 changes: 3 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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 = '3,000,000';
const version = '5';

app.get('/', (req, res) => {
// set response content
res.send(`<html>
<body>
<h1 style="color:blue;text-align: center;margin-top: 100px;"> [Version ${version}]: THis is AMAZING!!! Like & Subscribe!</h1>
<h1 style="color:blue;text-align: center;margin-top: 100px;"> [Version ${version}]: Home page</h1>
<div style="position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%)">
<img src="https://picsum.photos/400/400?random=1">
</div>
Expand Down
29 changes: 8 additions & 21 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -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