I have Jenkins on a Centos server and also deployed Docker in same server and established connection. I am trying to deploy Docker image to different production server using Jenkins pipeline.
I already have source code on github with all requirements to deploy.
JENKINFILE (below only small part)
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Running build automation'
sh './gradlew build --no-daemon'
archiveArtifacts artifacts: 'dist/trainSchedule.zip'
}
}
stage('Build Docker Image') {
when {
branch 'master'
}
steps {
script {
app = docker.build("willbla/train-schedule")
app.inside {
sh 'echo $(curl localhost:8080)'
}
}
}
}
stage('Push Docker Image') {
when {
branch 'master'
}
steps {
script {
docker.withRegistry('https://registry.hub.docker.com', 'docker_hub_login') {
app.push("${env.BUILD_NUMBER}")
app.push("latest")
DOCKER FILE
FROM node:carbon
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]
I am able to build image and deploy but I am confused how we Docker built image with source code COPY package*.json ./ .
. To do that it has to be locally on the Jenkins server where my Docker is. I found the images built by command docker image ls
and also found build artifacts in /var/lib/jenkins/jobs/<my-job-name>-build/builds/8/archive/target
, but where is the source code and how is it copied in Dockerfile?