-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathJenkinsfile
52 lines (51 loc) · 2.04 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
pipeline {
agent any
environment {
AWS_REGION = 'us-east-1'
ECR_REPOSITORY = '896470658577.dkr.ecr.us-east-1.amazonaws.com/code2cloud-ecr'
CONTAINER_NAME = 'code2cloud'
}
stages {
stage('Build') {
steps {
withAWS(credentials: 'aws-cred', region: 'us-east-1') {
sh '''
docker ps
aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $ECR_REPOSITORY:$CONTAINER_NAME
echo "Building the Docker image..."
docker build -t $ECR_REPOSITORY:$CONTAINER_NAME ./app/
docker image prune -f
docker image ls
'''
}
}
}
stage('Artifactory Deploy') {
steps {
withAWS(credentials: 'aws-cred', region: 'us-east-1') {
sh '''
docker ps
$(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
echo "Image push into registry"
docker push $ECR_REPOSITORY:$CONTAINER_NAME
'''
}
}
}
stage('Server Deploy') {
steps {
withAWS(credentials: 'aws-cred', region: 'us-east-1') {
sh '''
aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $ECR_REPOSITORY:$CONTAINER_NAME
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o ./docker-compose
echo "ECR_REPOSITORY=$ECR_REPOSITORY
CONTAINER_NAME=$CONTAINER_NAME" >> .env
docker image prune -f
chmod +x docker-compose
./docker-compose --env-file=.env pull && ./docker-compose --env-file=.env up -d
'''
}
}
}
}
}