From a78de2fbd55ceba2c3d42e154672903f0c55f3c8 Mon Sep 17 00:00:00 2001 From: Jesse James Isler Date: Thu, 9 Jun 2022 10:20:46 +0200 Subject: [PATCH] updated --- Dockerfile | 27 ++--------- Jenkinsfile | 130 ++++++++++++++++++++++------------------------------ 2 files changed, 58 insertions(+), 99 deletions(-) diff --git a/Dockerfile b/Dockerfile index af4c4d3..9bfde68 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,6 @@ -# STEP 1: -# Name the node stage "builder" -FROM node:16 AS builder -# Set working directory -WORKDIR /app -# Copy all files from current directory to working dir in image -COPY . . -# install node modules and build assets -RUN npm i && npm run build +FROM nginx:1.13.1-alpine -# STEP 2: -# nginx state for serving content -FROM nginx:alpine -# Set working directory to nginx asset directory -WORKDIR /usr/share/nginx/html -# Remove default nginx static assets -RUN rm -rf ./* -# Copy static assets from builder stage -COPY --from=builder /app/dist/schedulord-frontend . -# Containers run nginx with global directives and daemon off +EXPOSE 80 -#ENTRY POINT ["nginx", "-g"] - -#ENTRYPOINT ["nginx", "-g", "daemon off;"] -EXPOSE 80 \ No newline at end of file +COPY dist /var/www +COPY config/nginx.conf /etc/nginx/nginx.conf diff --git a/Jenkinsfile b/Jenkinsfile index 439da9c..ce2316a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,89 +1,67 @@ -/* -//Original Pipeline - -pipeline { - agent { dockerfile true } - stages { - stage('Test') { - steps { - echo "Build has worked!" - } - } - } -} -*/ - -//New Pipeline - pipeline { agent none -/* -//For some reason, this scrashes Jenkins - - tools { - nodejs "815Node" - } -*/ - -/* We won't be Pushing to Dockerhub YET - environment { - registry = 'dockerhubusername/dockerhubusername' - registryCredential = 'dockerhubcredentials' - } -*/ - stages { - stage('INSTALL PACKAGES') { - agent any - steps { - sh "npm install" - } - } - stage('CODETEST') { - agent any - steps { - echo "insert your testing here" - } - } - stage('BUILD APP') { - agent any - steps { - sh "node_modules/.bin/ng build --prod" - } - } - stage('Angular frontend Karma Test') { - agent any - steps { - sh 'npm rebuild' - sh 'npm run test' - sh 'ng test' - } - } - stage("BUILD DOCKER") { + stage('Fetch dependencies') { agent { - dockerfile true + docker 'circleci/node:9.3-stretch-browsers' } steps { - script { - dockerImageBuild = docker.build registry + ":latest" - } + sh 'yarn' + stash includes: 'node_modules/', name: 'node_modules' } } -/* -// Again, no pushing to Docker Hub - - stage("DEPLOY DOCKER") { - steps { - script { - docker.withRegistry('', registryCredential) { - dockerImageBuild.push() - } - } + stage('Lint') { + agent { + docker 'circleci/node:9.3-stretch-browsers' } - } - stage("DEPLOY & ACTIVATE") { steps { - echo 'this part will differ depending on setup' + unstash 'node_modules' + sh 'yarn lint' + } + } + stage('Unit Test') { + agent { + docker 'circleci/node:9.3-stretch-browsers' + } + steps { + unstash 'node_modules' + sh 'yarn test:ci' + junit 'reports/**/*.xml' + } + } + stage('E2E Test') { + agent { + docker 'circleci/node:9.3-stretch-browsers' + } + steps { + unstash 'node_modules' + sh 'mkdir -p reports' + sh 'yarn e2e:pre-ci' + sh 'yarn e2e:ci' + sh 'yarn e2e:post-ci' + junit 'reports/**/*.xml' + } + } + stage('Compile') { + agent { + docker 'circleci/node:9.3-stretch-browsers' + } + steps { + unstash 'node_modules' + sh 'yarn build:prod' + stash includes: 'dist/', name: 'dist' + } + } + stage('Build and Push Docker Image') { + agent any + environment { + DOCKER_PUSH = credentials('docker_push') + } + steps { + unstash 'dist' + sh 'docker build -t $DOCKER_PUSH_URL/frontend .' + sh 'docker login -u $DOCKER_PUSH_USR -p $DOCKER_PUSH_PSW $DOCKER_PUSH_URL' + sh 'docker push $DOCKER_PUSH_URL/frontend' } } }