diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 8563e33..f621291 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -5,18 +5,30 @@ on: jobs: deploy: runs-on: ubuntu-latest + # These permissions are needed to interact with GitHub's OIDC Token endpoint. + permissions: + id-token: write + contents: read steps: # Step 1 - name: Checkout to repo uses: actions/checkout@v2 - # Step 2 + # Step 2 - name: Set AWS credentials - uses: aws-actions/configure-aws-credentials@v1 + uses: aws-actions/configure-aws-credentials@v2 with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: us-east-1 + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-session-token: ${{secrets.AWS_SESSION_TOKEN}} + aws-region: us-east-1 + +# Step 2 +# - name: Set AWS credentials +# uses: aws-actions/configure-aws-credentials@v2 +# with: +# role-to-assume: arn:aws:iam::530095765619:role/LabRole +# aws-region: us-east-1 # Step 3 - name: Create CodeDeploy Deployment @@ -26,4 +38,4 @@ jobs: --application-name nodejs-express-app \ --deployment-group-name nodejs-express-app-cd1 \ --deployment-config-name CodeDeployDefault.OneAtATime \ - --github-location repository=${{ github.repository }},commitId=${{ github.sha }} \ No newline at end of file + --github-location repository=${{ github.repository }},commitId=${{ github.sha }} diff --git a/README.md b/README.md index 99522fd..e832e0e 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ How to set ci/cd for nodejs app with aws codeDeploy and aws codePipeline ## Installation instructions ### 1. Launch amazon linux server in aws +Amazon Linux 2 (ARM, x86) + Supported Amazon EC2 AMI operating systems ### 2. ssh to linux to install packages @@ -58,7 +60,8 @@ nvm --version #### 3.4 Install node ```sh -nvm install --lts # Latest stable node js server version +nvm install --lts # Latest stable node js server version 18.15.0, which is not well-supported, install a version which is active +nvm install 16.0.0 ``` #### 3.5 Check nodejs installed @@ -79,6 +82,7 @@ cd /home/ec2-user ```sh git clone https://github.com/saasscaleup/nodejs-aws-codedeploy-pipeline.git +git clone https://github.com/jipx/nodejs-aws-codedeploy-pipeline.git ``` ### 5. Run node app.js (Make sure everything working) @@ -115,16 +119,19 @@ sudo ln -s "$(which pm2)" /sbin/pm2 ### 8 Starting the app as sudo (Run nodejs in background and when server restart) ```sh sudo pm2 start app.js --name=nodejs-express-app +pm2 start app.js --name=nodejs-express-app ``` ```sh sudo pm2 save # saves the running processes # if not saved, pm2 will forget # the running apps on next boot +pm2 save ``` #### 8.1 IMPORTANT: If you want pm2 to start on system boot ```sh sudo pm2 startup # starts pm2 on computer boot +pm2 startup ``` ### 9. Install aws code deploy agent @@ -145,6 +152,10 @@ sudo ./install auto ```sh sudo service codedeploy-agent start ``` +```sh +sudo service codedeploy-agent status #check the service status +``` + verify the status ### 10. Continue in AWS console... diff --git a/app.js b/app.js index 2aaad68..185480e 100644 --- a/app.js +++ b/app.js @@ -1,25 +1,31 @@ -const express = require('express'); +const express = require("express"); const app = express(); -const hostname = '127.0.0.1'; // Your server ip address +const hostname = "127.0.0.1"; // Your server ip address const port = 3000; -const version = '3,000,000'; +const version = "3.28.1.12.3334"; -app.get('/', (req, res) => { - // set response content - res.send(` +app.get("/", (req, res) => { + // set response content + res.send(` -

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

-
- +

[Version ${version}]
Good Night,Mr.jipx @library,THis is AMAZING!!! EC2 needs to have a profile to do the tasks

+
+
`); - - console.log(`[Version ${version}]: New request => http://${hostname}:${port}`+req.url); -}) + console.log( + `[Version ${version}]: New request => http://${hostname}:${port}` + req.url + ); +}); app.listen(port, () => { - console.log(`[Version ${version}]: Server running at http://${hostname}:${port}/`); -}) + console.log( + `[Version ${version}]: Server running at http://${hostname}:${port}/` + ); +}); diff --git a/userData b/userData new file mode 100644 index 0000000..a0c214f --- /dev/null +++ b/userData @@ -0,0 +1,5 @@ +#!/bin/bash +yum install -y aws-cli +cd /home/ec2-user/ +aws s3 cp 's3://aws-codedeploy-us-east-1/latest/codedeploy-agent.noarch.rpm' . --region us-east-1 +yum -y install codedeploy-agent.noarch.rpm