-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathJenkinsfile
More file actions
50 lines (49 loc) · 1.63 KB
/
Jenkinsfile
File metadata and controls
50 lines (49 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
pipeline {
agent any
environment {
ECR_REGISTRY = "189241875931.dkr.ecr.us-east-1.amazonaws.com"
APP_REPO_NAME= "clarusway/to-do-app"
PATH="/usr/local/bin/:${env.PATH}"
}
stages {
stage("Run app on Docker"){
agent{
docker{
image 'node:12-alpine'
}
}
steps{
withEnv(["HOME=${env.WORKSPACE}"]) {
sh 'yarn install --production'
sh 'npm install'
}
}
}
stage('Build Docker Image') {
steps {
sh 'docker build --force-rm -t "$ECR_REGISTRY/$APP_REPO_NAME:latest" .'
sh 'docker image ls'
}
}
stage('Push Image to ECR Repo') {
steps {
sh 'aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin "$ECR_REGISTRY"'
sh 'docker push "$ECR_REGISTRY/$APP_REPO_NAME:latest"'
}
}
stage('Deploy') {
steps {
sh 'aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin "$ECR_REGISTRY"'
sh 'docker pull "$ECR_REGISTRY/$APP_REPO_NAME:latest"'
sh 'docker ps -q --filter "name=todo" | grep -q . && docker stop todo && docker rm -f todo'
sh 'docker run --name todo -dp 80:3000 "$ECR_REGISTRY/$APP_REPO_NAME:latest"'
}
}
}
post {
always {
echo 'Deleting all local images'
sh 'docker image prune -af'
}
}
}