-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJenkinsfile
83 lines (83 loc) · 3.27 KB
/
Jenkinsfile
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
pipeline {
agent any
environment {
registryFront = "public.ecr.aws/p1e0j1r1/lg-frontend"
registryBack = "public.ecr.aws/p1e0j1r1/lg-backend"
}
stages {
stage('Checkout GitHub repository') {
steps {
git branch: 'prod',
url: 'https://github.com/andymbwu/log-generator'
}
}
stage('Building frontend image') {
steps{
dir('frontend') {
script {
dockerImage = docker.build registryFront
}
}
}
}
stage('Pushing frontend image to ECR') {
steps{
withCredentials ([[
$class: 'AmazonWebServicesCredentialsBinding',
credentialsId: 'jenkins-aws-admin',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
sh 'aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/p1e0j1r1'
sh "docker push public.ecr.aws/p1e0j1r1/lg-frontend:latest"
}
}
}
stage('Building backend image') {
steps{
dir('backend') {
script {
dockerImage = docker.build registryBack
}
}
}
}
stage('Pushing backend image to ECR') {
steps{
withCredentials ([[
$class: 'AmazonWebServicesCredentialsBinding',
credentialsId: 'jenkins-aws-admin',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
sh 'aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/p1e0j1r1'
sh "docker push public.ecr.aws/p1e0j1r1/lg-backend:latest"
}
}
}
stage('Deploy backend') {
steps {
withCredentials([[
$class: 'AmazonWebServicesCredentialsBinding',
credentialsId: 'jenkins-aws-admin',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
sh 'aws ec2 start-instances --instance-ids i-0605937bc6c04b756 --region us-west-2'
sleep time: 60, unit: 'SECONDS'
sh "aws ecs update-service --cluster ad1EcsCluster --service ad1-back --desired-count 1 --force-new-deployment --region us-west-2"
}
}
}
stage('Deploy frontend') {
steps {
withCredentials([[
$class: 'AmazonWebServicesCredentialsBinding',
credentialsId: 'jenkins-aws-admin',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
sh 'aws ec2 start-instances --instance-ids i-07991c44637ace785 --region us-west-2'
sleep time: 60, unit: 'SECONDS'
sh "aws ecs update-service --cluster ad1EcsCluster --service ad1-front --desired-count 1 --force-new-deployment --region us-west-2"
}
}
}
}
}