From d2f6c9883a7050508c976c6aa3560d2c014c9c72 Mon Sep 17 00:00:00 2001 From: roye Date: Thu, 26 Dec 2024 10:09:37 -0800 Subject: [PATCH 01/13] build ci/cd --- .github/workflows/build.yaml | 21 +++++++++++++++++++ .idea/.gitignore | 3 +++ .../inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/misc.xml | 7 +++++++ .idea/vcs.xml | 6 ++++++ Dockerfile | 6 ++++++ 6 files changed, 49 insertions(+) create mode 100644 .github/workflows/build.yaml create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 Dockerfile diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..6181f46 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,21 @@ +name: NetflixMovieCatalog Build + +on: + push: + branches: + - main + +jobs: + Build: + runs-on: ubuntu-latest + steps: + - name: Checkout the repo code + uses: actions/checkout@v2 + + - name: Build and push image + run: | + docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} + + IMAGE_NAME=royeb/netflix-frontend:${{ github.run_number }} + docker build -t $IMAGE_NAME . + docker push $IMAGE_NAME \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e557d17 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bbcdc0d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM node:14.0.0-alpine3.11 +WORKDIR /app +COPY . . +RUN npm install +RUN npm run build +CMD ["npm", "start"] From c6989e049055f71525a93dea87a1314b1d0d0c05 Mon Sep 17 00:00:00 2001 From: roye-b Date: Sun, 29 Dec 2024 08:45:40 -0800 Subject: [PATCH 02/13] ci/cd --- .github/workflows/build.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6181f46..c80b4b8 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -13,9 +13,8 @@ jobs: uses: actions/checkout@v2 - name: Build and push image - run: | - docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} - + run: | + echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin IMAGE_NAME=royeb/netflix-frontend:${{ github.run_number }} docker build -t $IMAGE_NAME . docker push $IMAGE_NAME \ No newline at end of file From 5795e71a468b8e6bf14fe216407ff1a0109ad11f Mon Sep 17 00:00:00 2001 From: roye-b Date: Sun, 5 Jan 2025 22:55:27 -0800 Subject: [PATCH 03/13] test1 --- .github/workflows/build.yaml | 20 ------------- .github/workflows/service-deploy.yaml | 42 +++++++++++++++++++++++++++ deploy.sh | 3 ++ 3 files changed, 45 insertions(+), 20 deletions(-) delete mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/service-deploy.yaml create mode 100644 deploy.sh diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index c80b4b8..0000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,20 +0,0 @@ -name: NetflixMovieCatalog Build - -on: - push: - branches: - - main - -jobs: - Build: - runs-on: ubuntu-latest - steps: - - name: Checkout the repo code - uses: actions/checkout@v2 - - - name: Build and push image - run: | - echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin - IMAGE_NAME=royeb/netflix-frontend:${{ github.run_number }} - docker build -t $IMAGE_NAME . - docker push $IMAGE_NAME \ No newline at end of file diff --git a/.github/workflows/service-deploy.yaml b/.github/workflows/service-deploy.yaml new file mode 100644 index 0000000..2911978 --- /dev/null +++ b/.github/workflows/service-deploy.yaml @@ -0,0 +1,42 @@ +name: Netflix Movie Catalog Service Deployment + +on: + push: + branches: + - main + +env: + EC2_PUBLIC_IP: "13.60.60.5" # TODO replace to your EC2 instance public IP + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} # TODO define this secret in your GitHub repo settings + +jobs: + Deploy: + name: Deploy in EC2 + runs-on: ubuntu-latest + steps: + - name: Checkout the app code + uses: actions/checkout@v2 + + - name: Build and push image + run: | + echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin + IMAGE_NAME=royeb/netflix_movie_catalog:${{ github.run_number }} + docker build -t $IMAGE_NAME . + docker push $IMAGE_NAME + - name: SSH to EC2 instance + run: | + echo "$SSH_PRIVATE_KEY" > roye-key.pem + chmod 400 roye-key.pem + + # Copy the files from the current wrok dir into the EC2 instance, under `~/app`. + scp -o StrictHostKeyChecking=no -i roye-key.pem deploy.sh ubuntu@$EC2_PUBLIC_IP:~/app + + # Connect to your EC2 instance and execute the `deploy.sh` script (this script is part of the repo files). + # You need to implement the `deploy.sh` script yourself. + # + # Upon completion, the NetflixMovieCatalog app should be running with its newer version. + # To keep the app running in the background independently on the terminal session you are logging to, configure it as a Linux service. + + ssh -i roye-key.pem ubuntu@$EC2_PUBLIC_IP "bash /home/ubuntu/app/deploy.sh" + # + diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..a25676f --- /dev/null +++ b/deploy.sh @@ -0,0 +1,3 @@ +#!/bin/bash +docker-compose -f /home/ubuntu/app/docker-compose.yaml down --rmi all +docker compose -f /home/ubuntu/app/docker-compose.yaml up -d \ No newline at end of file From 65b6c38b9361f3f5c2007a1cdaf66b5896ba996b Mon Sep 17 00:00:00 2001 From: roye-b Date: Sun, 5 Jan 2025 22:58:22 -0800 Subject: [PATCH 04/13] test1 --- .github/workflows/service-deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/service-deploy.yaml b/.github/workflows/service-deploy.yaml index 2911978..734bf77 100644 --- a/.github/workflows/service-deploy.yaml +++ b/.github/workflows/service-deploy.yaml @@ -20,7 +20,7 @@ jobs: - name: Build and push image run: | echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin - IMAGE_NAME=royeb/netflix_movie_catalog:${{ github.run_number }} + IMAGE_NAME=royeb/netflix-frontend:${{ github.run_number }} docker build -t $IMAGE_NAME . docker push $IMAGE_NAME - name: SSH to EC2 instance From af1e8e1a1d256d5f38d06dea5a77df744636568e Mon Sep 17 00:00:00 2001 From: roye-b Date: Tue, 7 Jan 2025 09:21:37 -0800 Subject: [PATCH 05/13] test1 --- .github/workflows/service-deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/service-deploy.yaml b/.github/workflows/service-deploy.yaml index 734bf77..6feb74a 100644 --- a/.github/workflows/service-deploy.yaml +++ b/.github/workflows/service-deploy.yaml @@ -6,7 +6,7 @@ on: - main env: - EC2_PUBLIC_IP: "13.60.60.5" # TODO replace to your EC2 instance public IP + EC2_PUBLIC_IP: "13.60.200.193" # TODO replace to your EC2 instance public IP SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} # TODO define this secret in your GitHub repo settings jobs: From d5d9031cf080edebff7c5cc5f83a78984e132361 Mon Sep 17 00:00:00 2001 From: roye-b Date: Fri, 10 Jan 2025 01:06:57 -0800 Subject: [PATCH 06/13] alontest --- .github/workflows/service-deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/service-deploy.yaml b/.github/workflows/service-deploy.yaml index 6feb74a..08bdea7 100644 --- a/.github/workflows/service-deploy.yaml +++ b/.github/workflows/service-deploy.yaml @@ -6,7 +6,7 @@ on: - main env: - EC2_PUBLIC_IP: "13.60.200.193" # TODO replace to your EC2 instance public IP + EC2_PUBLIC_IP: "51.20.87.72" # TODO replace to your EC2 instance public IP SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} # TODO define this secret in your GitHub repo settings jobs: From 6d284d47730beda55aea40701a219c45e8215e3a Mon Sep 17 00:00:00 2001 From: roye-b Date: Sat, 8 Mar 2025 07:51:59 -0800 Subject: [PATCH 07/13] build jenkinsfile --- .github/workflows/service-deploy.yaml | 1 + pipelines/build.jenkinsfile | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 pipelines/build.jenkinsfile diff --git a/.github/workflows/service-deploy.yaml b/.github/workflows/service-deploy.yaml index 08bdea7..36cd24c 100644 --- a/.github/workflows/service-deploy.yaml +++ b/.github/workflows/service-deploy.yaml @@ -39,4 +39,5 @@ jobs: ssh -i roye-key.pem ubuntu@$EC2_PUBLIC_IP "bash /home/ubuntu/app/deploy.sh" # + diff --git a/pipelines/build.jenkinsfile b/pipelines/build.jenkinsfile new file mode 100644 index 0000000..d0c005c --- /dev/null +++ b/pipelines/build.jenkinsfile @@ -0,0 +1,25 @@ +// pipelines/build.Jenkinsfile + +pipeline { + agent any + + triggers { + githubPush() + } + + stages { + stage('Build app container') { + steps { + sh ''' + # your pipeline commands here.... + + # for example list the files in the pipeline workdir + ls + + # build an image + docker build -t netflix-front . + ''' + } + } + } +} \ No newline at end of file From 46ffbb90d42da9c14d17deaa65fbd1434a6a1b41 Mon Sep 17 00:00:00 2001 From: roye-b Date: Sat, 8 Mar 2025 08:07:50 -0800 Subject: [PATCH 08/13] build jenkinsfile2 --- pipelines/build.jenkinsfile | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pipelines/build.jenkinsfile b/pipelines/build.jenkinsfile index d0c005c..a8e4cd8 100644 --- a/pipelines/build.jenkinsfile +++ b/pipelines/build.jenkinsfile @@ -11,12 +11,6 @@ pipeline { stage('Build app container') { steps { sh ''' - # your pipeline commands here.... - - # for example list the files in the pipeline workdir - ls - - # build an image docker build -t netflix-front . ''' } From 4f5439a28d273700499027e99227a79e4f5c797d Mon Sep 17 00:00:00 2001 From: roye-b Date: Sat, 8 Mar 2025 13:18:48 -0800 Subject: [PATCH 09/13] build jenkinsfile2 --- pipelines/build.jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pipelines/build.jenkinsfile b/pipelines/build.jenkinsfile index a8e4cd8..34d90dd 100644 --- a/pipelines/build.jenkinsfile +++ b/pipelines/build.jenkinsfile @@ -1,7 +1,9 @@ // pipelines/build.Jenkinsfile pipeline { - agent any + agent { + label 'general' + } triggers { githubPush() From 819cd1b73a0200049db1380ea199f7b392d433c7 Mon Sep 17 00:00:00 2001 From: roye-b Date: Wed, 12 Mar 2025 21:30:35 -0700 Subject: [PATCH 10/13] build jenkinsfile2 --- pipelines/build.jenkinsfile | 39 ++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/pipelines/build.jenkinsfile b/pipelines/build.jenkinsfile index 34d90dd..7a169a6 100644 --- a/pipelines/build.jenkinsfile +++ b/pipelines/build.jenkinsfile @@ -1,19 +1,44 @@ -// pipelines/build.Jenkinsfile - pipeline { - agent { - label 'general' + agent { + label 'general' } triggers { - githubPush() + githubPush() // trigger the pipeline upon push event in github + } + + options { + timeout(time: 10, unit: 'MINUTES') // discard the build after 10 minutes of running + timestamps() // display timestamp in console output + } + + environment { + // GIT_COMMIT = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() + // TIMESTAMP = new Date().format("yyyyMMdd-HHmmss") + + IMAGE_TAG = "v1.0.$BUILD_NUMBER" + IMAGE_BASE_NAME = "netflix-frontend" + + DOCKER_CREDS = credentials('dockerhub') + DOCKER_USERNAME = "${DOCKER_CREDS_USR}" // The _USR suffix added to access the username value + DOCKER_PASS = "${DOCKER_CREDS_PSW}" // The _PSW suffix added to access the password value } stages { - stage('Build app container') { + stage('Docker setup') { steps { sh ''' - docker build -t netflix-front . + docker login -u $DOCKER_USERNAME -p $DOCKER_PASS + ''' + } + } + + stage('Build & Push') { + steps { + sh ''' + IMAGE_FULL_NAME=$DOCKER_USERNAME/$IMAGE_BASE_NAME:$IMAGE_TAG + + docker build --push -t $IMAGE_FULL_NAME . ''' } } From 778b1baed734c3ec00f41b42ed1d2b01027a1411 Mon Sep 17 00:00:00 2001 From: roye-b Date: Fri, 28 Mar 2025 04:43:09 -0700 Subject: [PATCH 11/13] build jenkinsfile2 --- pipelines/build.jenkinsfile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pipelines/build.jenkinsfile b/pipelines/build.jenkinsfile index 7a169a6..756d5da 100644 --- a/pipelines/build.jenkinsfile +++ b/pipelines/build.jenkinsfile @@ -42,5 +42,15 @@ pipeline { ''' } } + + + stage('Trigger Deploy') { + steps { + build job: '', wait: false, parameters: [ + string(name: 'SERVICE_NAME', value: "NetflixFrontend"), + string(name: 'IMAGE_FULL_NAME_PARAM', value: "$DOCKER_USERNAME/$IMAGE_BASE_NAME:$IMAGE_TAG") + ] } + } + } } \ No newline at end of file From e736efc238c1d7671058b8846508a863004ff213 Mon Sep 17 00:00:00 2001 From: roye-b Date: Fri, 28 Mar 2025 04:52:42 -0700 Subject: [PATCH 12/13] build jenkinsfile2 --- pipelines/build.jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelines/build.jenkinsfile b/pipelines/build.jenkinsfile index 756d5da..fbafc06 100644 --- a/pipelines/build.jenkinsfile +++ b/pipelines/build.jenkinsfile @@ -46,7 +46,7 @@ pipeline { stage('Trigger Deploy') { steps { - build job: '', wait: false, parameters: [ + build job: 'front-deploy', wait: false, parameters: [ string(name: 'SERVICE_NAME', value: "NetflixFrontend"), string(name: 'IMAGE_FULL_NAME_PARAM', value: "$DOCKER_USERNAME/$IMAGE_BASE_NAME:$IMAGE_TAG") ] From d2a943aa2fccb9cdc72f88e20d417d2c1536e657 Mon Sep 17 00:00:00 2001 From: roye-b Date: Sat, 29 Mar 2025 14:16:37 -0700 Subject: [PATCH 13/13] test jenkinsfile --- pipelines/test.jenkinsfile | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 pipelines/test.jenkinsfile diff --git a/pipelines/test.jenkinsfile b/pipelines/test.jenkinsfile new file mode 100644 index 0000000..695d82a --- /dev/null +++ b/pipelines/test.jenkinsfile @@ -0,0 +1,44 @@ +pipeline { + agent any + + stages { + stage('Tests before build') { + parallel { + stage('Unittest') { + steps { + sh 'echo unittesting...' + } + } + stage('Lint') { + steps { + sh 'echo linting...' + } + } + } + } + stage('Build and deploy to Test environment') { + steps { + sh 'echo trigger build and deploy pipelines for test environment... wait until successful deployment' + } + } + stage('Tests after build') { + parallel { + stage('Security vulnerabilities scanning') { + steps { + sh 'echo scanning for vulnerabilities...' + } + } + stage('API test') { + steps { + sh 'echo testing API...' + } + } + stage('Load test') { + steps { + sh 'echo testing under load...' + } + } + } + } + } +}