Added Jenkinsfile and Dockerfile

This commit is contained in:
Sebastian Seedorf
2022-08-18 10:58:47 +02:00
parent d97786f880
commit 044943f19a
2 changed files with 82 additions and 0 deletions

18
Dockerfile Normal file
View File

@@ -0,0 +1,18 @@
FROM node:16-alpine
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
COPY ./.next /app/.next
COPY ./public /app/public
COPY ./res /app/res
COPY ./node_modules /app/node_modules
COPY ./next.config.js /app/next.config.js
COPY ./package.json /app/package.json
COPY ./yarn.lock /app/yarn.lock
RUN npm install
ENTRYPOINT npm start
EXPOSE 3000

64
Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,64 @@
#!groovy
node {
stage('Checkout') {
checkout scm
}
stage('Prepare') {
sh 'git rev-parse --verify HEAD > GIT_COMMIT'
env.GIT_COMMIT = readFile('GIT_COMMIT').trim().substring(0, 10)
sh 'rm GIT_COMMIT'
def jobName = env.JOB_NAME.tokenize('/')
print env.jobName
// set env
env.DOCKER_NAME="${jobName[0]}/${jobName[1]}:${env.BRANCH_NAME}-${env.GIT_COMMIT}"
env.DOCKER_REGISTRY="docker.sebse.de"
env.NODEJS_HOME = "${tool 'node16'}"
env.PATH="${env.NODEJS_HOME}/bin:${env.PATH}"
env.NEXT_TELEMETRY_DISABLED=1
def customImage
}
/*stage('Test') {
env.NODE_ENV = "test"
print "Environment will be : ${env.NODE_ENV}"
sh 'node -v'
sh 'yarn install'
sh 'yarn test'
}*/
stage('Build Prod') {
env.NODE_ENV = "production"
print "Environment will be : ${env.NODE_ENV}"
sh 'node -v'
sh 'yarn install --production=false'
sh 'yarn run build'
sh 'rm node_modules -rf'
sh 'yarn install --production=true'
}
stage('Build Docker') {
customImage = docker.build(env.DOCKER_NAME)
}
stage('Deploy') {
echo 'Push to Repo'
docker.withRegistry("https://${DOCKER_REGISTRY}", 'docker-registry-robot-web-development') {
/* Push the container to the custom Registry */
customImage.push()
}
}
stage('Cleanup') {
echo 'prune and cleanup'
sh 'rm node_modules -rf'
sh "docker rmi ${env.DOCKER_NAME} ${DOCKER_REGISTRY}/${env.DOCKER_NAME}"
sh 'docker image prune -f'
sh 'docker rmi $(docker images -a | grep "<none>" | awk "{print \$3}") &2>/del/null || exit 0'
}
}