yazid138 3 years ago
parent
commit
2d80d7c27b
4 changed files with 178 additions and 1 deletions
  1. 68 0
      Jenkinsfile
  2. 68 0
      JenkinsfileDev
  3. 40 0
      dockerfile
  4. 2 1
      env.js

+ 68 - 0
Jenkinsfile

@@ -0,0 +1,68 @@
+/*
+  1. added 
+     client_max_body_size 0;
+     to avoid 413 error
+  
+  2. npm install error internet problem, fake update 1
+*/
+
+node {
+  def app
+  def registryAddress
+  def registryCredential
+  try {
+    // environment {
+      registryAddress = "https://registry.sidali.sixsenz.net"
+      registryCredential = 'DockerRegistry-ID'
+    // }
+	
+    stage('Checkout') {
+      checkout scm
+    }
+	
+    stage('Initialize'){
+      def dockerHome = tool 'myDocker'
+      env.PATH = "${dockerHome}/bin:${env.PATH}"
+    }
+	
+    stage('Environment') {
+      sh 'git --version'
+      echo "Branch: master"
+      sh 'docker -v'
+      sh 'printenv'
+    }
+	
+    stage('Test Build'){
+     sh 'docker build -t ptb-fe:latest -f dockerfile .'
+    }
+	
+    stage('Build Deploy '){
+            // // now you are on slave labeled with 'label'
+            // def workspace = WORKSPACE
+            // // ${workspace} will now contain an absolute path to job workspace on slave
+
+            // workspace = env.WORKSPACE
+            // // ${workspace} will still contain an absolute path to job workspace on slave
+
+            // // When using a GString at least later Jenkins versions could only handle the env.WORKSPACE variant:
+            // echo "Current workspace is ${env.WORKSPACE}"
+
+            // // the current Jenkins instances will support the short syntax, too:
+            // echo "Current workspace is $WORKSPACE"
+        docker.withTool("myDocker"){
+            docker.withRegistry(registryAddress, registryCredential) {
+
+                def dockerImage = docker.build("ptb-fe:${env.BUILD_ID}")
+
+                /* Push the container to the custom Registry */
+                dockerImage.push()
+                dockerImage.push('latest')
+            }
+        }
+
+     }
+  }
+  catch (err) {
+    throw err
+  }
+}

+ 68 - 0
JenkinsfileDev

@@ -0,0 +1,68 @@
+/*
+  1. added 
+     client_max_body_size 0;
+     to avoid 413 error
+  
+  2. npm install error internet problem, fake update 1
+*/
+
+node {
+  def app
+  def registryAddress
+  def registryCredential
+  try {
+    // environment {
+      registryAddress = "https://registry.sidali.sixsenz.net"
+      registryCredential = 'DockerRegistry-ID'
+    // }
+	
+    stage('Checkout') {
+      checkout scm
+    }
+	
+    stage('Initialize'){
+      def dockerHome = tool 'myDocker'
+      env.PATH = "${dockerHome}/bin:${env.PATH}"
+    }
+	
+    stage('Environment') {
+      sh 'git --version'
+      echo "Branch: master"
+      sh 'docker -v'
+      sh 'printenv'
+    }
+	
+    stage('Test Build'){
+     sh 'docker build -t ptb-fe-dev:latest -f dockerfile .'
+    }
+	
+    stage('Build Deploy '){
+            // // now you are on slave labeled with 'label'
+            // def workspace = WORKSPACE
+            // // ${workspace} will now contain an absolute path to job workspace on slave
+
+            // workspace = env.WORKSPACE
+            // // ${workspace} will still contain an absolute path to job workspace on slave
+
+            // // When using a GString at least later Jenkins versions could only handle the env.WORKSPACE variant:
+            // echo "Current workspace is ${env.WORKSPACE}"
+
+            // // the current Jenkins instances will support the short syntax, too:
+            // echo "Current workspace is $WORKSPACE"
+        docker.withTool("myDocker"){
+            docker.withRegistry(registryAddress, registryCredential) {
+
+                def dockerImage = docker.build("ptb-fe-dev:${env.BUILD_ID}")
+
+                /* Push the container to the custom Registry */
+                dockerImage.push()
+                dockerImage.push('latest')
+            }
+        }
+
+     }
+  }
+  catch (err) {
+    throw err
+  }
+}

+ 40 - 0
dockerfile

@@ -0,0 +1,40 @@
+# FROM node:14
+
+# # Create app directory
+# RUN mkdir -p /usr/src/app && chown -R node:node /usr/src/app
+# WORKDIR /usr/src/app
+# COPY --chown=node:node . .
+# USER node
+
+# RUN npm install
+
+# # Building app
+# # RUN npm run build
+# EXPOSE 3000
+
+# # Running the app
+# CMD "npm" "run" "dev"
+
+FROM node:14
+
+# Create app directory
+RUN mkdir -p /usr/src/app && chown -R node:node /usr/src/app
+WORKDIR /usr/src/app
+
+
+COPY package.json /usr/src/app
+
+# Installing dependencies
+RUN npm install
+
+# Build App
+RUN npm run build
+
+# # Copying source files
+COPY . /usr/src/app
+
+# Building app
+EXPOSE 3000
+
+# Running the app
+CMD "npm" "start"

+ 2 - 1
env.js

@@ -1,2 +1,3 @@
 // export const TOKEN=77aecfec-10ac-3b4f-ab59-3fbfbeed6324
-export const API_URL = "http://localhost:5000";
+// export const API_URL = "http://localhost:5000";
+export const API_URL = "https://api.sidali.sixsenz.net";