we have dockerfile in our angular2 project and we build/push/pull it on server with jenkins
here is content of dockerfile
# Stage 0, based on Node.js, to build and compile Angular
FROM node:latest as node
WORKDIR /app
COPY package.json /app/
RUN npm install
COPY ./ /app/
ARG env=prod
RUN npm run build -- --prod --environment $env
# Stage 1, based on Nginx, to have only the compiled app, ready for production with Nginx
FROM nginx:1.13
COPY --from=node /app/dist/ /usr/share/nginx/html
COPY ./nginx-custom.conf /etc/nginx/conf.d/default.conf
when I build and push it with this args (from powershell or cmd) it works great but need to put this arg from jenkins slave when deploying, is this possible?
--build-arg env=dev .
docker build -t admione-front-test:latest --build-arg env=test .
here is jenkins build and deploy script
node {
stage ('build') {
build job: 'pathToProject' //path to workspace (project files)
}
stage ('deploy') {
sshagent(credentials: ['jenkins-credential']) {
String commandToRun = 'docker stop project || true && docker rm project || true ';
commandToRun = commandToRun + ' && docker pull registry/project:latest ';
commandToRun = commandToRun + ' && docker run -d -p 81:80 --restart unless-stopped --name project registry/project:latest '
sh "ssh -o StrictHostKeyChecking=no root /bin/bash -c '\"${commandToRun}\"'"
}
}
}